Skip to content

Log error status of v2 chat agent correctly

Problem

Requesting to v2/chat/agent currently responds with 200 (success) response status even if it encountered an error.

How to reprorudce

diff --git a/ai_gateway/chat/agents/react.py b/ai_gateway/chat/agents/react.py
index 202eeaeb..994428bf 100644
--- a/ai_gateway/chat/agents/react.py
+++ b/ai_gateway/chat/agents/react.py
@@ -212,6 +212,8 @@ class ReActAgent(Prompt[ReActAgentInputs, TypeReActAgentAction]):
         astream = super().astream(input, config=config, **kwargs)
 
         async for action in astream:
+            raise ValueError("test")
+        
             if isinstance(action, ReActAgentToolAction):
                 state["tool_action"] = action
             elif isinstance(action, ReActAgentFinalAnswer) and len(action.text) > 0:

and

curl -X 'POST' \
  'http://localhost:5052/v2/chat/agent' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "prompt": "Hi, how are you?",
  "options": {
    "chat_history": "string",
    "agent_scratchpad": {
      "agent_type": "react",
      "steps": []
    }
  }
}'

Proposal

Raise HTTPException to return client side errors (4XX) or server side errors (5xx) to clients.

Edited by Shinya Maeda