Skip to content

Commit

Permalink
Merge pull request #183 from AgentOps-AI/main-fixes
Browse files Browse the repository at this point in the history
Better error message outside of project
  • Loading branch information
bboynton97 authored Jan 6, 2025
2 parents 776a114 + 51216f9 commit feaf019
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
8 changes: 7 additions & 1 deletion agentstack/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Optional, Union
import os, sys
import os
import json
from pathlib import Path
from pydantic import BaseModel
Expand All @@ -11,6 +11,12 @@

PATH: Path = Path()

def assert_project() -> None:
try:
ConfigFile()
return
except FileNotFoundError:
raise Exception("Could not find agentstack.json, are you in an AgentStack project directory?")

def set_path(path: Union[str, Path, None]):
"""Set the path to the project directory."""
Expand Down
34 changes: 21 additions & 13 deletions agentstack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def main():

# Handle commands
try:
# outside of project
if args.command in ["docs"]:
webbrowser.open("https://docs.agentstack.sh/")
elif args.command in ["quickstart"]:
Expand All @@ -167,36 +168,43 @@ def main():
webbrowser.open("https://docs.agentstack.sh/quickstart")
elif args.command in ["init", "i"]:
init_project_builder(args.slug_name, args.template, args.wizard)
elif args.command in ["run", "r"]:
run_project(command=args.function, debug=args.debug, cli_args=extra_args)
elif args.command in ['generate', 'g']:
if args.generate_command in ['agent', 'a']:
if not args.llm:
configure_default_model()
generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm)
elif args.generate_command in ['task', 't']:
generation.add_task(args.name, args.description, args.expected_output, args.agent)
else:
generate_parser.print_help()
elif args.command in ["tools", "t"]:
if args.tools_command in ["list", "l"]:
list_tools()
elif args.tools_command in ["add", "a"]:
conf.assert_project()
agents = [args.agent] if args.agent else None
agents = args.agents.split(",") if args.agents else agents
add_tool(args.name, agents)
elif args.tools_command in ["remove", "r"]:
conf.assert_project()
generation.remove_tool(args.name)
else:
tools_parser.print_help()
elif args.command in ['export', 'e']:
export_template(args.filename)
elif args.command in ['login']:
auth.login()
elif args.command in ['update', 'u']:
pass # Update check already done

# inside project dir commands only
conf.assert_project()

if args.command in ["run", "r"]:
run_project(command=args.function, debug=args.debug, cli_args=extra_args)
elif args.command in ['generate', 'g']:
if args.generate_command in ['agent', 'a']:
if not args.llm:
configure_default_model()
generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm)
elif args.generate_command in ['task', 't']:
generation.add_task(args.name, args.description, args.expected_output, args.agent)
else:
generate_parser.print_help()
elif args.command in ['export', 'e']:
export_template(args.filename)
else:
parser.print_help()

except Exception as e:
update_telemetry(telemetry_id, result=1, message=str(e))
print(term_color("An error occurred while running your AgentStack command:", "red"))
Expand Down

0 comments on commit feaf019

Please sign in to comment.