From 4cb94b18f1ad8d97e5c0a1b3dd15b5cf0d65074c Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Fri, 24 Apr 2026 23:06:24 -0400 Subject: [PATCH] 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) --- agent_service/routers/dispatch.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/agent_service/routers/dispatch.py b/agent_service/routers/dispatch.py index 5eff038..358d083 100644 --- a/agent_service/routers/dispatch.py +++ b/agent_service/routers/dispatch.py @@ -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,