Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading