feat(ai): add preparedTools/preparedToolChoice to experimental_streamModelCall#13823
Draft
feat(ai): add preparedTools/preparedToolChoice to experimental_streamModelCall#13823
Conversation
Add support for pre-prepared serializable tool descriptors in experimental_streamModelCall. When preparedTools is provided, the function skips prepareToolsAndToolChoice and uses the descriptors directly. This enables callers that operate across serialization boundaries (e.g., Workflow step functions) to prepare tools once outside the boundary and pass the serializable result through. New types: - FunctionToolDescriptor: serializable function tool (JSON schema) - ProviderToolDescriptor: serializable provider tool - ToolDescriptor: union of the above - ToolChoiceDescriptor: serializable tool choice These types intentionally alias the internal LanguageModelV4* types to shield consumers from provider spec version changes. Also exports experimental_prepareToolsAndToolChoice for callers that need to pre-prepare tools explicitly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
gr2m
added a commit
that referenced
this pull request
Mar 25, 2026
Move prepareToolsAndToolChoice out of streamModelCall so it only accepts serializable ToolDescriptor[] and ToolChoiceDescriptor instead of the full ToolSet (which contains non-serializable Zod schemas and execute functions). Callers must now call experimental_prepareToolsAndToolChoice before streamModelCall to convert ToolSet → ToolDescriptor[]. This is the alternative to #13823 (which adds preparedTools alongside tools). This approach is cleaner — streamModelCall only deals with serializable types — but requires updating stream-text.ts to prepare tools before the call. New types and exports: same as #13823. TODO: Update stream-text.test.ts and other tests that pass ToolSet directly to streamModelCall. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 tasks
Collaborator
Author
|
Alternative approach: #13824 removes |
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.
Summary
Add support for pre-prepared serializable tool descriptors in
experimental_streamModelCall. WhenpreparedToolsis provided, the function skipsprepareToolsAndToolChoiceand uses the descriptors directly. This is needed to unblock #13820.Alternative approach: #13824
Problem
experimental_streamModelCallrequiresToolSetfor itstoolsparameter.ToolSetcontains Zod schemas andexecutefunctions — neither of which are serializable. WhenstreamModelCallis called inside a Workflow'use step'function, theToolSetcrosses the step serialization boundary and fails:Solution
Allow callers to pre-prepare tools outside the serialization boundary and pass the serializable result through:
New types
Intentionally alias internal
LanguageModelV4*types to shield consumers from provider spec version changes:FunctionToolDescriptor— serializable function tool descriptor (JSON schema, name, description)ProviderToolDescriptor— serializable provider tool descriptorToolDescriptor— union of the aboveToolChoiceDescriptor— serializable tool choice (auto|none|required|{ tool: name })New exports from
aiFunctionToolDescriptor,ProviderToolDescriptor,ToolDescriptor,ToolChoiceDescriptor(types)experimental_prepareToolsAndToolChoice(function — extracts serializable descriptors fromToolSet)Test plan
pnpm buildin packages/ai — passespnpm test:nodein packages/ai — 2266 tests pass