Skip to content

feat(ai): accept only serializable tool descriptors in experimental_streamModelCall#13824

Draft
gr2m wants to merge 4 commits intomainfrom
gr2m/stream-model-call-descriptor-only-tools
Draft

feat(ai): accept only serializable tool descriptors in experimental_streamModelCall#13824
gr2m wants to merge 4 commits intomainfrom
gr2m/stream-model-call-descriptor-only-tools

Conversation

@gr2m
Copy link
Collaborator

@gr2m gr2m commented Mar 25, 2026

Summary

Alternative to #13823. Move prepareToolsAndToolChoice out of experimental_streamModelCall so it only accepts serializable ToolDescriptor[] and ToolChoiceDescriptor instead of the full ToolSet.

Both PRs solve the same problem (unblocking #13820 where ToolSet can't cross Workflow serialization boundaries), but with different approaches:

#13823 (additive) This PR (breaking)
Approach Add preparedTools alongside existing tools Replace tools: ToolSet with tools: ToolDescriptor[]
Breaking No — tools still works Yes — callers must call prepareToolsAndToolChoice first
API surface Larger (both tools and preparedTools accepted) Smaller (only descriptors)
Caller change Optional — use preparedTools when needed Required — always prepare first

Changes

  • experimental_streamModelCall accepts tools?: ToolDescriptor[] and toolChoice?: ToolChoiceDescriptor (serializable only)
  • Removes activeTools parameter (folded into prepareToolsAndToolChoice)
  • streamText calls prepareToolsAndToolChoice before streamModelCall
  • Inside streamModelCall: rebuilds a ToolSet-like Record from descriptors for parseToolCall validation (wraps JSON schemas with jsonSchema())
  • Same new types and exports as feat(ai): add preparedTools/preparedToolChoice to experimental_streamModelCall #13823

Known limitation

title is not part of LanguageModelV4FunctionTool, so it's lost when tools go through prepareToolsAndToolChoice. The FunctionToolDescriptor type includes title but prepareToolsAndToolChoice doesn't extract it. This affects stream part metadata (tool calls show title: undefined). 14 snapshot updates reflect this.

Test plan

  • pnpm build — passes
  • pnpm test:node — all 2266 tests pass
  • streamModelCall tests updated to call prepareToolsAndToolChoice first
  • stream-text test snapshots updated

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>
@gr2m
Copy link
Collaborator Author

gr2m commented Mar 25, 2026

Additive approach: #13823 adds preparedTools/preparedToolChoice alongside the existing tools parameter. Non-breaking — callers can use either.

@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. feature New feature or request labels Mar 25, 2026
- 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>
gr2m and others added 2 commits March 26, 2026 23:05
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant