Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit cde8d07

Browse files
authored
feat: add before invocation and before model calls cancellation (#785)
1 parent 7e2f16d commit cde8d07

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/content/docs/user-guide/concepts/agents/hooks.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ Most event properties are read-only to prevent unintended modifications. However
357357
</Tab>
358358
<Tab label="TypeScript">
359359

360+
- `BeforeInvocationEvent`
361+
- `cancel` - Cancel the agent invocation with a message.
362+
363+
- `BeforeModelCallEvent`
364+
- `cancel` - Cancel the model call with a message.
365+
360366
- `BeforeToolsEvent`
361367
- `cancel` - Cancel all tool calls in a batch with a message. See [Limit Tool Counts](#limit-tool-counts).
362368

src/content/docs/user-guide/concepts/streaming/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ All streaming methods yield the same set of events:
3636
Each event emitted from the TypeScript agent is a class with a `type` attribute that has a unique value. When determining an event, you can use `instanceof` on the class, or an equality check on the `event.type` value. All events extend `HookableEvent`, making them both streamable and subscribable via hook callbacks.
3737

3838
- **`BeforeInvocationEvent`**: Start of agent loop (before any iterations)
39+
- **`cancel`**: Set by hook callbacks to cancel the invocation (`boolean | string`)
3940
- **`AfterInvocationEvent`**: End of agent loop (after all iterations complete)
4041
- **`error?`**: Optional error if loop terminated due to exception
4142
- **`BeforeModelCallEvent`**: Before model invocation
4243
- **`messages`**: Array of messages being sent to model
44+
- **`cancel`**: Set by hook callbacks to cancel the model call (`boolean | string`)
4345
- **`AfterModelCallEvent`**: After model invocation
4446
- **`message`**: Assistant message returned by model
4547
- **`stopReason`**: Why generation stopped

0 commit comments

Comments
 (0)