From db252a27c176f721b9df9c40527af8e7ae6226e3 Mon Sep 17 00:00:00 2001 From: Travis Dent Date: Tue, 26 Nov 2024 07:12:19 -0800 Subject: [PATCH 1/2] Add post_install and post_remove hooks to tool json configs. Basic documentaton for tool configs. --- agentstack/generation/tool_generation.py | 5 +++- agentstack/tools/~README.md | 33 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 agentstack/tools/~README.md diff --git a/agentstack/generation/tool_generation.py b/agentstack/generation/tool_generation.py index f60b3f16..d36ae014 100644 --- a/agentstack/generation/tool_generation.py +++ b/agentstack/generation/tool_generation.py @@ -43,7 +43,8 @@ def add_tool(tool_name: str, path: Optional[str] = None): insert_code_after_tag(f'{path}.env', '# Tools', [tool_data['env']], next_line=True) # Add env var if not string_in_file(f'{path}.env.example', first_var_name): insert_code_after_tag(f'{path}.env.example', '# Tools', [tool_data['env']], next_line=True) # Add env var - + if tool_data.get('post_install'): + os.system(tool_data['post_install']) if not agentstack_json.get('tools'): agentstack_json['tools'] = [] agentstack_json['tools'].append(tool_name) @@ -78,6 +79,8 @@ def remove_tool(tool_name: str, path: Optional[str] = None): os.remove(f'{path}src/tools/{tool_name}_tool.py') remove_tool_from_tools_init(tool_data, path) remove_tool_from_agent_definition(framework, tool_data, path) + if tool_data.get('post_remove'): + os.system(tool_data['post_remove']) # We don't remove the .env variables to preserve user data. agentstack_json['tools'].remove(tool_name) diff --git a/agentstack/tools/~README.md b/agentstack/tools/~README.md new file mode 100644 index 00000000..642f26e0 --- /dev/null +++ b/agentstack/tools/~README.md @@ -0,0 +1,33 @@ +Tool Configuration Files +======================== +Tools are configured for installation & removal using JSON files in this directory. + +## Parameters + +### `name` (string) [required] +The name of the tool in snake_case. This is used to identify the tool in the system. + +### `cta` (string) [optional] +String to print in the terminal when the tool is installed that provides a call to action. + +### `tools` (list) [required] +List of public methods that are accessible in the tool implementation. + +### `env` (string) [optional] +Definitions for environment variables that will be appended to the local `.env` file. +Separate multiple environment variables with a newline character. + +### `packages` (list) [optional] +A list of package names to install. These are the names of the packages that will +be installed and removed by the package manager. + +### `post_install` (string) [optional] +Shell command that will be executed after packages have been installed and environment +variables have been set. + +### `post_remove` (string) [optional] +Shell command that will be executed after the tool has been removed. + +### `tools_bundled` (boolean) [optional] +Include all bundled tools in the tool implementation. + From 2787089ac23605e57d4df78f39956d22463c3645 Mon Sep 17 00:00:00 2001 From: Travis Dent Date: Wed, 27 Nov 2024 09:11:25 -0800 Subject: [PATCH 2/2] Clarify tools_bundled in tools readme. --- agentstack/tools/~README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/agentstack/tools/~README.md b/agentstack/tools/~README.md index 642f26e0..39b78db0 100644 --- a/agentstack/tools/~README.md +++ b/agentstack/tools/~README.md @@ -7,12 +7,16 @@ Tools are configured for installation & removal using JSON files in this directo ### `name` (string) [required] The name of the tool in snake_case. This is used to identify the tool in the system. -### `cta` (string) [optional] -String to print in the terminal when the tool is installed that provides a call to action. - ### `tools` (list) [required] List of public methods that are accessible in the tool implementation. +### `tools_bundled` (boolean) [optional] +Indicates that the tool file exports a `list` of tools. Specify the variable name +of the list in the `tools` field. + +### `cta` (string) [optional] +String to print in the terminal when the tool is installed that provides a call to action. + ### `env` (string) [optional] Definitions for environment variables that will be appended to the local `.env` file. Separate multiple environment variables with a newline character. @@ -28,6 +32,3 @@ variables have been set. ### `post_remove` (string) [optional] Shell command that will be executed after the tool has been removed. -### `tools_bundled` (boolean) [optional] -Include all bundled tools in the tool implementation. -