fix(anthropic-adapter): preserve image blocks in tool results during format conversion

When converting Anthropic /v1/messages to OpenAI /v1/chat/completions format,
single-image tool results had their image data stored as a plain URL string
in ChatCompletionToolMessage.content, instead of a structured
ChatCompletionImageObject list. This caused downstream models (e.g. vLLM) to
treat the base64 data URI as plain text, making image recognition fail.

The multi-item tool result path already handled this correctly by creating a
ChatCompletionImageObject. This fix applies the same pattern to the
single-item case.
This commit is contained in:
zhanghao 2026-04-10 13:58:54 +08:00
parent 9e6d2d2069
commit b510628bc2

View file

@ -480,7 +480,12 @@ class LiteLLMAnthropicMessagesAdapter:
tool_call_id=content.get(
"tool_use_id", ""
),
content=openai_image_url,
content=[ChatCompletionImageObject(
type="image_url",
image_url=ChatCompletionImageUrlObject(
url=openai_image_url
),
)],
)
self._add_cache_control_if_applicable(
content, tool_result, model