Tool results: support multi-part tool content output#155
Merged
Conversation
The core goal here is to support image output from tools, so that we can support a read file tool that returns an image, or a screenshot tool, etc. We add a ContentOutput type that contains `list[TextPart|FilePart]` and is handled specially by the tool calling code. `ToolResultPart` gets a `result_kind` field that can signal the presence of `ContentOutput` while encoding/decoding. BACKWARDS COMPATABILITY: This is a compatability break, though, since it changes the serialized fields on ToolResultOutput (eliminating `is_error` and adding `result_kind`).
A content tool result's multipart payload already round-trips inside the UI tool part's `output`, but the signal to rehydrate it as a typed `ContentOutput` was lost on the way back in -- it landed as opaque JSON. Carry the signal through the existing `aiPython` adapter metadata channel (the same one used for source ids), keyed by tool_call_id: outbound records `toolResultKinds` for content results, inbound looks it up and rebuilds the ContentOutput so providers re-expand it into multimodal blocks. Only `content` is recorded -- `error` rides the UI `state` enum and `json` is the default.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
anbuzin
approved these changes
May 29, 2026
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.
The core goal here is to support image output from tools, so that we
can support a read file tool that returns an image, or a screenshot
tool, etc.
We add a ContentOutput type that contains
list[TextPart|FilePart]and is handled specially by the tool calling code.
ToolResultPartgets aresult_kindfield that can signal thepresence of
ContentOutputwhile encoding/decoding.We use UI protocol metadata to round trip that flag through the UI
protocol. That's in a separate commit because I'm not as sure about
it.
BACKWARDS COMPATABILITY: This is a compatability break, though, since
it changes the serialized fields on ToolResultOutput (eliminating
is_errorand addingresult_kind). We could avoid that if wethought we should?