diff --git a/agentstack/conf.py b/agentstack/conf.py index 2b7810e..c92e49d 100644 --- a/agentstack/conf.py +++ b/agentstack/conf.py @@ -1,5 +1,5 @@ from typing import Optional, Union -import os, sys +import os import json from pathlib import Path from pydantic import BaseModel @@ -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.""" diff --git a/agentstack/main.py b/agentstack/main.py index 7c60ddf..858ae2d 100644 --- a/agentstack/main.py +++ b/agentstack/main.py @@ -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"]: @@ -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"))