Scott Cogan commited on
Commit
0bf52c9
·
1 Parent(s): c1ed0a4

fix: add CustomCodeAgent to handle both list and dictionary tool formats

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -232,9 +232,27 @@ 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_dict, # Pass tools as a dictionary for template rendering
 
238
  max_steps=15,
239
  verbosity_level=2,
240
  grammar=None,
 
232
  for name, tool in tools_dict.items():
233
  logger.debug(f" {name}: {tool}")
234
 
235
+ # Create a custom CodeAgent class that handles both list and dictionary requirements
236
+ class CustomCodeAgent(CodeAgent):
237
+ def __init__(self, *args, **kwargs):
238
+ # Store the tools dictionary for template rendering
239
+ self.tools_dict = kwargs.pop('tools_dict', {})
240
+ super().__init__(*args, **kwargs)
241
+
242
+ def initialize_system_prompt(self):
243
+ # Override to use tools_dict for template rendering
244
+ return self.populate_template(
245
+ self.prompt_templates["system_prompt"],
246
+ tools=self.tools_dict,
247
+ task=self.task,
248
+ managed_agents=self.managed_agents,
249
+ authorized_imports=self.authorized_imports
250
+ )
251
+
252
+ agent = CustomCodeAgent(
253
  model=model,
254
+ tools=tools, # Pass tools as a list for _setup_tools
255
+ tools_dict=tools_dict, # Pass tools as a dictionary for template rendering
256
  max_steps=15,
257
  verbosity_level=2,
258
  grammar=None,