Guides
Events
Observe agent runs, tool calls and approvals for logs, analytics and alerts.
When an agent fails at night or an approval waits for hours, you want to know without opening the dashboard. Events report every run, tool call, and approval to your own code, so you can send them to logs, analytics, or alerting.
What Each Event Contains
| Event | Payload |
|---|---|
run:start | run |
run:finish | run, status (succeeded, failed, cancelled), output, error |
tool:call | run, tool, input, durationMs, approvalRequired, error? |
approval:requested | run, tool, approvalId |
approval:resolved | approvalId, ownerId, workspace, approved, run? |
run is { runId, agentId, ownerId, workspace, sessionId }. Automation runs have a sessionId
that starts with automation-.
Handlers run after the fact and never change the outcome: a handler that throws is logged, and the run continues. Runs emit from their Durable Object, and approval answers emit from the request that answered them.
Listening in Nuxt
Events are Nitro runtime hooks named agentic:<event>. The starter logs finished runs and
approval requests:
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('agentic:run:finish', ({ run, status, error }) => {
const reason = error ? `: ${error}` : ''
console.info(`[agentic] Run ${run.runId} of agent ${run.agentId} ${status}${reason}`)
})
nitroApp.hooks.hook('agentic:approval:requested', ({ run, tool, approvalId }) => {
console.info(`[agentic] Approval ${approvalId} requested for ${tool} in run ${run.runId}`)
})
})
Hooks are typed. In development, the Agentic tab in Nuxt DevTools shows recent events and pending approvals.
Listening in Void
Pass one handler to defineVoidAgentic. It receives the event and the Worker env:
export default defineVoidAgentic({
models: [customers],
events(event, env) {
if (event.type === 'run:finish' && event.status === 'failed') {
console.error(`Run ${event.run.runId} failed: ${event.error}`)
}
},
})
Listening in a Feature
A feature's events(event, { env, database, platform }) handler runs before the app's handler
and gets the database, for example to write an audit trail. See Features.