feat (provider/openai): support custom tools#12948
Merged
Conversation
packages/openai/src/responses/openai-responses-language-model.ts
Outdated
Show resolved
Hide resolved
mclenhard
approved these changes
Feb 28, 2026
dancer
approved these changes
Feb 28, 2026
Contributor
|
🚀 Published in:
|
4 tasks
dancer
added a commit
that referenced
this pull request
Mar 18, 2026
…3071) ## background followup to #12948. lars feedback: custom tools required a separate `name` field in args that duplicated the sdk tool key. every other provider tool derives its name from the key automatically. the extra `name` introduced alias mapping complexity and the `resolveProviderToolName` extension to `createToolNameMapping` ## summary - remove `name` from `customTool` args schema and type - use the sdk tool key (`tool.name`) as the name sent to openai - remove `resolveProviderToolName` from `createToolNameMapping` in provider-utils - remove alias mapping tests and repro examples - update docs and examples ## before ```ts tools: { write_sql: openai.tools.customTool({ name: 'write_sql', // redundant description: '...', }), } ``` ## after ```ts tools: { write_sql: openai.tools.customTool({ description: '...', }), } ``` ## verification - `pnpm tsx src/generate-text/openai/responses-custom-tool.ts` - `pnpm tsx src/stream-text/openai/responses-custom-tool.ts` - `pnpm tsx src/generate-text/openai/responses-custom-tool-multi-turn.ts` - `pnpm tsx src/stream-text/openai/responses-custom-tool-multi-turn.ts` ## checklist - [x] tests have been added / updated (for bug fixes / features) - [x] documentation has been added / updated (for bug fixes / features) - [x] a _patch_ changeset for relevant packages has been added (run `pnpm changeset` in root) - [x] i have reviewed this pull request (self-review)
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.

background
adds support for openai custom tools in responses and fixes alias mapping failures that could cause runtime errors
refs https://developers.openai.com/api/reference/resources/responses/methods/create/
summary
before this fix
after this fix
{ type: 'custom', name: 'write_sql' }and executes correctlyalias_namerepro
repro-alias-forced
before fix (
368bbdd468)git checkout 368bbdd468 cd examples/ai-functions pnpm tsx src/generate-text/openai/repro-alias-forced.tsresult
AI_APICallError: Tool choice 'function' not found in 'tools' parametertool_choice: { type: 'function', name: 'alias_name' }after fix (
a3565b08c2)git checkout a3565b08c2 cd examples/ai-functions pnpm tsx src/generate-text/openai/repro-alias-forced.tsresult
alias_nameSteps: 2repro-alias-unforced
before fix (
368bbdd468)git checkout 368bbdd468 cd examples/ai-functions pnpm tsx src/generate-text/openai/repro-alias-unforced.tsobserved behavior (multiple runs)
toolCalls: []AI_NoSuchToolErrorwhen model emitswrite_sqlbut available tool key isalias_nametoolCalls: []after fix (
a3565b08c2)git checkout a3565b08c2 cd examples/ai-functions pnpm tsx src/generate-text/openai/repro-alias-unforced.tsobserved behavior (multiple runs)
toolCalls: [],toolResults: [],Steps: 2verification
pnpm tsx src/generate-text/openai/responses-custom-tool.tspnpm tsx src/stream-text/openai/responses-custom-tool.tspnpm tsx src/generate-text/openai/responses-custom-tool-multi-turn.tspnpm tsx src/stream-text/openai/responses-custom-tool-multi-turn.tschecklist
pnpm changesetin root)related issues
fixes #12614