anderson-ufrj commited on
Commit
3414466
·
1 Parent(s): eb127f7

fix: resolve chat endpoint errors for Drummond agent

Browse files

- Fix undefined 'context' variable by creating AgentContext properly
- Fix response validation error for investigation endpoint
- Ensure proper ChatResponse format is returned in all cases
- This fixes the 500 error when using Drummond with Maritaca AI

Files changed (1) hide show
  1. src/api/routes/chat.py +17 -8
src/api/routes/chat.py CHANGED
@@ -156,6 +156,13 @@ async def send_message(
156
  }
157
  )
158
 
 
 
 
 
 
 
 
159
  # Route to appropriate agent based on intent
160
  logger.info(f"Target agent: {target_agent}")
161
 
@@ -166,7 +173,7 @@ async def send_message(
166
  drummond_agent = await get_drummond_agent()
167
 
168
  if drummond_agent:
169
- response = await drummond_agent.process(agent_message, context)
170
  drummond_loaded = True
171
  else:
172
  raise Exception("Drummond agent not available")
@@ -240,13 +247,15 @@ async def send_message(
240
  # NOTE: Enhanced Zumbi temporarily disabled to fix circular import
241
  investigation_result = None
242
  if investigation_result is None:
243
- # Return a simple error for now
244
- return {
245
- "response": "Desculpe, o sistema de investigação está temporariamente indisponível. Por favor, tente novamente mais tarde.",
246
- "session_id": session_id,
247
- "message_id": str(uuid.uuid4()),
248
- "timestamp": datetime.utcnow().isoformat()
249
- }
 
 
250
 
251
  # Format response
252
  message = f"🏹 **Investigação Concluída**\n\n"
 
156
  }
157
  )
158
 
159
+ # Create agent context
160
+ agent_context = AgentContext(
161
+ investigation_id=session.current_investigation_id,
162
+ user_id=session.user_id,
163
+ session_id=session_id
164
+ )
165
+
166
  # Route to appropriate agent based on intent
167
  logger.info(f"Target agent: {target_agent}")
168
 
 
173
  drummond_agent = await get_drummond_agent()
174
 
175
  if drummond_agent:
176
+ response = await drummond_agent.process(agent_message, agent_context)
177
  drummond_loaded = True
178
  else:
179
  raise Exception("Drummond agent not available")
 
247
  # NOTE: Enhanced Zumbi temporarily disabled to fix circular import
248
  investigation_result = None
249
  if investigation_result is None:
250
+ # Return a properly formatted response
251
+ return ChatResponse(
252
+ session_id=session_id,
253
+ agent_id="system",
254
+ agent_name="Sistema",
255
+ message="Desculpe, o sistema de investigação está temporariamente indisponível. Por favor, tente novamente mais tarde.",
256
+ confidence=0.0,
257
+ metadata={"status": "investigation_unavailable"}
258
+ )
259
 
260
  # Format response
261
  message = f"🏹 **Investigação Concluída**\n\n"