[bugfix] Normalize tool message content from array to string format (#39899)
Signed-off-by: JaredforReal <w13431838023@gmail.com>
This commit is contained in:
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user