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