Add image support in tool results across all providers

Tool results now use content blocks and can include both text and images.
All providers (Anthropic, Google, OpenAI Completions, OpenAI Responses)
correctly pass images from tool results to LLMs.

- Update ToolResultMessage type to use content blocks
- Add placeholder text for image-only tool results in Google/Anthropic
- OpenAI providers send tool result + follow-up user message with images
- Fix Anthropic JSON parsing for empty tool arguments
- Add comprehensive tests for image-only and text+image tool results
- Update README with tool result content blocks API
This commit is contained in:
Mario Zechner 2025-11-12 10:45:56 +01:00
parent 9dac37d836
commit 84dcab219b
37 changed files with 720 additions and 544 deletions

View file

@ -55,7 +55,7 @@ const providerContexts = {
role: "toolResult" as const,
toolCallId: "toolu_01abc123",
toolName: "get_weather",
output: "Weather in Tokyo: 18°C, partly cloudy",
content: [{ type: "text", text: "Weather in Tokyo: 18°C, partly cloudy" }],
isError: false,
timestamp: Date.now(),
} satisfies ToolResultMessage,
@ -106,7 +106,7 @@ const providerContexts = {
role: "toolResult" as const,
toolCallId: "call_gemini_123",
toolName: "get_weather",
output: "Weather in Berlin: 22°C, sunny",
content: [{ type: "text", text: "Weather in Berlin: 22°C, sunny" }],
isError: false,
timestamp: Date.now(),
} satisfies ToolResultMessage,
@ -156,7 +156,7 @@ const providerContexts = {
role: "toolResult" as const,
toolCallId: "call_abc123",
toolName: "get_weather",
output: "Weather in London: 15°C, rainy",
content: [{ type: "text", text: "Weather in London: 15°C, rainy" }],
isError: false,
timestamp: Date.now(),
} satisfies ToolResultMessage,
@ -208,7 +208,7 @@ const providerContexts = {
role: "toolResult" as const,
toolCallId: "call_789_item_012", // Match the updated ID format
toolName: "get_weather",
output: "Weather in Sydney: 25°C, clear",
content: [{ type: "text", text: "Weather in Sydney: 25°C, clear" }],
isError: false,
timestamp: Date.now(),
} satisfies ToolResultMessage,