Spaces:
Sleeping
Sleeping
jesusgj
commited on
Commit
·
888c2fc
1
Parent(s):
82f909c
Modified files
Browse files
agent.py
CHANGED
|
@@ -15,7 +15,7 @@ from smolagents import (
|
|
| 15 |
InferenceClientModel,
|
| 16 |
GoogleSearchTool,
|
| 17 |
tool,
|
| 18 |
-
Tool,
|
| 19 |
)
|
| 20 |
|
| 21 |
# --- Configuration and Setup ---
|
|
@@ -99,8 +99,6 @@ def create_gaia_agent_wrapper(agent: CodeAgent):
|
|
| 99 |
return normalized_answer
|
| 100 |
return gaia_compliant_agent
|
| 101 |
|
| 102 |
-
# --- Main Agent Initialization ---
|
| 103 |
-
|
| 104 |
# --- Tool Implementations (with robustness decorators) ---
|
| 105 |
@retry
|
| 106 |
@lru_cache(maxsize=128)
|
|
@@ -191,10 +189,8 @@ def initialize_agent():
|
|
| 191 |
model = InferenceClientModel(model_id="Qwen/Qwen2.5-7B-Instruct", token=api_keys['together'], provider="together")
|
| 192 |
logging.info("✅ Fallback model (Qwen 2.5 7B) loaded successfully")
|
| 193 |
|
| 194 |
-
# The tool finds the API key from the environment automatically.
|
| 195 |
google_search_tool = GoogleSearchTool() if api_keys['serpapi'] else None
|
| 196 |
|
| 197 |
-
# The list now contains genuine Tool objects.
|
| 198 |
tools_list = [
|
| 199 |
tool for tool in [
|
| 200 |
google_search_tool,
|
|
@@ -214,27 +210,22 @@ def initialize_agent():
|
|
| 214 |
|
| 215 |
1. **Analyze**: Break down the user's question into logical steps.
|
| 216 |
2. **Plan**: Decide if you need to search the web, read a webpage, get a video transcript, or perform a calculation.
|
| 217 |
-
3. **Execute**: Write a Python script to perform the steps.
|
| 218 |
-
* For general web searches, use `GoogleSearchTool()`.
|
| 219 |
-
* For Wikipedia lookups, use `wikipedia_search()`.
|
| 220 |
-
* To read the text content of a specific webpage, use `get_webpage_content()`.
|
| 221 |
-
* To get the transcript of a YouTube video, use `get_youtube_transcript()`.
|
| 222 |
-
* For complex calculations or data manipulation, write the Python code directly using libraries like `math`.
|
| 223 |
|
| 224 |
**HOW TO USE TOOLS IN YOUR CODE:**
|
| 225 |
-
To solve a problem, you will write a Python code block that calls the necessary tools.
|
| 226 |
|
| 227 |
*Example 1: Simple Calculation*
|
| 228 |
-
|
| 229 |
-
|
| 230 |
import math
|
| 231 |
result = math.factorial(15) / (math.factorial(12) * math.factorial(3))
|
| 232 |
print(int(result))
|
| 233 |
-
|
| 234 |
|
| 235 |
*Example 2: Multi-step question involving web search and reading a page*
|
| 236 |
-
|
| 237 |
-
|
| 238 |
# First, find the URL of the paper.
|
| 239 |
search_results = GoogleSearchTool(query="A Rapid and Sensitive Method for the Quantitation of Microgram Quantities of Protein Utilizing the Principle of Protein-Dye Binding")
|
| 240 |
# Let's assume the first result has a good URL, like "https://www.sciencedirect.com/science/article/pii/0003269776905271"
|
|
@@ -243,7 +234,7 @@ def initialize_agent():
|
|
| 243 |
# Now I will analyze the text `page_content` in my head to find the journal name.
|
| 244 |
# After reading the text, I found the journal is "Analytical Biochemistry".
|
| 245 |
print("Analytical Biochemistry")
|
| 246 |
-
|
| 247 |
|
| 248 |
**CRITICAL INSTRUCTION:** You MUST end your entire response with the line `FINAL ANSWER: [Your Final Answer]`. This is the only part of your response that will be graded. Adhere to strict formatting: no extra words, no currency symbols, no commas in numbers.
|
| 249 |
"""
|
|
|
|
| 15 |
InferenceClientModel,
|
| 16 |
GoogleSearchTool,
|
| 17 |
tool,
|
| 18 |
+
Tool,
|
| 19 |
)
|
| 20 |
|
| 21 |
# --- Configuration and Setup ---
|
|
|
|
| 99 |
return normalized_answer
|
| 100 |
return gaia_compliant_agent
|
| 101 |
|
|
|
|
|
|
|
| 102 |
# --- Tool Implementations (with robustness decorators) ---
|
| 103 |
@retry
|
| 104 |
@lru_cache(maxsize=128)
|
|
|
|
| 189 |
model = InferenceClientModel(model_id="Qwen/Qwen2.5-7B-Instruct", token=api_keys['together'], provider="together")
|
| 190 |
logging.info("✅ Fallback model (Qwen 2.5 7B) loaded successfully")
|
| 191 |
|
|
|
|
| 192 |
google_search_tool = GoogleSearchTool() if api_keys['serpapi'] else None
|
| 193 |
|
|
|
|
| 194 |
tools_list = [
|
| 195 |
tool for tool in [
|
| 196 |
google_search_tool,
|
|
|
|
| 210 |
|
| 211 |
1. **Analyze**: Break down the user's question into logical steps.
|
| 212 |
2. **Plan**: Decide if you need to search the web, read a webpage, get a video transcript, or perform a calculation.
|
| 213 |
+
3. **Execute**: Write a Python script to perform the steps. You must always use the `<code>...</code>` format to wrap your code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
**HOW TO USE TOOLS IN YOUR CODE:**
|
| 216 |
+
To solve a problem, you will write a Python code block that calls the necessary tools.
|
| 217 |
|
| 218 |
*Example 1: Simple Calculation*
|
| 219 |
+
Thought: The user wants to know 15! / (12! * 3!). I will use the math library to calculate the factorials and then perform the division.
|
| 220 |
+
<code>
|
| 221 |
import math
|
| 222 |
result = math.factorial(15) / (math.factorial(12) * math.factorial(3))
|
| 223 |
print(int(result))
|
| 224 |
+
</code>
|
| 225 |
|
| 226 |
*Example 2: Multi-step question involving web search and reading a page*
|
| 227 |
+
Thought: I need to find the name of the journal that published a specific article. First, I will use the Google Search tool to find the webpage for the article. Then, I will use the `get_webpage_content` tool to read the text of that page. Finally, I will analyze the text to find the journal's name and print it.
|
| 228 |
+
<code>
|
| 229 |
# First, find the URL of the paper.
|
| 230 |
search_results = GoogleSearchTool(query="A Rapid and Sensitive Method for the Quantitation of Microgram Quantities of Protein Utilizing the Principle of Protein-Dye Binding")
|
| 231 |
# Let's assume the first result has a good URL, like "https://www.sciencedirect.com/science/article/pii/0003269776905271"
|
|
|
|
| 234 |
# Now I will analyze the text `page_content` in my head to find the journal name.
|
| 235 |
# After reading the text, I found the journal is "Analytical Biochemistry".
|
| 236 |
print("Analytical Biochemistry")
|
| 237 |
+
</code>
|
| 238 |
|
| 239 |
**CRITICAL INSTRUCTION:** You MUST end your entire response with the line `FINAL ANSWER: [Your Final Answer]`. This is the only part of your response that will be graded. Adhere to strict formatting: no extra words, no currency symbols, no commas in numbers.
|
| 240 |
"""
|