Skip to content

fix(ai): restore onFinish callback in ToolLoopAgent stream and generate methods - #15823

Closed
MaitreyeeDeshmukh wants to merge 2 commits into
vercel:mainfrom
MaitreyeeDeshmukh:fix/tool-loop-agent-on-finish-callback
Closed

MaitreyeeDeshmukh wants to merge 2 commits into
vercel:mainfrom
MaitreyeeDeshmukh:fix/tool-loop-agent-on-finish-callback

Conversation

@MaitreyeeDeshmukh

Copy link
Copy Markdown

Background

PR #13698 accidentally removed onFinish from callbackArgs in both ToolLoopAgent.stream() and ToolLoopAgent.generate() while removing experimental callbacks. onFinish is a stable public API callback, not experimental — any handler passed to the agent was silently dropped after that change.

What changed

Added onFinish: mergeCallbacks(this.settings.onFinish, onFinish) back to callbackArgs in both methods in packages/ai/src/agent/tool-loop-agent.ts, immediately after the existing onStepFinish line.

Testing

Added two regression tests to tool-loop-agent.test.ts — one for generate() and one for stream() — verifying onFinish is called on completion. All 103 tests pass locally.

Closes #14330

@gr2m

gr2m commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

should be fixed now, cheers

@gr2m gr2m closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: onFinish callback not working in ToolLoopAgent.stream() since v6.0.135

2 participants