[PoC] feat(anthropic): images in tool results - #5
Open
ayman3000 wants to merge 2 commits into
Open
Conversation
Lets a tool-result message carry images (e.g. a browser screenshot) so a vision model can see them. Anthropic places the image INSIDE the tool_result.content array, keeping it in the same user turn as the result — no user/assistant alternation break. - LLMMessage.tool(_:images:toolCallId:) convenience factory (struct already carried `images`). - AnthropicProvider: tool_result.content becomes [text, image…] blocks when images are present; text-only path unchanged (stays a string). - Deterministic wire-format tests proving the structure + alternation. PoC: Anthropic path only. OpenAI/Ollama (image on a following user message) and Gemini (inlineData beside functionResponse) are the generalization step. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Renders a solid-red PNG (CoreGraphics), sends it as a tool_result image to the real Anthropic API, and asserts the reply names 'red'. Gated on ANTHROPIC_API_KEY so it skips in normal runs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proof-of-concept — the Anthropic slice of feeding tool-result images (e.g. browser screenshots) to a vision model, to de-risk the trickiest provider before generalizing.
Why Anthropic first
Anthropic maps tool results to a user turn (
tool_resultblock). You can't add a second consecutive user message (alternation rule), so the image must live insidetool_result.content— which Anthropic supports as a[text|image]array. This PR proves that encoding.Changes
LLMMessage.tool(_:images:toolCallId:)factory (the struct already carriedimages).AnthropicProvider: when a tool message has images,tool_result.contentbecomes[{text}, {image}…]; text-only tool results stay a plain string (unchanged).tool_result.content, roles alternateuser/assistant/user, and text-only is untouched.Status / scope
inlineDatabesidefunctionResponse) are the generalization step. No live API call yet (needs a key).Pairs with SwiftAgentKit
feat/tool-result-images.🤖 Generated with Claude Code