add metadata.tools in ToolFunctionDefinition format to all spans#1291
Open
add metadata.tools in ToolFunctionDefinition format to all spans#1291
Conversation
Add tools to metadata.tools for all spans that use tools, formatted to match
the ToolFunctionDefinition schema:
{ type: "function", function: { name, description?, parameters?, strict? } }
Changes:
- Add transformToolsForMetadata() to convert AI SDK tool definitions (with Zod
schemas) into the standard ToolFunctionDefinition array format
- Add metadata.tools to generateText, generateObject, streamText, streamObject
root spans
- Add metadata.tools to doGenerate and doStream child spans (wrapModel)
ibolmo
reviewed
Jan 20, 2026
| * Transforms tools into ToolFunctionDefinition format for metadata.tools | ||
| * Output format: Array<{ type: "function", function: { name, description?, parameters?, strict? } }> | ||
| */ | ||
| const transformToolsForMetadata = ( |
Collaborator
There was a problem hiding this comment.
if you don't mind asking the ai to repro the problem with a change to ai-sdk.test.ts
but yeah this is the sort of change i'd expect
ibolmo
reviewed
Jan 21, 2026
| }> => { | ||
| if (!tools || typeof tools !== "object") return []; | ||
|
|
||
| const result: Array<{ |
Collaborator
There was a problem hiding this comment.
oh wait. we shouldn't be messing with the user's input/data. we should be doing this chang ein the ai-sdk-converters
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.
Add tools to metadata.tools for all spans that use tools, formatted to match the ToolFunctionDefinition schema:
{ type: "function", function: { name, description?, parameters?, strict? } }
Changes: