Skip to content

feat(ai): add experimental_onLanguageModelCallStart/End to AgentCallParameters#15034

Open
Mmartinrusso wants to merge 1 commit intovercel:mainfrom
Mmartinrusso:feat/agent-language-model-callbacks
Open

feat(ai): add experimental_onLanguageModelCallStart/End to AgentCallParameters#15034
Mmartinrusso wants to merge 1 commit intovercel:mainfrom
Mmartinrusso:feat/agent-language-model-callbacks

Conversation

@Mmartinrusso
Copy link
Copy Markdown
Contributor

@Mmartinrusso Mmartinrusso commented May 5, 2026

Background

generateText and streamText support experimental_onLanguageModelCallStart/End for per-LLM-call observability (latency, logging). These callbacks worked at runtime through ToolLoopAgent because unrecognised fields in ...options flow through prepareCall into the underlying call. However, AgentCallParameters did not declare them, forcing users to use as any.

Summary

  • Add experimental_onLanguageModelCallStart and experimental_onLanguageModelCallEnd to AgentCallParameters and AgentStreamParameters
  • Add the same callbacks to ToolLoopAgentSettings so they can be set once at construction time
  • Explicitly handle them in ToolLoopAgent.generate() and ToolLoopAgent.stream(), merging settings-level and call-level callbacks (same pattern as experimental_onToolExecutionStart/End)
  • Add type-level tests in tool-loop-agent.test-d.ts

Manual Verification

  • pnpm tsc --noEmit passes in packages/ai
  • pnpm vitest run src/agent/ — 91/91 pass
  • New type tests confirm both callbacks appear in AgentCallParameters and ToolLoopAgentSettings with the correct types

Checklist

  • All commits are signed
  • Tests have been added / updated
  • Documentation has been added / updated
  • A patch changeset for relevant packages has been added
  • I have reviewed this pull request

Related Issues

Fixes #14278

…arameters

Add `experimental_onLanguageModelCallStart` and `experimental_onLanguageModelCallEnd`
to `AgentCallParameters`, `AgentStreamParameters`, and `ToolLoopAgentSettings`.

These callbacks already exist in `generateText`/`streamText` and work at runtime
via the `...options` spread but TypeScript rejects them because they are absent
from `AgentCallParameters`. This change makes the type surface match the runtime
behavior and enables proper observability of per-LLM-call events in agent loops.

Closes vercel#14278

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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