From bb1e93fabb467cb873b16d9e01db37bf80ad8306 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Sat, 16 May 2026 16:31:45 -0400 Subject: [PATCH] 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 --- addons/activeblue_ai/models/ab_ai_mail.py | 17 ++++++++++++++++- agent_service/routers/dispatch.py | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/addons/activeblue_ai/models/ab_ai_mail.py b/addons/activeblue_ai/models/ab_ai_mail.py index 29fd17d..70ac3c9 100644 --- a/addons/activeblue_ai/models/ab_ai_mail.py +++ b/addons/activeblue_ai/models/ab_ai_mail.py @@ -117,9 +117,24 @@ def _agent_thread(db: str, uid: int, text: str, att_data: list, 'I could not process your request right now.' except _requests.exceptions.Timeout: 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: _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) diff --git a/agent_service/routers/dispatch.py b/agent_service/routers/dispatch.py index 358d083..4a3eefd 100644 --- a/agent_service/routers/dispatch.py +++ b/agent_service/routers/dispatch.py @@ -5,7 +5,7 @@ import hmac import logging import time import uuid -from typing import Optional +from typing import Any, Optional from fastapi import APIRouter, Depends, HTTPException, Request, status from pydantic import BaseModel, Field @@ -31,7 +31,7 @@ class DispatchResponse(BaseModel): reply: str agent_reports: list[dict] = [] escalations: list[str] = [] - actions_taken: list[dict] = [] + actions_taken: list[Any] = [] session_id: Optional[str] = None