From 3689bc0e69dc6fd6404863ec208f362d2acbb689 Mon Sep 17 00:00:00 2001 From: Willem Jiang Date: Mon, 20 Oct 2025 23:10:58 +0800 Subject: [PATCH] fix: handle non-string tool results to fix #631 (#633) - Backend: Convert non-string content (lists, dicts) to JSON strings in _create_event_stream_message to ensure frontend always receives string content - Frontend: Add type guard before calling startsWith() on toolCall.result for defensive programming This fixes the TypeError: toolCall.result.startsWith is not a function when tools return complex objects. --- src/server/app.py | 6 +++++- web/src/app/chat/components/research-activities-block.tsx | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/app.py b/src/server/app.py index c1414a7..dc087a6 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -157,6 +157,10 @@ def _create_event_stream_message( message_chunk, message_metadata, thread_id, agent_name ): """Create base event stream message.""" + content = message_chunk.content + if not isinstance(content, str): + content = json.dumps(content, ensure_ascii=False) + event_stream_message = { "thread_id": thread_id, "agent": agent_name, @@ -166,7 +170,7 @@ def _create_event_stream_message( "langgraph_node": message_metadata.get("langgraph_node", ""), "langgraph_path": message_metadata.get("langgraph_path", ""), "langgraph_step": message_metadata.get("langgraph_step", ""), - "content": message_chunk.content, + "content": content, } # Add optional fields diff --git a/web/src/app/chat/components/research-activities-block.tsx b/web/src/app/chat/components/research-activities-block.tsx index 2e83196..3da1172 100644 --- a/web/src/app/chat/components/research-activities-block.tsx +++ b/web/src/app/chat/components/research-activities-block.tsx @@ -105,7 +105,7 @@ const ActivityListItem = React.memo(({ messageId }: { messageId: string }) => { if (message) { if (!message.isStreaming && message.toolCalls?.length) { for (const toolCall of message.toolCalls) { - if (toolCall.result?.startsWith("Error")) { + if (typeof toolCall.result === "string" && toolCall.result?.startsWith("Error")) { return null; } if (toolCall.name === "web_search") {