@@ -11,29 +11,34 @@ Agents emit structured events for every significant operation — RPC calls, sta
1111
1212## Event structure
1313
14- Every event has three fields:
14+ Every event has these fields:
1515
1616``` ts
1717{
1818 type : " rpc" , // what happened
19+ agent : " MyAgent" , // which agent class emitted it
20+ name : " user-123" , // which agent instance (Durable Object name)
1921 payload : { method : " getWeather" }, // details
2022 timestamp : 1758005142787 // when (ms since epoch)
2123}
2224```
2325
26+ ` agent ` and ` name ` identify the source agent — ` agent ` is the class name and ` name ` is the Durable Object instance name.
27+
2428## Channels
2529
26- Events are routed to seven named channels based on their type:
30+ Events are routed to eight named channels based on their type:
2731
28- | Channel | Event types | Description |
29- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
30- | ` agents:state ` | ` state:update ` | State sync events |
31- | ` agents:rpc ` | ` rpc ` , ` rpc:error ` | RPC method calls and failures |
32- | ` agents:message ` | ` message:request ` , ` message:response ` , ` message:clear ` , ` message:cancel ` , ` message:error ` , ` tool:result ` , ` tool:approval ` | Chat message and tool lifecycle |
33- | ` agents:schedule ` | ` schedule:create ` , ` schedule:execute ` , ` schedule:cancel ` , ` schedule:retry ` , ` schedule:error ` , ` queue:retry ` , ` queue:error ` | Scheduled and queued task lifecycle |
34- | ` agents:lifecycle ` | ` connect ` , ` destroy ` | Agent connection and teardown |
35- | ` agents:workflow ` | ` workflow:start ` , ` workflow:event ` , ` workflow:approved ` , ` workflow:rejected ` , ` workflow:terminated ` , ` workflow:paused ` , ` workflow:resumed ` , ` workflow:restarted ` | Workflow state transitions |
36- | ` agents:mcp ` | ` mcp:client:preconnect ` , ` mcp:client:connect ` , ` mcp:client:authorize ` , ` mcp:client:discover ` | MCP client operations |
32+ | Channel | Event types | Description |
33+ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
34+ | ` agents:state ` | ` state:update ` | State sync events |
35+ | ` agents:rpc ` | ` rpc ` , ` rpc:error ` | RPC method calls and failures |
36+ | ` agents:message ` | ` message:request ` , ` message:response ` , ` message:clear ` , ` message:cancel ` , ` message:error ` , ` tool:result ` , ` tool:approval ` | Chat message and tool lifecycle |
37+ | ` agents:schedule ` | ` schedule:create ` , ` schedule:execute ` , ` schedule:cancel ` , ` schedule:retry ` , ` schedule:error ` , ` queue:create ` , ` queue:retry ` , ` queue:error ` | Scheduled and queued task lifecycle |
38+ | ` agents:lifecycle ` | ` connect ` , ` disconnect ` , ` destroy ` | Agent connection and teardown |
39+ | ` agents:workflow ` | ` workflow:start ` , ` workflow:event ` , ` workflow:approved ` , ` workflow:rejected ` , ` workflow:terminated ` , ` workflow:paused ` , ` workflow:resumed ` , ` workflow:restarted ` | Workflow state transitions |
40+ | ` agents:mcp ` | ` mcp:client:preconnect ` , ` mcp:client:connect ` , ` mcp:client:authorize ` , ` mcp:client:discover ` | MCP client operations |
41+ | ` agents:email ` | ` email:receive ` , ` email:reply ` | Email processing |
3742
3843## Subscribing to events
3944
@@ -183,15 +188,17 @@ These events are emitted by `AIChatAgent` from `@cloudflare/ai-chat`. They track
183188| ` schedule:cancel ` | ` { callback, id } ` | A schedule is cancelled |
184189| ` schedule:retry ` | ` { callback, id, attempt, maxAttempts } ` | A scheduled callback is retried |
185190| ` schedule:error ` | ` { callback, id, error, attempts } ` | A scheduled callback fails after all retries |
191+ | ` queue:create ` | ` { callback, id } ` | A task is enqueued |
186192| ` queue:retry ` | ` { callback, id, attempt, maxAttempts } ` | A queued callback is retried |
187193| ` queue:error ` | ` { callback, id, error, attempts } ` | A queued callback fails after all retries |
188194
189195### Lifecycle events
190196
191- | Type | Payload | When |
192- | --------- | ------------------ | ------------------------------------- |
193- | ` connect ` | ` { connectionId } ` | A WebSocket connection is established |
194- | ` destroy ` | ` {} ` | The agent is destroyed |
197+ | Type | Payload | When |
198+ | ------------ | -------------------------------- | ------------------------------------- |
199+ | ` connect ` | ` { connectionId } ` | A WebSocket connection is established |
200+ | ` disconnect ` | ` { connectionId, code, reason } ` | A WebSocket connection is closed |
201+ | ` destroy ` | ` {} ` | The agent is destroyed |
195202
196203### Workflow events
197204
@@ -215,6 +222,13 @@ These events are emitted by `AIChatAgent` from `@cloudflare/ai-chat`. They track
215222| ` mcp:client:authorize ` | ` { serverId, authUrl, clientId? } ` | An MCP OAuth flow begins |
216223| ` mcp:client:discover ` | ` { url?, state?, error?, capability? } ` | MCP capability discovery succeeds or fails |
217224
225+ ### Email events
226+
227+ | Type | Payload | When |
228+ | --------------- | ------------------------ | --------------------- |
229+ | ` email:receive ` | ` { from, to, subject? } ` | An email is received |
230+ | ` email:reply ` | ` { from, to, subject? } ` | A reply email is sent |
231+
218232## Next steps
219233
220234<LinkCard
0 commit comments