Added a web and a manager agent
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool,
|
|
|
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
@@ -14,20 +15,36 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
# Initialize the search tool
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Initialize the model
|
| 20 |
-
model = InferenceClientModel(
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
self.
|
| 23 |
-
model
|
| 24 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
)
|
| 26 |
print("BasicAgent initialized.")
|
| 27 |
def __call__(self, question: str) -> str:
|
| 28 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 29 |
# Example usage
|
| 30 |
-
response = self.
|
| 31 |
print(f"Agent returning fixed answer: {response}")
|
| 32 |
return response
|
| 33 |
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, WikipediaSearchTool, \
|
| 7 |
+
VisitWebpageTool, InferenceClientModel, GoogleSearchTool
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
# Initialize the search tool
|
| 18 |
+
web_search_tool = DuckDuckGoSearchTool()
|
| 19 |
+
google_search_tool = GoogleSearchTool()
|
| 20 |
+
visit_webpage_tool = VisitWebpageTool()
|
| 21 |
+
final_answer_tool = FinalAnswerTool()
|
| 22 |
|
| 23 |
# Initialize the model
|
| 24 |
+
model = InferenceClientModel(
|
| 25 |
+
"Qwen/Qwen2.5-Coder-32B-Instruct", provider="together"
|
| 26 |
+
)
|
| 27 |
|
| 28 |
+
self.web_agent = CodeAgent(
|
| 29 |
+
model=model,
|
| 30 |
+
tools=[google_search_tool, visit_webpage_tool],
|
| 31 |
+
name="web_agent",
|
| 32 |
+
description="Browses the web to find information"
|
| 33 |
+
)
|
| 34 |
+
print("WebAgent initialized.")
|
| 35 |
+
self.manager_agent = CodeAgent(
|
| 36 |
+
model=InferenceClientModel("deepseek-ai/DeepSeek-R1", provider="together", max_tokens=8096),
|
| 37 |
+
tools=[final_answer_tool],
|
| 38 |
+
managed_agents=[self.web_agent],
|
| 39 |
+
planning_interval=5,
|
| 40 |
+
verbosity_level=2,
|
| 41 |
+
max_steps=15,
|
| 42 |
)
|
| 43 |
print("BasicAgent initialized.")
|
| 44 |
def __call__(self, question: str) -> str:
|
| 45 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 46 |
# Example usage
|
| 47 |
+
response = self.manager_agent.run(question)
|
| 48 |
print(f"Agent returning fixed answer: {response}")
|
| 49 |
return response
|
| 50 |
|