File size: 1,642 Bytes
4343907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
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")