feat(ai): accept only serializable tool descriptors in experimental_streamModelCall#13824
Draft
feat(ai): accept only serializable tool descriptors in experimental_streamModelCall#13824
Conversation
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>
3 tasks
Collaborator
Author
|
Additive approach: #13823 adds |
- Wrap JSON schema objects with jsonSchema() so asSchema() can handle them in parseToolCall validation - Include provider tools in toolsRecord (not just function tools) - Add title field to FunctionToolDescriptor - Update streamModelCall tests to call prepareToolsAndToolChoice first - Update stream-text test snapshots (title becomes undefined when passing through descriptors — title is not in V4 tool format) All 2266 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Alternative to #13823. Move
prepareToolsAndToolChoiceout ofexperimental_streamModelCallso it only accepts serializableToolDescriptor[]andToolChoiceDescriptorinstead of the fullToolSet.Both PRs solve the same problem (unblocking #13820 where
ToolSetcan't cross Workflow serialization boundaries), but with different approaches:preparedToolsalongside existingtoolstools: ToolSetwithtools: ToolDescriptor[]toolsstill worksprepareToolsAndToolChoicefirsttoolsandpreparedToolsaccepted)preparedToolswhen neededChanges
experimental_streamModelCallacceptstools?: ToolDescriptor[]andtoolChoice?: ToolChoiceDescriptor(serializable only)activeToolsparameter (folded intoprepareToolsAndToolChoice)streamTextcallsprepareToolsAndToolChoicebeforestreamModelCallstreamModelCall: rebuilds a ToolSet-like Record from descriptors forparseToolCallvalidation (wraps JSON schemas withjsonSchema())Known limitation
titleis not part ofLanguageModelV4FunctionTool, so it's lost when tools go throughprepareToolsAndToolChoice. TheFunctionToolDescriptortype includestitlebutprepareToolsAndToolChoicedoesn't extract it. This affects stream part metadata (tool calls showtitle: undefined). 14 snapshot updates reflect this.Test plan
pnpm build— passespnpm test:node— all 2266 tests passstreamModelCalltests updated to callprepareToolsAndToolChoicefirststream-texttest snapshots updated