Skip to content

[PoC] feat(anthropic): images in tool results - #5

Open
ayman3000 wants to merge 2 commits into
mainfrom
feat/tool-result-images
Open

[PoC] feat(anthropic): images in tool results#5
ayman3000 wants to merge 2 commits into
mainfrom
feat/tool-result-images

Conversation

@ayman3000

Copy link
Copy Markdown
Owner

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_result block). You can't add a second consecutive user message (alternation rule), so the image must live inside tool_result.content — which Anthropic supports as a [text|image] array. This PR proves that encoding.

Changes

  • LLMMessage.tool(_:images:toolCallId:) factory (the struct already carried images).
  • AnthropicProvider: when a tool message has images, tool_result.content becomes [{text}, {image}…]; text-only tool results stay a plain string (unchanged).
  • Deterministic tests: assert the image rides inside tool_result.content, roles alternate user/assistant/user, and text-only is untouched.

Status / scope

  • ✅ Full suite green (40 tests).
  • ⚠️ PoC — not for merge yet. OpenAI/Ollama (image on a following user message) and Gemini (inlineData beside functionResponse) are the generalization step. No live API call yet (needs a key).

Pairs with SwiftAgentKit feat/tool-result-images.

🤖 Generated with Claude Code

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>
@gemini-code-assist

Copy link
Copy Markdown

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant