[bugfix] Normalize tool message content from array to string format (#39899)

Signed-off-by: JaredforReal <w13431838023@gmail.com>
This commit is contained in:
Jared Wen
2026-04-16 11:54:39 -07:00
committed by GitHub
parent 3abb7560c0
commit afabb5f45a
+12
View File
@@ -1550,6 +1550,18 @@ def _parse_chat_message_content(
parsed_msg = _ToolParser(message)
if "tool_call_id" in parsed_msg:
result_msg["tool_call_id"] = parsed_msg["tool_call_id"]
# Normalize tool message content from OpenAI array format to plain
# string. Clients like Claude Code / Cursor send tool results as
# [{"type": "text", "text": "..."}], but most chat templates only
# handle string content for tool messages.
msg_content = result_msg.get("content")
if isinstance(msg_content, list):
texts = [
item.get("text", "")
for item in msg_content
if isinstance(item, dict) and item.get("type") == "text"
]
result_msg["content"] = "\n".join(texts) if texts else ""
if "name" in message and isinstance(message["name"], str):
result_msg["name"] = message["name"]