Tool results: Make ToolResultOutput typed, support multipart output#153
Closed
msullivan wants to merge 2 commits into
Closed
Tool results: Make ToolResultOutput typed, support multipart output#153msullivan wants to merge 2 commits into
msullivan wants to merge 2 commits into
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.
The approach I take is that the result of a tool becomes a tagged
union, similar to how AI SDK does it.
New types (src/ai/types/messages.py):
ToolResultOutput =
| TextOutput # {type:"text", value:str}
| JsonOutput # {type:"json", value:Any}
| ContentOutput # {type:"content", value:list[TextPart|FilePart]}
| ErrorTextOutput # {type:"error-text", value:str}
| ErrorJsonOutput # {type:"error-json", value:Any}
| ExecutionDeniedOutput # {type:"execution-denied", reason?:str}
Tool return processing will then preserve a ToolResultOutput while
coercing other types into it. Currently, `BaseModel` gets preserved as
part of JsonOutput (because UI outbound still depends on it), which is
not really correct and should be revisisted.
BACKWARDS COMPATABILITY: This is a compatability break, though, since
it changes the type of `result`. There is soem compatability goo
though where we still try to accept "raw" results on input to
ToolResultPart, so that loading old saved messages will still work. I
don't know if anybody in the world would benefit from this other than
my saved `tau` sessions though so maybe we don't need it?
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
The approach I take is that the result of a tool becomes a tagged
union, similar to how AI SDK does it.
Tool return processing will then preserve a ToolResultOutput while
coercing other types into it. Currently,
BaseModelgets preserved aspart of JsonOutput (because UI outbound still depends on it), which is
not really correct and should be revisisted.
BACKWARDS COMPATABILITY: This is a compatability break, though, since
it changes the type of
result. There is soem compatability goothough where we still try to accept "raw" results on input to
ToolResultPart, so that loading old saved messages will still work. I
don't know if anybody in the world would benefit from this other than
my saved
tausessions though so maybe we don't need it?