Skip to content

fix(ai): align toolsToModelTools with core AI SDK's prepareToolsAndToolChoice#1544

Open
iNishant wants to merge 2 commits intovercel:mainfrom
iNishant:fix/tools-to-model-tools-strict-mode
Open

fix(ai): align toolsToModelTools with core AI SDK's prepareToolsAndToolChoice#1544
iNishant wants to merge 2 commits intovercel:mainfrom
iNishant:fix/tools-to-model-tools-strict-mode

Conversation

@iNishant
Copy link
Copy Markdown

@iNishant iNishant commented Mar 28, 2026

Summary

@workflow/ai's toolsToModelTools only forwards type, name, description, and inputSchema when building LanguageModelV3FunctionTool objects. The core AI SDK's prepareToolsAndToolChoice forwards three additional properties:

  • strict — enables strict schema validation on providers that support it (e.g. OpenAI)
  • inputExamples — optional examples for the language model
  • providerOptions — provider-specific tool options

This means tools using these properties lose them when run through DurableAgent.

This PR aligns toolsToModelTools with the core AI SDK's implementation in ai/src/prompt/prepare-tools-and-tool-choice.ts.

Changes

packages/ai/src/agent/tools-to-model-tools.ts

Before:

export function toolsToModelTools(
  tools: ToolSet
): LanguageModelV2FunctionTool[] {
  return Object.entries(tools).map(([name, tool]) => ({
    type: 'function',
    name,
    description: tool.description,
    inputSchema: asSchema(tool.inputSchema).jsonSchema,
  }));
}

After:

export async function toolsToModelTools(
  tools: ToolSet
): Promise<LanguageModelV3FunctionTool[]> {
  return Promise.all(
    Object.entries(tools).map(async ([name, tool]) => ({
      type: 'function' as const,
      name,
      description: tool.description,
      inputSchema: await asSchema(tool.inputSchema).jsonSchema,
      ...(tool.inputExamples != null
        ? { inputExamples: tool.inputExamples }
        : {}),
      providerOptions: tool.providerOptions,
      ...(tool.strict != null ? { strict: tool.strict } : {}),
    }))
  );
}

Also updates the return type from LanguageModelV2FunctionTool to LanguageModelV3FunctionTool and makes the function async to match the upstream signature change.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 28, 2026

🦋 Changeset detected

Latest commit: 9df0089

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 28, 2026

@iNishant is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

The core AI SDK's `prepareToolsAndToolChoice` already forwards
`tool.strict` when building `LanguageModelV2FunctionTool` objects,
but `@workflow/ai`'s `toolsToModelTools` does not.

This means tools with `strict: true` lose that flag when run
through DurableAgent, causing providers that support strict
schema validation to fall back to non-strict mode.

Align with the AI SDK by conditionally spreading `strict` when
the tool defines it.
@iNishant iNishant force-pushed the fix/tools-to-model-tools-strict-mode branch from 9ee5d52 to a113bad Compare March 28, 2026 11:27
@iNishant iNishant marked this pull request as ready for review March 28, 2026 11:29
@iNishant iNishant requested a review from a team as a code owner March 28, 2026 11:29
@iNishant iNishant changed the title fix(ai): align toolsToModelTools with AI SDK's prepareToolsAndToolChoice fix(ai): align toolsToModelTools with core AI SDK's prepareToolsAndToolChoice Mar 28, 2026
Copy link
Copy Markdown
Member

@VaguelySerious VaguelySerious left a comment

Choose a reason for hiding this comment

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

AI review: blocking issues found

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