SergeyO7 commited on
Commit
5df360a
·
verified ·
1 Parent(s): bd57e5a

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +14 -12
agent.py CHANGED
@@ -377,11 +377,12 @@ class MagAgent:
377
 
378
  # Validate loaded prompts structure
379
  if isinstance(user_prompts, dict):
380
- # Merge with defaults, preserving missing keys
381
- self.prompt_templates.update({
382
- k: v for k, v in user_prompts.items()
383
- if k in self.prompt_templates
384
- })
 
385
  else:
386
  print(f"Invalid prompts.yaml structure. Using defaults. Got type: {type(user_prompts)}")
387
 
@@ -423,13 +424,14 @@ class MagAgent:
423
 
424
  def _build_task_prompt(self, question: str, task_id: str) -> str:
425
  """Constructs task-specific prompts using templates"""
426
- base_template = self.prompt_templates.get("base_prompt", "")
427
- task_template = self.prompt_templates.get("task_prompt", "").format(
428
- question=question,
429
- task_id=task_id,
430
- current_date=datetime.now().strftime("%Y-%m-%d")
431
- )
432
- return f"{base_template}\n\n{task_template}"
 
433
 
434
  async def _execute_agent(self, question: str, task_id: str) -> str:
435
  return await asyncio.to_thread(
 
377
 
378
  # Validate loaded prompts structure
379
  if isinstance(user_prompts, dict):
380
+ for key in self.prompt_templates.keys():
381
+ if key in user_prompts:
382
+ # Merge nested template dictionaries
383
+ self.prompt_templates[key].update(
384
+ user_prompts[key]
385
+ )
386
  else:
387
  print(f"Invalid prompts.yaml structure. Using defaults. Got type: {type(user_prompts)}")
388
 
 
424
 
425
  def _build_task_prompt(self, question: str, task_id: str) -> str:
426
  """Constructs task-specific prompts using templates"""
427
+ system_template = self.prompt_templates["system_prompt"]["template"]
428
+ managed_agent_template = self.prompt_templates["managed_agent"]["template"].format(
429
+ question_analysis=question,
430
+ subtasks=self._generate_subtasks(question),
431
+ validation_rules=self._get_validation_rules()
432
+ )
433
+
434
+ return f"{system_template}\n\n{managed_agent_template}"
435
 
436
  async def _execute_agent(self, question: str, task_id: str) -> str:
437
  return await asyncio.to_thread(