anderson-ufrj Claude commited on
Commit
1955e9b
·
1 Parent(s): 05ab472

fix: resolve agent initialization error causing maintenance mode

Browse files

- Add proper agent initialization in ChatService._initialize_agents()
- Create master_agent instance in chat.py routes
- Add agent_id attribute to all agent instances
- Update Makefile to use python3 instead of python3.11

This fix enables the multi-agent system to process messages correctly,
routing conversations to appropriate agents (Drummond, Zumbi, Anita, etc.)
instead of returning maintenance mode responses.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

Makefile CHANGED
@@ -4,7 +4,7 @@
4
  .DEFAULT_GOAL := help
5
 
6
  # Variables
7
- PYTHON := python3.11
8
  PIP := $(PYTHON) -m pip
9
  PYTEST := $(PYTHON) -m pytest
10
  BLACK := $(PYTHON) -m black
 
4
  .DEFAULT_GOAL := help
5
 
6
  # Variables
7
+ PYTHON := python3
8
  PIP := $(PYTHON) -m pip
9
  PYTEST := $(PYTHON) -m pytest
10
  BLACK := $(PYTHON) -m black
src/api/routes/chat.py CHANGED
@@ -25,6 +25,9 @@ router = APIRouter(prefix="/api/v1/chat", tags=["chat"])
25
  # Services are already initialized
26
  intent_detector = IntentDetector()
27
 
 
 
 
28
  class ChatRequest(BaseModel):
29
  """Chat message request"""
30
  message: str = Field(..., min_length=1, max_length=1000)
 
25
  # Services are already initialized
26
  intent_detector = IntentDetector()
27
 
28
+ # Initialize master agent
29
+ master_agent = MasterAgent()
30
+
31
  class ChatRequest(BaseModel):
32
  """Chat message request"""
33
  message: str = Field(..., min_length=1, max_length=1000)
src/services/chat_service.py CHANGED
@@ -366,8 +366,8 @@ class ChatService:
366
  self.sessions: Dict[str, ChatSession] = {}
367
  self.messages: Dict[str, List[Dict]] = defaultdict(list)
368
 
369
- # Agents will be initialized lazily when needed
370
- self.agents = {}
371
 
372
  async def get_or_create_session(
373
  self,
@@ -444,4 +444,27 @@ class ChatService:
444
  """Update session with current investigation"""
445
  if session_id in self.sessions:
446
  self.sessions[session_id].current_investigation_id = investigation_id
447
- self.sessions[session_id].last_activity = datetime.utcnow()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  self.sessions: Dict[str, ChatSession] = {}
367
  self.messages: Dict[str, List[Dict]] = defaultdict(list)
368
 
369
+ # Initialize agents
370
+ self._initialize_agents()
371
 
372
  async def get_or_create_session(
373
  self,
 
444
  """Update session with current investigation"""
445
  if session_id in self.sessions:
446
  self.sessions[session_id].current_investigation_id = investigation_id
447
+ self.sessions[session_id].last_activity = datetime.utcnow()
448
+
449
+ def _initialize_agents(self):
450
+ """Initialize available agents"""
451
+ # Import here to avoid circular imports
452
+ from src.agents import (
453
+ MasterAgent, InvestigatorAgent, AnalystAgent,
454
+ ReporterAgent, CommunicationAgent
455
+ )
456
+
457
+ # Create agent instances
458
+ agents = {
459
+ "abaporu": MasterAgent(),
460
+ "zumbi": InvestigatorAgent(),
461
+ "anita": AnalystAgent(),
462
+ "tiradentes": ReporterAgent(),
463
+ "drummond": CommunicationAgent()
464
+ }
465
+
466
+ # Add agent_id attribute to each agent
467
+ for agent_id, agent in agents.items():
468
+ agent.agent_id = agent_id
469
+
470
+ self.agents = agents