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.
This commit is contained in:
Willem Jiang
2025-10-20 23:10:58 +08:00
committed by GitHub
parent 984aa69acf
commit 3689bc0e69
2 changed files with 6 additions and 2 deletions

View File

@@ -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

View File

@@ -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") {