Skip to content

Commit

Permalink
Merge pull request #21 from AgentOps-AI/add-tools-to-config
Browse files Browse the repository at this point in the history
add tool to agenstack.json
  • Loading branch information
bboynton97 authored Oct 17, 2024
2 parents 1736ff3 + 2f67a07 commit ce67f51
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions agentstack/generation/tool_generation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import sys
from typing import Optional

from .gen_utils import insert_code_after_tag
from ..utils import snake_to_camel, open_json_file, get_framework
from ..utils import open_json_file, get_framework, term_color
import os
import shutil
import fileinput
Expand All @@ -24,7 +25,14 @@ 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
insert_code_after_tag(f'{path}/.env.example', '# Tools', [tool_data['env']], next_line=True) # Add env var

print(f'\033[92m🔨 Tool {tool_name} added to agentstack project successfully\033[0m')
agentstack_json = open_json_file(f'{path}/agentstack.json')
if not agentstack_json.get('tools'):
agentstack_json['tools'] = []
agentstack_json['tools'].append(tool_name)
with open(f'{path}/agentstack.json', 'w') as f:
json.dump(agentstack_json, f, indent=4)

print(term_color(f'🔨 Tool {tool_name} added to agentstack project successfully', 'green'))


def add_tool_to_tools_init(tool_data: dict, path: Optional[str] = None):
Expand Down
12 changes: 6 additions & 6 deletions agentstack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def get_framework(path: Optional[str] = None) -> str:
file_path = 'agentstack.json'
if path is not None:
file_path = path + '/' + file_path
with open(file_path, 'r') as f:
data = json.load(f)
framework = data.get('framework')

if framework.lower() not in ['crewai', 'autogen', 'litellm']:
print("\033[31magentstack.json contains an invalid framework\033[0m")
agentstack_data = open_json_file(file_path)
framework = agentstack_data.get('framework')

return framework
if framework.lower() not in ['crewai', 'autogen', 'litellm']:
print(term_color("agentstack.json contains an invalid framework", "red"))

return framework
except FileNotFoundError:
print("\033[31mFile agentstack.json does not exist. Are you in the right directory?\033[0m")
sys.exit(1)
Expand Down

0 comments on commit ce67f51

Please sign in to comment.