Scott Cogan commited on
Commit
c09aeb1
·
1 Parent(s): 885e6d3

fix: pass tools as dictionary to match template usage

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -198,18 +198,18 @@ class GetCurrentTimeInTimezoneTool(Tool):
198
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
199
 
200
  # Create the agent with the templates
201
- tools = [
202
- final_answer, # This is already a Tool instance
203
- DuckDuckGoSearchTool(), # This is already a Tool instance
204
- CalculateMinPriceTool(), # This is a Tool subclass
205
- ExtractPriceFromSnippetTool(), # This is a Tool subclass
206
- GetCurrentTimeInTimezoneTool() # This is a Tool subclass
207
- ]
208
 
209
  # Debug prints to inspect tools
210
- logger.debug("Inspecting tools list:")
211
- for i, tool in enumerate(tools):
212
- logger.debug(f"Tool {i}: {tool}")
213
  logger.debug(f" Type: {type(tool)}")
214
  logger.debug(f" Is Tool instance: {isinstance(tool, Tool)}")
215
  logger.debug(f" Has name: {hasattr(tool, 'name')}")
@@ -220,21 +220,15 @@ for i, tool in enumerate(tools):
220
  logger.debug(f" Description: {tool.description}")
221
 
222
  # Verify all tools are proper Tool instances and have required attributes
223
- for tool in tools:
224
  if not isinstance(tool, Tool):
225
- raise TypeError(f"Tool {tool} is not an instance of Tool or its subclass")
226
  if not hasattr(tool, 'name') or not hasattr(tool, 'description'):
227
- raise AttributeError(f"Tool {tool} is missing required attributes (name or description)")
228
-
229
- # Create a dictionary of tools for template rendering
230
- tools_dict = {tool.name: tool for tool in tools}
231
- logger.debug("Created tools dictionary:")
232
- for name, tool in tools_dict.items():
233
- logger.debug(f" {name}: {tool}")
234
 
235
  agent = CodeAgent(
236
  model=model,
237
- tools=tools, # Pass tools as a list of Tool instances
238
  max_steps=15,
239
  verbosity_level=2,
240
  grammar=None,
 
198
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
199
 
200
  # Create the agent with the templates
201
+ tools = {
202
+ 'final_answer': final_answer, # This is already a Tool instance
203
+ 'web_search': DuckDuckGoSearchTool(), # This is already a Tool instance
204
+ 'calculate_min_price': CalculateMinPriceTool(), # This is a Tool subclass
205
+ 'extract_price_from_snippet': ExtractPriceFromSnippetTool(), # This is a Tool subclass
206
+ 'get_current_time_in_timezone': GetCurrentTimeInTimezoneTool() # This is a Tool subclass
207
+ }
208
 
209
  # Debug prints to inspect tools
210
+ logger.debug("Inspecting tools dictionary:")
211
+ for name, tool in tools.items():
212
+ logger.debug(f"Tool {name}: {tool}")
213
  logger.debug(f" Type: {type(tool)}")
214
  logger.debug(f" Is Tool instance: {isinstance(tool, Tool)}")
215
  logger.debug(f" Has name: {hasattr(tool, 'name')}")
 
220
  logger.debug(f" Description: {tool.description}")
221
 
222
  # Verify all tools are proper Tool instances and have required attributes
223
+ for name, tool in tools.items():
224
  if not isinstance(tool, Tool):
225
+ raise TypeError(f"Tool {name} is not an instance of Tool or its subclass")
226
  if not hasattr(tool, 'name') or not hasattr(tool, 'description'):
227
+ raise AttributeError(f"Tool {name} is missing required attributes (name or description)")
 
 
 
 
 
 
228
 
229
  agent = CodeAgent(
230
  model=model,
231
+ tools=tools, # Pass tools as a dictionary
232
  max_steps=15,
233
  verbosity_level=2,
234
  grammar=None,