Commit
·
7dd9795
1
Parent(s):
a5d9083
cumulative upgrade - context + safety + response length v3
Browse files
src/agents/synthesis_agent.py
CHANGED
|
@@ -267,13 +267,36 @@ class EnhancedSynthesisAgent:
|
|
| 267 |
if not isinstance(user_input, str):
|
| 268 |
user_input = str(user_input) if user_input else ''
|
| 269 |
|
| 270 |
-
# Default agent_outputs to empty list
|
| 271 |
if agent_outputs is None:
|
| 272 |
agent_outputs = []
|
| 273 |
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
# STEP 1: Extract skill probabilities from skills_result
|
| 279 |
skill_probabilities = self._extract_skill_probabilities(skills_result)
|
|
@@ -459,9 +482,36 @@ RESPONSE GUIDELINES:
|
|
| 459 |
# Build agent outputs section if any
|
| 460 |
agent_outputs_section = ""
|
| 461 |
if agent_outputs:
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
|
| 466 |
# Construct full prompt
|
| 467 |
prompt = f"""{expert_preamble}
|
|
|
|
| 267 |
if not isinstance(user_input, str):
|
| 268 |
user_input = str(user_input) if user_input else ''
|
| 269 |
|
| 270 |
+
# Default agent_outputs to empty list and normalize format
|
| 271 |
if agent_outputs is None:
|
| 272 |
agent_outputs = []
|
| 273 |
|
| 274 |
+
# Normalize agent_outputs: convert dict to list if needed
|
| 275 |
+
if isinstance(agent_outputs, dict):
|
| 276 |
+
# Convert dict {task_name: result} to list of dicts
|
| 277 |
+
normalized_outputs = []
|
| 278 |
+
for task_name, result in agent_outputs.items():
|
| 279 |
+
if isinstance(result, dict):
|
| 280 |
+
# Add task name to the result dict for context
|
| 281 |
+
result_with_task = result.copy()
|
| 282 |
+
result_with_task['task_name'] = task_name
|
| 283 |
+
normalized_outputs.append(result_with_task)
|
| 284 |
+
else:
|
| 285 |
+
# Wrap non-dict results
|
| 286 |
+
normalized_outputs.append({
|
| 287 |
+
'task_name': task_name,
|
| 288 |
+
'content': str(result),
|
| 289 |
+
'result': str(result)
|
| 290 |
+
})
|
| 291 |
+
agent_outputs = normalized_outputs
|
| 292 |
+
|
| 293 |
+
# Ensure it's a list
|
| 294 |
+
if not isinstance(agent_outputs, list):
|
| 295 |
+
agent_outputs = [agent_outputs] if agent_outputs else []
|
| 296 |
+
|
| 297 |
+
logger.info(f"{self.agent_id} synthesizing {len(agent_outputs)} agent outputs")
|
| 298 |
+
if context:
|
| 299 |
+
logger.info(f"{self.agent_id} context has {len(context.get('interactions', []))} interactions")
|
| 300 |
|
| 301 |
# STEP 1: Extract skill probabilities from skills_result
|
| 302 |
skill_probabilities = self._extract_skill_probabilities(skills_result)
|
|
|
|
| 482 |
# Build agent outputs section if any
|
| 483 |
agent_outputs_section = ""
|
| 484 |
if agent_outputs:
|
| 485 |
+
# Handle both dict and list formats
|
| 486 |
+
if isinstance(agent_outputs, dict):
|
| 487 |
+
# Convert dict to list format
|
| 488 |
+
outputs_list = []
|
| 489 |
+
for task_name, result in agent_outputs.items():
|
| 490 |
+
if isinstance(result, dict):
|
| 491 |
+
outputs_list.append(result)
|
| 492 |
+
else:
|
| 493 |
+
# Wrap string/non-dict results in dict format
|
| 494 |
+
outputs_list.append({
|
| 495 |
+
'task': task_name,
|
| 496 |
+
'content': str(result),
|
| 497 |
+
'result': str(result)
|
| 498 |
+
})
|
| 499 |
+
agent_outputs = outputs_list
|
| 500 |
+
|
| 501 |
+
# Ensure it's a list now
|
| 502 |
+
if isinstance(agent_outputs, list):
|
| 503 |
+
agent_outputs_section = f"\n\nAgent Analysis Results:\n"
|
| 504 |
+
for i, output in enumerate(agent_outputs, 1):
|
| 505 |
+
# Handle both dict and string outputs
|
| 506 |
+
if isinstance(output, dict):
|
| 507 |
+
output_text = output.get('content') or output.get('result') or output.get('final_response') or str(output)
|
| 508 |
+
else:
|
| 509 |
+
# If output is a string or other type
|
| 510 |
+
output_text = str(output)
|
| 511 |
+
agent_outputs_section += f"Agent {i}: {output_text}\n"
|
| 512 |
+
else:
|
| 513 |
+
# Fallback for unexpected types
|
| 514 |
+
agent_outputs_section = f"\n\nAgent Analysis Results:\n{str(agent_outputs)}\n"
|
| 515 |
|
| 516 |
# Construct full prompt
|
| 517 |
prompt = f"""{expert_preamble}
|