Skip to content

Tool results: support multi-part tool content output#155

Merged
msullivan merged 3 commits into
mainfrom
result-kind
May 29, 2026
Merged

Tool results: support multi-part tool content output#155
msullivan merged 3 commits into
mainfrom
result-kind

Conversation

@msullivan
Copy link
Copy Markdown
Contributor

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.

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_error and adding result_kind). We could avoid that if we
thought we should?

msullivan added 2 commits May 28, 2026 16:29
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.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-python Ready Ready Preview, Comment May 29, 2026 5:58pm

@msullivan msullivan merged commit 846e4fb into main May 29, 2026
7 checks passed
@msullivan msullivan deleted the result-kind branch May 29, 2026 18:00
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.

2 participants