Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-agent-call-parameters-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Added missing `experimental_onToolCallStart` and `experimental_onToolCallFinish` callback properties to the `AgentCallParameters` type. These callbacks were already supported at runtime (flowing through the rest spread into `generateText`/`streamText`) but caused TypeScript errors when passed to `agent.generate()` or `agent.stream()`.
18 changes: 18 additions & 0 deletions packages/ai/src/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { StreamTextTransform } from '../generate-text/stream-text';
import { StreamTextResult } from '../generate-text/stream-text-result';
import { ToolSet } from '../generate-text/tool-set';
import { TimeoutConfiguration } from '../prompt/call-settings';
import type {
OnToolCallFinishEvent,
OnToolCallStartEvent,
} from '../generate-text/callback-events';
import type { ToolLoopAgentOnStepFinishCallback } from './tool-loop-agent-settings';

/**
Expand Down Expand Up @@ -57,6 +61,20 @@ export type AgentCallParameters<CALL_OPTIONS, TOOLS extends ToolSet = {}> = ([
*/
timeout?: TimeoutConfiguration;

/**
* Callback that is called before each tool execution begins.
*/
experimental_onToolCallStart?: (
event: OnToolCallStartEvent<TOOLS>,
) => PromiseLike<void> | void;

/**
* Callback that is called after each tool execution completes.
*/
experimental_onToolCallFinish?: (
event: OnToolCallFinishEvent<TOOLS>,
) => PromiseLike<void> | void;

/**
* Callback that is called when each step (LLM call) is finished, including intermediate steps.
*/
Expand Down
17 changes: 17 additions & 0 deletions packages/ai/src/agent/tool-loop-agent.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ describe('ToolLoopAgent', () => {
});

describe('generate', () => {
it('should accept experimental_onToolCallStart and experimental_onToolCallFinish', async () => {
const agent = new ToolLoopAgent({
model: new MockLanguageModelV3(),
});

// Should compile without error
await agent.generate({
prompt: 'Hello',
experimental_onToolCallStart: async ({ toolCall }) => {
toolCall;
},
experimental_onToolCallFinish: async ({ toolCall }) => {
toolCall;
},
});
});

it('should not allow system prompt', async () => {
const agent = new ToolLoopAgent({
model: new MockLanguageModelV3(),
Expand Down