Skip to content

fix(ai): make experimental_context required in ToolLoopAgentOnFinishCallback#12219

Merged
dancer merged 4 commits intovercel:mainfrom
kaizen403:fix/experimental-context-optionality
Feb 9, 2026
Merged

fix(ai): make experimental_context required in ToolLoopAgentOnFinishCallback#12219
dancer merged 4 commits intovercel:mainfrom
kaizen403:fix/experimental-context-optionality

Conversation

@kaizen403
Copy link
Copy Markdown
Contributor

Summary

  • Fixes type inconsistency where ToolLoopAgentOnFinishCallback had experimental_context as optional (?) while StreamTextOnFinishCallback and GenerateTextOnFinishCallback had it as required
  • Adds type tests to verify callback type compatibility between agent and streamText/generateText callbacks
  • Updates JSDoc comment to use "tool execution" wording for consistency with other callbacks

Problem

As reported in #12195, ToolLoopAgentOnFinishCallback defines experimental_context?: unknown (optional), but StreamTextOnFinishCallback and GenerateTextOnFinishCallback define experimental_context: unknown (required).

Since ToolLoopAgent delegates to streamText/generateText, and both always pass experimental_context when invoking the callback (stream-text.ts#L1011, generate-text.ts#L940), the types should match.

This inconsistency causes type errors when trying to use a StreamTextOnFinishCallback where ToolLoopAgentOnFinishCallback is expected (or vice versa).

Solution

Changed experimental_context?: unknown to experimental_context: unknown in ToolLoopAgentOnFinishCallback to match the other callback types.

Testing

  • All 1812 tests pass including new type tests
  • Added 2 new type tests verifying bidirectional type compatibility between StreamTextOnFinishCallback and ToolLoopAgentOnFinishCallback
  • Full type check passes with no errors

Fixes #12195

…allback

This fixes a type inconsistency where ToolLoopAgentOnFinishCallback had
experimental_context as optional while StreamTextOnFinishCallback and
GenerateTextOnFinishCallback had it as required.

Since ToolLoopAgent delegates to streamText/generateText, and both always
pass experimental_context when invoking the callback, the types should match.

Fixes vercel#12195
@vercel-ai-sdk vercel-ai-sdk bot added the ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. label Feb 3, 2026
@kaizen403
Copy link
Copy Markdown
Contributor Author

Hi @lgrammel, small type fix for #12195. all tests pass.

@dancer dancer enabled auto-merge (squash) February 9, 2026 14:57
@dancer dancer merged commit 59fcf30 into vercel:main Feb 9, 2026
18 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToolLoopAgentOnFinishCallback and StreamTextOnFinishCallback have inconsistent experimental_context optionality

2 participants