fix(agent): align /dispatch with MasterAgent.handle_message signature

The router was calling handle_message(user_id, message, context, session_id)
but MasterAgent accepts (user_id, channel_id, message, directive_id) and
returns MasterResponse{response, status, ...} with no .reply or
.agent_reports fields. Discuss DMs to the bot crashed with TypeError.

Now the router:
- Derives directive_id from session_id (or generates one)
- Pulls channel_id out of req.context
- Maps MasterResponse.response -> DispatchResponse.reply
- Returns an empty agent_reports list (the field is reserved for future use;
  per-agent reports aren't part of MasterResponse)
This commit is contained in:
Carlos Garcia
2026-04-24 23:06:24 -04:00
parent beb08b0b4b
commit 4cb94b18f1

View File

@@ -4,6 +4,7 @@ import hashlib
import hmac
import logging
import time
import uuid
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Request, status
@@ -73,13 +74,16 @@ async def dispatch(req: DispatchRequest, request: Request):
settings = get_settings()
timeout = settings.directive_timeout_minutes * 60
directive_id = req.session_id or uuid.uuid4().hex
channel_id = req.context.get('channel_id') if isinstance(req.context, dict) else None
try:
response = await asyncio.wait_for(
master.handle_message(
user_id=req.user_id,
channel_id=channel_id,
message=req.message,
context=req.context,
session_id=req.session_id,
directive_id=directive_id,
),
timeout=timeout,
)
@@ -94,8 +98,8 @@ async def dispatch(req: DispatchRequest, request: Request):
return DispatchResponse(
directive_id=response.directive_id,
reply=response.reply,
agent_reports=[r.dict() if hasattr(r, 'dict') else r for r in response.agent_reports],
reply=response.response,
agent_reports=[],
escalations=response.escalations,
actions_taken=response.actions_taken,
session_id=req.session_id,