zaldivards commited on
Commit
7bfc491
·
1 Parent(s): df6c855

Refactor MainAgent ot use just one agent

Browse files
Files changed (3) hide show
  1. agent.py +20 -15
  2. requirements.txt +3 -0
  3. utils.py +1 -0
agent.py CHANGED
@@ -1,7 +1,17 @@
1
- from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, VisitWebpageTool, AmazonBedrockServerModel
2
 
3
- from tools import AudioTranscriber, txt_reader, pdf_reader, excel_reader, math_calculator
4
- from utils import BEDROCK_MODEL_ID
 
 
 
 
 
 
 
 
 
 
5
 
6
  MAIN_PROMPT = """
7
  You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
@@ -21,24 +31,19 @@ class MainAgent:
21
  """Main agent that orchestrates file handling and web search tasks."""
22
 
23
  def __init__(self):
24
- model = AmazonBedrockServerModel(model_id=BEDROCK_MODEL_ID)
25
- file_handler_agent = ToolCallingAgent(
26
- name="FileHandlerAgent",
27
- description="Handles file-related tasks such as reading Excel, text, PDF files, etc.",
28
  tools=[
 
 
29
  AudioTranscriber(),
30
  txt_reader,
31
  pdf_reader,
32
  excel_reader,
 
33
  ],
34
- max_steps=3,
35
- model=model,
36
- )
37
- self.agent = ToolCallingAgent(
38
- name="web_search_agent",
39
- description="An agent that can search the web, visit webpages, and perform calculations.",
40
- managed_agents=[file_handler_agent],
41
- tools=[DuckDuckGoSearchTool(), VisitWebpageTool(), math_calculator],
42
  max_steps=5,
43
  model=model,
44
  )
 
1
+ import os
2
 
3
+ from smolagents import OpenAIServerModel, ToolCallingAgent
4
+
5
+ from tools import (
6
+ AudioTranscriber,
7
+ txt_reader,
8
+ pdf_reader,
9
+ excel_reader,
10
+ math_calculator,
11
+ search_engine,
12
+ image_transcriber,
13
+ )
14
+ from utils import OPENAI_MODEL_ID
15
 
16
  MAIN_PROMPT = """
17
  You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
 
31
  """Main agent that orchestrates file handling and web search tasks."""
32
 
33
  def __init__(self):
34
+ model = OpenAIServerModel(model_id=OPENAI_MODEL_ID, api_key=os.getenv("OPENAI_API_KEY"))
35
+ self.agent = ToolCallingAgent(
36
+ name="main_agent",
37
+ description="An agent that can search the web, visit webpages, perform calculations, and handle files.",
38
  tools=[
39
+ search_engine,
40
+ math_calculator,
41
  AudioTranscriber(),
42
  txt_reader,
43
  pdf_reader,
44
  excel_reader,
45
+ image_transcriber,
46
  ],
 
 
 
 
 
 
 
 
47
  max_steps=5,
48
  model=model,
49
  )
requirements.txt CHANGED
@@ -31,6 +31,7 @@ jmespath==1.0.1 ; python_version >= '3.7'
31
  jsonpatch==1.33 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'
32
  jsonpointer==3.0.0 ; python_version >= '3.7'
33
  langchain-core==0.3.61 ; python_version >= '3.9'
 
34
  langgraph==0.4.7
35
  langgraph-checkpoint==2.0.26 ; python_version >= '3.9'
36
  langgraph-prebuilt==0.2.1 ; python_version >= '3.9'
@@ -60,6 +61,7 @@ python-dotenv==1.1.0
60
  python-multipart==0.0.20 ; python_version >= '3.8'
61
  pytz==2025.2
62
  pyyaml==6.0.2 ; python_version >= '3.8'
 
63
  requests==2.32.3
64
  requests-toolbelt==1.0.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
65
  rich==14.0.0 ; python_full_version >= '3.8.0'
@@ -74,6 +76,7 @@ sniffio==1.3.1 ; python_version >= '3.7'
74
  soupsieve==2.7 ; python_version >= '3.8'
75
  starlette==0.46.2 ; sys_platform != 'emscripten'
76
  tenacity==9.1.2 ; python_version >= '3.9'
 
77
  tomlkit==0.13.2 ; python_version >= '3.8'
78
  tqdm==4.67.1 ; python_version >= '3.7'
79
  typer==0.16.0 ; sys_platform != 'emscripten'
 
31
  jsonpatch==1.33 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'
32
  jsonpointer==3.0.0 ; python_version >= '3.7'
33
  langchain-core==0.3.61 ; python_version >= '3.9'
34
+ langchain-openai==0.3.18
35
  langgraph==0.4.7
36
  langgraph-checkpoint==2.0.26 ; python_version >= '3.9'
37
  langgraph-prebuilt==0.2.1 ; python_version >= '3.9'
 
61
  python-multipart==0.0.20 ; python_version >= '3.8'
62
  pytz==2025.2
63
  pyyaml==6.0.2 ; python_version >= '3.8'
64
+ regex==2024.11.6 ; python_version >= '3.8'
65
  requests==2.32.3
66
  requests-toolbelt==1.0.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
67
  rich==14.0.0 ; python_full_version >= '3.8.0'
 
76
  soupsieve==2.7 ; python_version >= '3.8'
77
  starlette==0.46.2 ; sys_platform != 'emscripten'
78
  tenacity==9.1.2 ; python_version >= '3.9'
79
+ tiktoken==0.9.0 ; python_version >= '3.9'
80
  tomlkit==0.13.2 ; python_version >= '3.8'
81
  tqdm==4.67.1 ; python_version >= '3.7'
82
  typer==0.16.0 ; sys_platform != 'emscripten'
utils.py CHANGED
@@ -6,6 +6,7 @@ import requests
6
 
7
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
  BEDROCK_MODEL_ID = "anthropic.claude-3-5-sonnet-20240620-v1:0"
 
9
 
10
  bedrock_runtime = boto3.client("bedrock-runtime", region_name=os.getenv("AWS_REGION"))
11
 
 
6
 
7
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
  BEDROCK_MODEL_ID = "anthropic.claude-3-5-sonnet-20240620-v1:0"
9
+ OPENAI_MODEL_ID = "o4-mini"
10
 
11
  bedrock_runtime = boto3.client("bedrock-runtime", region_name=os.getenv("AWS_REGION"))
12