| """ |
| Agent Initialization Fix for SAAP Backend |
| Ensures agents are loaded properly in memory |
| """ |
|
|
| import asyncio |
| import json |
| from pathlib import Path |
|
|
| async def initialize_default_agents(agent_manager): |
| """Initialize default agents in memory""" |
| templates_path = Path("src/backend/models/agent_templates.json") |
| |
| if templates_path.exists(): |
| with open(templates_path, 'r') as f: |
| templates = json.load(f) |
| |
| for agent_id, template in templates.items(): |
| try: |
| |
| from models.agent import SaapAgent |
| agent = SaapAgent( |
| id=template["id"], |
| name=template["name"], |
| type=template["type"], |
| status=template["status"], |
| description=template["description"], |
| capabilities=template["capabilities"], |
| llm_config=template["llm_config"], |
| personality=template.get("personality", {}), |
| system_prompt=template.get("system_prompt", "") |
| ) |
| |
| |
| agent_manager.agents[agent_id] = agent |
| print(f"✅ Initialized agent: {agent.name}") |
| |
| except Exception as e: |
| print(f"❌ Failed to initialize agent {agent_id}: {e}") |
| |
| print(f"✅ Agent initialization complete: {len(agent_manager.agents)} agents loaded") |
| return agent_manager.agents |
|
|
| if __name__ == "__main__": |
| print("Agent initialization fix loaded") |
|
|