Skip to content

Conversation

@stretpjc
Copy link

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)

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)
@stretpjc stretpjc requested a review from ibolmo January 20, 2026 22:05
* Transforms tools into ToolFunctionDefinition format for metadata.tools
* Output format: Array<{ type: "function", function: { name, description?, parameters?, strict? } }>
*/
const transformToolsForMetadata = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

}> => {
if (!tools || typeof tools !== "object") return [];

const result: Array<{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait. we shouldn't be messing with the user's input/data. we should be doing this chang ein the ai-sdk-converters

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.

3 participants