Commit
·
d1b9537
1
Parent(s):
e47481b
Add MainAgent class
Browse files
agent.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, VisitWebpageTool, AmazonBedrockServerModel
|
| 2 |
+
|
| 3 |
+
from tools import AudioTranscriber, txt_reader, pdf_reader, excel_reader, math_calculator
|
| 4 |
+
|
| 5 |
+
MAIN_PROMPT = """
|
| 6 |
+
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 7 |
+
|
| 8 |
+
[YOUR FINAL ANSWER]
|
| 9 |
+
|
| 10 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 11 |
+
If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
|
| 12 |
+
If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
|
| 13 |
+
If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 14 |
+
|
| 15 |
+
Each question will contain the question, the task ID, and if available, a file name.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class MainAgent:
|
| 20 |
+
"""Main agent that orchestrates file handling and web search tasks."""
|
| 21 |
+
|
| 22 |
+
def __init__(self):
|
| 23 |
+
model = AmazonBedrockServerModel(model_id="anthropic.claude-3-5-sonnet-20241022-v2:0")
|
| 24 |
+
file_handler_agent = ToolCallingAgent(
|
| 25 |
+
name="FileHandlerAgent",
|
| 26 |
+
description="Handles file-related tasks such as reading Excel, text, PDF files, etc.",
|
| 27 |
+
tools=[
|
| 28 |
+
AudioTranscriber(),
|
| 29 |
+
txt_reader,
|
| 30 |
+
pdf_reader,
|
| 31 |
+
excel_reader,
|
| 32 |
+
],
|
| 33 |
+
max_steps=3,
|
| 34 |
+
model=model,
|
| 35 |
+
)
|
| 36 |
+
self.agent = ToolCallingAgent(
|
| 37 |
+
name="web_search_agent",
|
| 38 |
+
description="An agent that can search the web, visit webpages, and perform calculations.",
|
| 39 |
+
managed_agents=[file_handler_agent],
|
| 40 |
+
tools=[DuckDuckGoSearchTool(), VisitWebpageTool(), math_calculator],
|
| 41 |
+
max_steps=5,
|
| 42 |
+
model=model,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
def run(self, question: str, task_id: str, file_name: str | None) -> str:
|
| 46 |
+
"""Run the agent with the provided question, task ID, and optional file name."""
|
| 47 |
+
query = f"""q: {question}
|
| 48 |
+
task_id: {task_id}
|
| 49 |
+
{'file_name: ' + file_name if file_name else ''}
|
| 50 |
+
"""
|
| 51 |
+
return self.agent.run(query)
|