anderson-ufrj
commited on
Commit
·
f81934c
1
Parent(s):
5e8dbb9
fix: add debug logging to identify Drummond agent initialization issues
Browse files- Add detailed logging for agent creation and message processing
- Log target agent selection and availability status
- Include traceback for initialization failures
- Help diagnose why agent falls back to maintenance message
- src/api/routes/chat.py +17 -5
src/api/routes/chat.py
CHANGED
|
@@ -28,9 +28,11 @@ intent_detector = IntentDetector()
|
|
| 28 |
# Initialize Drummond agent
|
| 29 |
try:
|
| 30 |
drummond_agent = CommunicationAgent()
|
| 31 |
-
logger.info("Drummond agent
|
| 32 |
except Exception as e:
|
| 33 |
-
logger.error(f"Failed to
|
|
|
|
|
|
|
| 34 |
drummond_agent = None
|
| 35 |
|
| 36 |
class ChatRequest(BaseModel):
|
|
@@ -105,13 +107,23 @@ async def send_message(
|
|
| 105 |
)
|
| 106 |
|
| 107 |
# Route to appropriate agent based on intent
|
|
|
|
|
|
|
| 108 |
if target_agent == "drummond" and drummond_agent:
|
| 109 |
# Use Drummond for conversational intents
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
else:
|
| 114 |
# For now, return a simple response if agents are not available
|
|
|
|
| 115 |
response = AgentResponse(
|
| 116 |
agent_name="Sistema",
|
| 117 |
status=AgentStatus.COMPLETED,
|
|
|
|
| 28 |
# Initialize Drummond agent
|
| 29 |
try:
|
| 30 |
drummond_agent = CommunicationAgent()
|
| 31 |
+
logger.info("Drummond agent created successfully")
|
| 32 |
except Exception as e:
|
| 33 |
+
logger.error(f"Failed to create Drummond agent: {e}")
|
| 34 |
+
import traceback
|
| 35 |
+
traceback.print_exc()
|
| 36 |
drummond_agent = None
|
| 37 |
|
| 38 |
class ChatRequest(BaseModel):
|
|
|
|
| 107 |
)
|
| 108 |
|
| 109 |
# Route to appropriate agent based on intent
|
| 110 |
+
logger.info(f"Target agent: {target_agent}, Drummond available: {drummond_agent is not None}")
|
| 111 |
+
|
| 112 |
if target_agent == "drummond" and drummond_agent:
|
| 113 |
# Use Drummond for conversational intents
|
| 114 |
+
try:
|
| 115 |
+
response = await drummond_agent.process(agent_message)
|
| 116 |
+
agent_id = "drummond"
|
| 117 |
+
agent_name = "Carlos Drummond de Andrade"
|
| 118 |
+
logger.info(f"Drummond response received: {response}")
|
| 119 |
+
except Exception as e:
|
| 120 |
+
logger.error(f"Error processing with Drummond: {e}")
|
| 121 |
+
import traceback
|
| 122 |
+
traceback.print_exc()
|
| 123 |
+
raise
|
| 124 |
else:
|
| 125 |
# For now, return a simple response if agents are not available
|
| 126 |
+
logger.warning(f"Falling back to maintenance message. Target: {target_agent}, Drummond: {drummond_agent}")
|
| 127 |
response = AgentResponse(
|
| 128 |
agent_name="Sistema",
|
| 129 |
status=AgentStatus.COMPLETED,
|