mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-28 21:27:14 +00:00
fix(provider): stringify MCP tool results for OpenAI-compatible APIs (#2476)
execute_func_call returns list[ContentElement] for MCP tools, but the runner assigned that list directly to the tool-message content. The OpenAI chat-completions spec requires tool-message content to be a string, so OpenAI-compatible endpoints return HTTP 500 when the raw list is sent. Serialize the list to a string before building the tool message, using ContentElement.__str__ which returns the text payload for text elements and a human-readable placeholder for images and files. Fixes #2457.
This commit is contained in:
@@ -619,7 +619,9 @@ class LocalAgentRunner(runner.RequestRunner):
|
||||
and len(func_ret) > 0
|
||||
and isinstance(func_ret[0], provider_message.ContentElement)
|
||||
):
|
||||
tool_content = func_ret
|
||||
# OpenAI-compatible APIs require tool-message content to be a
|
||||
# string; a raw list of ContentElement causes HTTP 500 (#2457).
|
||||
tool_content = '\n'.join(str(ce) for ce in func_ret)
|
||||
else:
|
||||
tool_content = json.dumps(func_ret, ensure_ascii=False)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user