Spaces:
Sleeping
Sleeping
| """ | |
| 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: | |
| # Create agent from template | |
| 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", "") | |
| ) | |
| # Register agent in memory | |
| 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") | |