SergeyO7 commited on
Commit
9a0c550
·
verified ·
1 Parent(s): ae43ddf

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +14 -7
agent.py CHANGED
@@ -380,19 +380,21 @@ class MagAgent:
380
  user_prompts = yaml.safe_load(f)
381
 
382
  # Validate loaded prompts structure
 
383
  if isinstance(user_prompts, dict):
384
  for key in self.prompt_templates:
385
  if key in user_prompts:
386
- # Merge main template
387
- self.prompt_templates[key].update(
388
- {k:v for k,v in user_prompts[key].items()
389
- if k in ['template', 'variables']}
390
- )
391
- # Merge sub-templates
 
392
  if 'sub_templates' in user_prompts[key]:
393
  self.prompt_templates[key].setdefault('sub_templates', {}).update(
394
  user_prompts[key]['sub_templates']
395
- )
396
  else:
397
  print(f"Invalid prompts.yaml structure. Using defaults. Got type: {type(user_prompts)}")
398
 
@@ -404,6 +406,11 @@ class MagAgent:
404
  if missing := required_keys - self.prompt_templates.keys():
405
  raise ValueError(f"Missing required prompt templates: {missing}")
406
 
 
 
 
 
 
407
 
408
  self.agent = CodeAgent(
409
  model=self.model,
 
380
  user_prompts = yaml.safe_load(f)
381
 
382
  # Validate loaded prompts structure
383
+ # In MagAgent's __init__ method:
384
  if isinstance(user_prompts, dict):
385
  for key in self.prompt_templates:
386
  if key in user_prompts:
387
+ # Merge main template properties
388
+ self.prompt_templates[key].update({
389
+ k: v for k, v in user_prompts[key].items()
390
+ if k in ['template', 'variables']
391
+ })
392
+
393
+ # Merge sub-templates if present
394
  if 'sub_templates' in user_prompts[key]:
395
  self.prompt_templates[key].setdefault('sub_templates', {}).update(
396
  user_prompts[key]['sub_templates']
397
+ )
398
  else:
399
  print(f"Invalid prompts.yaml structure. Using defaults. Got type: {type(user_prompts)}")
400
 
 
406
  if missing := required_keys - self.prompt_templates.keys():
407
  raise ValueError(f"Missing required prompt templates: {missing}")
408
 
409
+ # After loading templates, add:
410
+ planning_subtemplates = self.prompt_templates['planning'].get('sub_templates', {})
411
+ required_subtemplates = {'initial_plan', 'initial_facts'}
412
+ if missing := required_subtemplates - planning_subtemplates.keys():
413
+ raise ValueError(f"Missing required planning sub-templates: {missing}")
414
 
415
  self.agent = CodeAgent(
416
  model=self.model,