Skip to content

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

EventPayload
run:startrun
run:finishrun, status (succeeded, failed, cancelled), output, error
tool:callrun, tool, input, durationMs, approvalRequired, error?
approval:requestedrun, tool, approvalId
approval:resolvedapprovalId, 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:

server/plugins/agentic-events.ts
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:

src/agentic.ts
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.