Unverified Commit afabb5f4 authored by Jared Wen's avatar Jared Wen Committed by GitHub
Browse files

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


Signed-off-by: default avatarJaredforReal <w13431838023@gmail.com>
parent 3abb7560
...@@ -1550,6 +1550,18 @@ def _parse_chat_message_content( ...@@ -1550,6 +1550,18 @@ def _parse_chat_message_content(
parsed_msg = _ToolParser(message) parsed_msg = _ToolParser(message)
if "tool_call_id" in parsed_msg: if "tool_call_id" in parsed_msg:
result_msg["tool_call_id"] = parsed_msg["tool_call_id"] 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): if "name" in message and isinstance(message["name"], str):
result_msg["name"] = message["name"] result_msg["name"] = message["name"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment