Skip to content

fix(ai): type legacy tool callbacks on agents#15588

Open
he-yufeng wants to merge 2 commits into
vercel:mainfrom
he-yufeng:fix/agent-experimental-tool-callback-types
Open

fix(ai): type legacy tool callbacks on agents#15588
he-yufeng wants to merge 2 commits into
vercel:mainfrom
he-yufeng:fix/agent-experimental-tool-callback-types

Conversation

@he-yufeng
Copy link
Copy Markdown

Background

ToolLoopAgent.generate() and ToolLoopAgent.stream() forward extra call options into generateText() and streamText(). The legacy experimental_onToolCallStart and experimental_onToolCallFinish callbacks therefore work at runtime, but the agent call parameter type did not expose them.

That left consumers needing as any for callbacks that the underlying text APIs still support.

Summary

  • add the two legacy callback fields to AgentCallParameters
  • keep them marked as deprecated aliases for the newer onToolExecutionStart / onToolExecutionEnd fields
  • cover both generate() and stream() in the agent d.ts test
  • add a patch changeset for ai

Manual Verification

pnpm --filter ai type-check
pnpm --filter ai test:node -- src/agent/tool-loop-agent.test.ts
pnpm exec oxfmt --check packages/ai/src/agent/agent.ts packages/ai/src/agent/tool-loop-agent.test-d.ts .changeset/agent-tool-call-callback-types.md
pnpm exec oxlint packages/ai/src/agent/agent.ts packages/ai/src/agent/tool-loop-agent.test-d.ts
pnpm --filter ai build

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #14278

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

Legacy experimental_onToolCallStart and experimental_onToolCallFinish callbacks are silently ignored when passed to ToolLoopAgent.generate() or ToolLoopAgent.stream() because mergeCallbacks() always returns a non-nullish function that shadows them.

Fix on Vercel

@he-yufeng
Copy link
Copy Markdown
Author

Updated this branch to wire legacy experimental_onToolCallStart and experimental_onToolCallFinish through ToolLoopAgent.generate() and .stream(), with regression coverage for both start/finish callbacks on generate and stream. Validation: ultracite check passed; pnpm --filter ai test:node src/agent/tool-loop-agent.test.ts passed (103 tests); pnpm --filter ai type-check passed; git diff --check passed. The remaining Vercel deployment check still appears to be the team authorization gate.

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.

AgentCallParameters type missing experimental_onToolCallStart/Finish callbacks that work at runtime

1 participant