fix: widen actions_taken to list[Any] and improve bot error replies

DispatchResponse declared actions_taken as list[dict] but agents return
list[str], causing a 422 on every successful upload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Carlos Garcia
2026-05-16 16:31:45 -04:00
parent cf3fe5e0a5
commit bb1e93fabb
2 changed files with 18 additions and 3 deletions

View File

@@ -117,9 +117,24 @@ def _agent_thread(db: str, uid: int, text: str, att_data: list,
'I could not process your request right now.' 'I could not process your request right now.'
except _requests.exceptions.Timeout: except _requests.exceptions.Timeout:
reply_text = 'The request timed out. Please try again.' reply_text = 'The request timed out. Please try again.'
except _requests.exceptions.HTTPError as exc:
# Try to surface the server-side error detail so the user knows what failed
detail = ''
try:
detail = exc.response.json().get('detail') or ''
except Exception:
pass
_logger.error('Agent HTTP error channel=%s status=%s: %s',
channel_id, exc.response.status_code if exc.response else '?', exc)
if detail:
reply_text = f'The agent returned an error: {detail}'
else:
reply_text = (f'The agent service returned an unexpected error '
f'(HTTP {exc.response.status_code if exc.response else "?"}). '
f'Please try again or contact your administrator.')
except Exception as exc: except Exception as exc:
_logger.error('Agent thread error channel=%s: %s', channel_id, exc) _logger.error('Agent thread error channel=%s: %s', channel_id, exc)
reply_text = 'I encountered an error. Please try again or contact your administrator.' reply_text = f'I encountered an error: {exc}'
_post_bot_reply(db, channel_id, bot_partner_id, reply_text) _post_bot_reply(db, channel_id, bot_partner_id, reply_text)

View File

@@ -5,7 +5,7 @@ import hmac
import logging import logging
import time import time
import uuid import uuid
from typing import Optional from typing import Any, Optional
from fastapi import APIRouter, Depends, HTTPException, Request, status from fastapi import APIRouter, Depends, HTTPException, Request, status
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@@ -31,7 +31,7 @@ class DispatchResponse(BaseModel):
reply: str reply: str
agent_reports: list[dict] = [] agent_reports: list[dict] = []
escalations: list[str] = [] escalations: list[str] = []
actions_taken: list[dict] = [] actions_taken: list[Any] = []
session_id: Optional[str] = None session_id: Optional[str] = None