Skip to content

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

Merged
VaguelySerious merged 7 commits intovercel:mainfrom
iNishant:fix/tools-to-model-tools-strict-mode
Apr 17, 2026
Merged

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

Conversation

@iNishant
Copy link
Copy Markdown
Contributor

@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: 84818d5

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

Comment thread packages/ai/src/agent/tools-to-model-tools.ts Outdated
Comment thread packages/ai/src/agent/tools-to-model-tools.ts Outdated
Comment thread packages/ai/src/agent/tools-to-model-tools.ts
@iNishant iNishant force-pushed the fix/tools-to-model-tools-strict-mode branch 4 times, most recently from 7781a25 to 9df0089 Compare April 10, 2026 14:06
…ols-strict-mode

# Conflicts:
#	packages/ai/src/agent/tools-to-model-tools.test.ts
#	packages/ai/src/agent/tools-to-model-tools.ts
@iNishant iNishant force-pushed the fix/tools-to-model-tools-strict-mode branch from 5c9549c to 595f700 Compare April 16, 2026 20:58
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@iNishant
Copy link
Copy Markdown
Contributor Author

@VaguelySerious good to go?

iNishant and others added 2 commits April 17, 2026 02:39
@VaguelySerious
Copy link
Copy Markdown
Member

VaguelySerious commented Apr 16, 2026

@iNishant Thanks for the reminder, yes. DCO is failing, could you ensure that passes? Will merge after

I, inishant <saysnishant@gmail.com>, hereby add my Signed-off-by to this commit: a113bad
I, inishant <saysnishant@gmail.com>, hereby add my Signed-off-by to this commit: 9df0089
I, inishant <saysnishant@gmail.com>, hereby add my Signed-off-by to this commit: 03ce3d7
I, inishant <saysnishant@gmail.com>, hereby add my Signed-off-by to this commit: 65e20ae

Signed-off-by: inishant <saysnishant@gmail.com>
@iNishant
Copy link
Copy Markdown
Contributor Author

@VaguelySerious did the DCO thing.

@VaguelySerious VaguelySerious merged commit 3f6d98f into vercel:main Apr 17, 2026
3 of 17 checks passed
@VaguelySerious
Copy link
Copy Markdown
Member

Thanks for your patience!

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