Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/content/docs/agents/api-reference/get-current-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class MyAgent extends AIChatAgent {

### Built-in vs custom methods

- **Built-in methods** (`onRequest`, `onEmail`, `onStateChanged`): Already have context.
- **Built-in methods** (`onStart`, `onRequest`, `onConnect`, `onMessage`, `onClose`, `onEmail`, `onStateChanged`): Already have context.
- **Custom methods** (your methods): Automatically wrapped during initialization.
- **External functions**: Access context through `getCurrentAgent()`.

Expand Down Expand Up @@ -231,13 +231,21 @@ The context available depends on how the method was invoked:

| Invocation | `agent` | `connection` | `request` | `email` |
| ----------------------- | ------- | ------------ | --------- | ------- |
| `onStart()` | Yes | No | No | No |
| `onRequest()` | Yes | No | Yes | No |
| `onConnect()` | Yes | Yes | Yes | No |
| `onMessage()` | Yes | Yes | No | No |
| `onClose()` | Yes | Yes | No | No |
| `onEmail()` | Yes | No | No | Yes |
| `onStateChanged()` | Yes | Inherited | Inherited | Inherited |
| `onError()` | Yes | Inherited | Inherited | Inherited |
| Custom method (via RPC) | Yes | Yes | No | No |
| Scheduled task | Yes | No | No | No |
| Queue callback | Yes | Depends | Depends | Depends |
| Queue callback | Yes | Inherited | Inherited | Inherited |

:::note
"Inherited" means the value depends on the calling context. For example, `onStateChanged()` receives the `connection` when a client triggers a state update, but not when the server calls `setState()`. Similarly, `onError()` inherits whatever context was active when the error occurred.
:::

## Best practices

Expand Down
Loading