Update multiagents.py
Browse files- multiagents.py +27 -25
multiagents.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
|
|
| 1 |
# a multi agent proposal to solve HF agent course final assignment
|
| 2 |
import os
|
| 3 |
-
import textwrap
|
| 4 |
import dotenv
|
| 5 |
from smolagents import CodeAgent
|
| 6 |
from smolagents import OpenAIServerModel
|
|
@@ -28,15 +28,15 @@ vllm_model = OpenAIServerModel(
|
|
| 28 |
)
|
| 29 |
|
| 30 |
openai_41nano_model = OpenAIServerModel(
|
| 31 |
-
model_id="
|
| 32 |
-
api_base="https://api.
|
| 33 |
-
api_key=os.environ["
|
| 34 |
)
|
| 35 |
|
| 36 |
openai_41mini_model = OpenAIServerModel(
|
| 37 |
-
model_id="
|
| 38 |
-
api_base="https://api.
|
| 39 |
-
api_key=os.environ["
|
| 40 |
)
|
| 41 |
|
| 42 |
|
|
@@ -81,43 +81,44 @@ audiovideo_agent = CodeAgent(
|
|
| 81 |
max_steps=7,
|
| 82 |
)
|
| 83 |
|
| 84 |
-
|
|
|
|
| 85 |
manager_agent = CodeAgent(
|
| 86 |
model=openai_41mini_model,
|
| 87 |
-
tools=[PythonInterpreterTool()],
|
| 88 |
-
managed_agents=[web_agent, audiovideo_agent],
|
| 89 |
-
additional_authorized_imports=["pandas", "numpy",
|
| 90 |
planning_interval=5,
|
| 91 |
verbosity_level=2,
|
| 92 |
final_answer_checks=[check_final_answer],
|
| 93 |
max_steps=15,
|
| 94 |
name="manager_agent",
|
| 95 |
description="A manager agent that coordinates the work of other agents to answer questions.",
|
| 96 |
-
# Add system prompt here if the CodeAgent supports it
|
| 97 |
-
system_prompt="You are the top agent of a multi-agent system that can answer questions by coordinating the work of other agents. You will receive a question and you will decide which agent to use to answer it. You can use: web_agent to search the web and fetch page content, audiovideo_agent for video/audio file information. You can also use your own knowledge. Think step by step and don't skip steps."
|
| 98 |
)
|
| 99 |
|
| 100 |
class MultiAgent:
|
| 101 |
def __init__(self):
|
| 102 |
-
print("
|
| 103 |
|
| 104 |
def __call__(self, question: str) -> str:
|
| 105 |
-
mylog(self.__class__.__name__, question)
|
| 106 |
|
| 107 |
try:
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
-
# Just add the output format requirements to the question
|
| 113 |
-
enhanced_question = f"""{question.strip()}
|
| 114 |
|
| 115 |
-
|
| 116 |
-
{myprompts.output_format.strip() if hasattr(myprompts, 'output_format') else 'Provide a clear, concise answer.'}"""
|
| 117 |
|
| 118 |
-
|
| 119 |
-
return manager_agent.run(enhanced_question)
|
| 120 |
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
error = f"An error occurred while processing the question: {e}"
|
| 123 |
print(error)
|
|
@@ -132,4 +133,5 @@ What was the actual enrollment of the Malko competition in 2023?
|
|
| 132 |
"""
|
| 133 |
agent = MultiAgent()
|
| 134 |
answer = agent(question)
|
| 135 |
-
print(f"Answer: {answer}")
|
|
|
|
|
|
| 1 |
+
|
| 2 |
# a multi agent proposal to solve HF agent course final assignment
|
| 3 |
import os
|
|
|
|
| 4 |
import dotenv
|
| 5 |
from smolagents import CodeAgent
|
| 6 |
from smolagents import OpenAIServerModel
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
openai_41nano_model = OpenAIServerModel(
|
| 31 |
+
model_id="gpt-4.1-nano",
|
| 32 |
+
api_base="https://api.openai.com/v1",
|
| 33 |
+
api_key=os.environ["OPENAI_API_KEY"],
|
| 34 |
)
|
| 35 |
|
| 36 |
openai_41mini_model = OpenAIServerModel(
|
| 37 |
+
model_id="gpt-3.5-turbo",
|
| 38 |
+
api_base="https://api.openai.com/v1",
|
| 39 |
+
api_key=os.environ["OPENAI_API_KEY"],
|
| 40 |
)
|
| 41 |
|
| 42 |
|
|
|
|
| 81 |
max_steps=7,
|
| 82 |
)
|
| 83 |
|
| 84 |
+
|
| 85 |
+
|
| 86 |
manager_agent = CodeAgent(
|
| 87 |
model=openai_41mini_model,
|
| 88 |
+
tools=[ PythonInterpreterTool()],
|
| 89 |
+
managed_agents=[web_agent, audiovideo_agent],
|
| 90 |
+
additional_authorized_imports=["pandas", "numpy","bs4"],
|
| 91 |
planning_interval=5,
|
| 92 |
verbosity_level=2,
|
| 93 |
final_answer_checks=[check_final_answer],
|
| 94 |
max_steps=15,
|
| 95 |
name="manager_agent",
|
| 96 |
description="A manager agent that coordinates the work of other agents to answer questions.",
|
|
|
|
|
|
|
| 97 |
)
|
| 98 |
|
| 99 |
class MultiAgent:
|
| 100 |
def __init__(self):
|
| 101 |
+
print("BasicAgent initialized.")
|
| 102 |
|
| 103 |
def __call__(self, question: str) -> str:
|
| 104 |
+
mylog(self.__class__.__name__, question)
|
| 105 |
|
| 106 |
try:
|
| 107 |
+
prefix = """You are the top agent of a multi-agent system that can answer questions by coordinating the work of other agents.
|
| 108 |
+
You will receive a question and you will decide which agent to use to answer it.
|
| 109 |
+
You can use the web_agent to search the web for information and for fetching the content of a web page, or the audiovideo_agent to extract information from video or audio files.
|
| 110 |
+
You can also use your own knowledge to answer the question.
|
| 111 |
+
You need to respect the output format that is given to you.
|
| 112 |
+
Finding the correct answer to the question need reasoning and plannig, read the question carrefully, think step by step and do not skip any steps.
|
| 113 |
+
"""
|
| 114 |
|
| 115 |
+
question = prefix + "\nTHE QUESTION:\n" + question + '\n' + myprompts.output_format
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
fixed_answer = ""
|
|
|
|
| 118 |
|
| 119 |
+
fixed_answer = manager_agent.run(question)
|
|
|
|
| 120 |
|
| 121 |
+
return fixed_answer
|
| 122 |
except Exception as e:
|
| 123 |
error = f"An error occurred while processing the question: {e}"
|
| 124 |
print(error)
|
|
|
|
| 133 |
"""
|
| 134 |
agent = MultiAgent()
|
| 135 |
answer = agent(question)
|
| 136 |
+
print(f"Answer: {answer}")
|
| 137 |
+
|