From 05ebdbbf1c0383cbbb181a1be110bfe8509a6dda Mon Sep 17 00:00:00 2001 From: Travis Dent Date: Fri, 13 Dec 2024 13:04:10 -0800 Subject: [PATCH 1/2] Dynamically generate tags sent to AgentOps for better observability. --- agentstack/__init__.py | 8 ++++++++ agentstack/conf.py | 13 +++++++++++-- .../src/main.py | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/agentstack/__init__.py b/agentstack/__init__.py index da5ea50f..d907c818 100644 --- a/agentstack/__init__.py +++ b/agentstack/__init__.py @@ -10,6 +10,14 @@ ___all___ = [ "conf", + "get_tags", "get_inputs", ] + +def get_tags() -> list[str]: + """ + Get a list of tags relevant to the user's project. + """ + return ['agentstack', conf.get_framework(), *conf.get_installed_tools()] + diff --git a/agentstack/conf.py b/agentstack/conf.py index 22003ca6..2b7810e4 100644 --- a/agentstack/conf.py +++ b/agentstack/conf.py @@ -23,12 +23,21 @@ def get_framework() -> Optional[str]: and if we are inside a project directory. """ try: - config = ConfigFile() - return config.framework + return ConfigFile().framework except FileNotFoundError: return None # not in a project directory; that's okay +def get_installed_tools() -> list[str]: + """The tools used in the project. Will be available after PATH has been set + and if we are inside a project directory. + """ + try: + return ConfigFile().tools + except FileNotFoundError: + return [] + + class ConfigFile(BaseModel): """ Interface for interacting with the agentstack.json file inside a project directory. diff --git a/agentstack/templates/crewai/{{cookiecutter.project_metadata.project_slug}}/src/main.py b/agentstack/templates/crewai/{{cookiecutter.project_metadata.project_slug}}/src/main.py index 98f7987e..15023c89 100644 --- a/agentstack/templates/crewai/{{cookiecutter.project_metadata.project_slug}}/src/main.py +++ b/agentstack/templates/crewai/{{cookiecutter.project_metadata.project_slug}}/src/main.py @@ -4,7 +4,7 @@ import agentstack import agentops -agentops.init(default_tags=['crewai', 'agentstack']) +agentops.init(default_tags=agentstack.get_tags()) instance = {{cookiecutter.project_metadata.project_name|replace('-', '')|replace('_', '')|capitalize}}Crew().crew() From 4ea260dc74e56375a2997c494c9203305dc08c47 Mon Sep 17 00:00:00 2001 From: Travis Dent Date: Fri, 13 Dec 2024 13:19:19 -0800 Subject: [PATCH 2/2] Resolve type checking errors --- agentstack/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/agentstack/__init__.py b/agentstack/__init__.py index d907c818..e8addfb9 100644 --- a/agentstack/__init__.py +++ b/agentstack/__init__.py @@ -6,11 +6,13 @@ """ from pathlib import Path from agentstack import conf +from agentstack.utils import get_framework from agentstack.inputs import get_inputs ___all___ = [ "conf", "get_tags", + "get_framework", "get_inputs", ] @@ -19,5 +21,5 @@ def get_tags() -> list[str]: """ Get a list of tags relevant to the user's project. """ - return ['agentstack', conf.get_framework(), *conf.get_installed_tools()] + return ['agentstack', get_framework(), *conf.get_installed_tools()]