Scott Cogan commited on
Commit
d76dcc4
·
1 Parent(s): 746446f

fix: Create properly formatted templates for CodeAgent

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -199,6 +199,50 @@ with open("prompts.yaml", 'r') as stream:
199
  prompt_templates['system_prompt']['text'] = system_prompt
200
  logger.debug(f"Pre-processed system prompt: {system_prompt[:200]}...")
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  agent = CodeAgent(
203
  model=model,
204
  tools=[final_answer, DuckDuckGoSearchTool(), calculate_min_price, extract_price_from_snippet, get_current_time_in_timezone],
@@ -208,7 +252,7 @@ agent = CodeAgent(
208
  planning_interval=1, # Added planning interval to ensure proper planning
209
  name="question_answering_agent",
210
  description="An agent specialized in answering various types of questions using available tools. The agent must use the final_answer tool to submit its answer.",
211
- prompt_templates=prompt_templates
212
  )
213
 
214
  # Configure Gradio UI with sharing enabled
 
199
  prompt_templates['system_prompt']['text'] = system_prompt
200
  logger.debug(f"Pre-processed system prompt: {system_prompt[:200]}...")
201
 
202
+ # Log the final templates before creating the agent
203
+ logger.debug("Final templates before creating agent:")
204
+ for key, value in prompt_templates.items():
205
+ if isinstance(value, dict):
206
+ logger.debug(f"{key}:")
207
+ for subkey, subvalue in value.items():
208
+ logger.debug(f" {subkey}: {str(subvalue)[:200]}...")
209
+ else:
210
+ logger.debug(f"{key}: {str(value)[:200]}...")
211
+
212
+ # Create a copy of the templates for the agent
213
+ agent_templates = {}
214
+ for key, value in prompt_templates.items():
215
+ if isinstance(value, dict):
216
+ agent_templates[key] = {}
217
+ for subkey, subvalue in value.items():
218
+ if isinstance(subvalue, str):
219
+ # Ensure each template string is properly formatted
220
+ if '{{' in subvalue or '{%' in subvalue:
221
+ # Keep template syntax as is
222
+ agent_templates[key][subkey] = subvalue
223
+ else:
224
+ # For non-template content, wrap in a simple template expression
225
+ agent_templates[key][subkey] = '{{ "' + subvalue.replace('"', '\\"') + '" }}'
226
+ else:
227
+ agent_templates[key][subkey] = subvalue
228
+ else:
229
+ if isinstance(value, str):
230
+ if '{{' in value or '{%' in value:
231
+ agent_templates[key] = value
232
+ else:
233
+ agent_templates[key] = '{{ "' + value.replace('"', '\\"') + '" }}'
234
+ else:
235
+ agent_templates[key] = value
236
+
237
+ logger.debug("Templates for agent:")
238
+ for key, value in agent_templates.items():
239
+ if isinstance(value, dict):
240
+ logger.debug(f"{key}:")
241
+ for subkey, subvalue in value.items():
242
+ logger.debug(f" {subkey}: {str(subvalue)[:200]}...")
243
+ else:
244
+ logger.debug(f"{key}: {str(value)[:200]}...")
245
+
246
  agent = CodeAgent(
247
  model=model,
248
  tools=[final_answer, DuckDuckGoSearchTool(), calculate_min_price, extract_price_from_snippet, get_current_time_in_timezone],
 
252
  planning_interval=1, # Added planning interval to ensure proper planning
253
  name="question_answering_agent",
254
  description="An agent specialized in answering various types of questions using available tools. The agent must use the final_answer tool to submit its answer.",
255
+ prompt_templates=agent_templates
256
  )
257
 
258
  # Configure Gradio UI with sharing enabled