SergeyO7 commited on
Commit
73cc123
·
verified ·
1 Parent(s): 1b61ca7

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +27 -18
agent.py CHANGED
@@ -351,26 +351,35 @@ class MagAgent:
351
  SpeechToTextTool(),
352
  ]
353
 
354
- # Load prompts with required templates
355
- default_prompts = {
356
- "system_prompt": "Default system instructions...",
357
- "managed_agent": "Default subtask template...",
358
- "planning": "Default planning template...",
359
- "final_answer": "Default answer format: {answer}"
360
  }
361
 
362
- # try:
363
- # with open("prompts.yaml") as f:
364
- # self.prompt_templates = yaml.safe_load(f)
365
- # except Exception as e:
366
- # self.prompt_templates = {
367
- # "base_prompt": "Default base prompt...",
368
- # "task_prompt": "Default task template: {question}"
369
- # }
370
-
371
- # Load prompt templates
372
- with open("prompts.yaml", 'r') as stream:
373
- self.prompt_templates = yaml.safe_load(stream)
 
 
 
 
 
 
 
 
 
374
 
375
 
376
  self.agent = CodeAgent(
 
351
  SpeechToTextTool(),
352
  ]
353
 
354
+ # Initialize with default prompts
355
+ self.prompt_templates = {
356
+ "system_prompt": "You are Magus...",
357
+ "managed_agent": "Decomposing problem...",
358
+ "planning": "Step-by-Step Plan...",
359
+ "final_answer": "Final Verified Answer..."
360
  }
361
 
362
+ try:
363
+ with open("prompts.yaml") as f:
364
+ user_prompts = yaml.safe_load(f)
365
+
366
+ # Validate loaded prompts structure
367
+ if isinstance(user_prompts, dict):
368
+ # Merge with defaults, preserving missing keys
369
+ self.prompt_templates.update({
370
+ k: v for k, v in user_prompts.items()
371
+ if k in self.prompt_templates
372
+ })
373
+ else:
374
+ print(f"Invalid prompts.yaml structure. Using defaults. Got type: {type(user_prompts)}")
375
+
376
+ except Exception as e:
377
+ print(f"Error loading prompts.yaml: {str(e)}. Using default templates")
378
+
379
+ # Final validation
380
+ required_keys = {'system_prompt', 'managed_agent', 'planning', 'final_answer'}
381
+ if missing := required_keys - self.prompt_templates.keys():
382
+ raise ValueError(f"Missing required prompt templates: {missing}")
383
 
384
 
385
  self.agent = CodeAgent(