Imnotchis commited on
Commit
b7be636
·
verified ·
1 Parent(s): 8f08017

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -21
app.py CHANGED
@@ -11,7 +11,6 @@ from pathlib import Path
11
  from smolagents import (
12
  ToolCallingAgent,
13
  OpenAIModel,
14
- VisitWebpageTool,
15
  WikipediaSearchTool,
16
  PythonInterpreterTool,
17
  )
@@ -156,11 +155,8 @@ class SmartWebSearchTool(Tool):
156
  name = "smart_web_search"
157
 
158
  description = (
159
- "Search the web and automatically read the main content "
160
- "of the most relevant pages in a single tool call. "
161
- "Returns page titles, source URLs, snippets, and extracted "
162
- "content. Use for factual research and verification. "
163
- "Input must be a focused search query."
164
  )
165
 
166
  inputs = {
@@ -171,6 +167,10 @@ class SmartWebSearchTool(Tool):
171
  }
172
 
173
  output_type = "string"
 
 
 
 
174
 
175
  def forward(self, query: str) -> str:
176
  query = query.strip()
@@ -181,7 +181,7 @@ class SmartWebSearchTool(Tool):
181
  try:
182
  results = DDGS(timeout=8).text(
183
  query,
184
- max_results=3
185
  )
186
  except Exception as e:
187
  return f"Search failed: {type(e).__name__}: {e}"
@@ -205,7 +205,7 @@ class SmartWebSearchTool(Tool):
205
  )
206
 
207
  # Only read the first two suitable pages.
208
- if pages_read >= 2:
209
  continue
210
 
211
  parsed = urlparse(url)
@@ -295,13 +295,12 @@ class BasicAgent:
295
  "timeout": 60.0,
296
  "max_retries": 0
297
  },
298
- max_tokens=700,
299
  retry=False
300
  )
301
 
302
  # Tools
303
  self.tools = [
304
- SmartWebSearchTool(),
305
  WikipediaSearchTool(),
306
  PythonInterpreterTool(
307
  authorized_imports=["math", "re", "datetime", "collections"]
@@ -315,19 +314,32 @@ class BasicAgent:
315
  max_steps=5,
316
  verbosity_level=1,
317
  instructions="""
318
- Solve GAIA questions accurately with minimal tool calls.
319
-
320
- - Follow the exact answer format requested.
321
- - Answer directly when no research is needed.
322
- - For research, use smart_web_search with focused keywords.
323
- - Read all returned evidence before searching again.
324
- - Do not repeat searches or visit inaccessible sources.
 
 
 
 
 
325
  - Use wikipedia_search for Wikipedia-specific questions.
326
  - Use python_interpreter for calculations when necessary.
327
- - Never invent facts or claim to have inspected missing media.
328
- - Call final_answer as soon as sufficient evidence exists.
329
- - Return only the requested answer without explanations.
330
- - Use only tools and arguments defined in their schemas.
 
 
 
 
 
 
 
 
331
  """
332
  )
333
 
 
11
  from smolagents import (
12
  ToolCallingAgent,
13
  OpenAIModel,
 
14
  WikipediaSearchTool,
15
  PythonInterpreterTool,
16
  )
 
155
  name = "smart_web_search"
156
 
157
  description = (
158
+ "Search the web and extract the main content "
159
+ "from relevant pages in a single tool call."
 
 
 
160
  )
161
 
162
  inputs = {
 
167
  }
168
 
169
  output_type = "string"
170
+ def __init__(self, max_pages=3, max_results=5):
171
+ super().__init__()
172
+ self.max_pages = max_pages
173
+ self.max_results = max_results
174
 
175
  def forward(self, query: str) -> str:
176
  query = query.strip()
 
181
  try:
182
  results = DDGS(timeout=8).text(
183
  query,
184
+ max_results=self.max_results
185
  )
186
  except Exception as e:
187
  return f"Search failed: {type(e).__name__}: {e}"
 
205
  )
206
 
207
  # Only read the first two suitable pages.
208
+ if pages_read >= self.max_pages:
209
  continue
210
 
211
  parsed = urlparse(url)
 
295
  "timeout": 60.0,
296
  "max_retries": 0
297
  },
 
298
  retry=False
299
  )
300
 
301
  # Tools
302
  self.tools = [
303
+ SmartWebSearchTool(max_pages=3, max_results=5),
304
  WikipediaSearchTool(),
305
  PythonInterpreterTool(
306
  authorized_imports=["math", "re", "datetime", "collections"]
 
314
  max_steps=5,
315
  verbosity_level=1,
316
  instructions="""
317
+ You are an AI agent solving GAIA benchmark questions.
318
+
319
+ RULES:
320
+ - Read the question carefully.
321
+ - Follow the exact answer format.
322
+ - Never invent facts or sources.
323
+ - Answer directly when research is unnecessary.
324
+
325
+ TOOLS:
326
+ - Use smart_web_search for external research.
327
+ - smart_web_search searches and reads webpages in one call.
328
+ - Read all search results before searching again.
329
  - Use wikipedia_search for Wikipedia-specific questions.
330
  - Use python_interpreter for calculations when necessary.
331
+ - Call only available tools with valid arguments.
332
+
333
+ EFFICIENCY:
334
+ - Avoid repeated searches.
335
+ - Prefer a single focused search query.
336
+ - Stop researching when sufficient evidence is available.
337
+ - Do not claim to have inspected inaccessible attachments.
338
+
339
+ FINAL ANSWER:
340
+ - Call final_answer when ready.
341
+ - Return only the requested answer.
342
+ - Do not add explanations unless requested.
343
  """
344
  )
345