Skip to main content
Reference

Events

Full event catalog with payload shapes for agentOS.

Event types

sessionEvent

Emitted for every agent session event (streaming output, errors, status changes).

agent.on("sessionEvent", (data) => {
  // data.sessionId: string
  // data.event: JsonRpcNotification (method, params)
  console.log(data.sessionId, data.event.method, data.event.params);
});

Events are also persisted to SQLite for replay via getSessionEvents.

permissionRequest

Emitted when an agent requests permission to use a tool.

agent.on("permissionRequest", async (data) => {
  // data.sessionId: string
  // data.request: PermissionRequest (id, toolName, etc.)
  console.log("Permission requested:", data.request);

  await agent.respondPermission(data.sessionId, data.request.permissionId, "once");
});

See Permissions for approval patterns.

processOutput

Emitted when a spawned process writes to stdout or stderr.

agent.on("processOutput", (data) => {
  // data.pid: number
  // data.stream: "stdout" | "stderr"
  // data.data: Uint8Array
  const text = new TextDecoder().decode(data.data);
  console.log(`[${data.pid}] ${data.stream}: ${text}`);
});

processExit

Emitted when a spawned process exits.

agent.on("processExit", (data) => {
  // data.pid: number
  // data.exitCode: number
  console.log(`Process ${data.pid} exited with code ${data.exitCode}`);
});

shellData

Emitted when an interactive shell produces output.

agent.on("shellData", (data) => {
  // data.shellId: string
  // data.data: Uint8Array
  const text = new TextDecoder().decode(data.data);
  process.stdout.write(text);
});

cronEvent

Emitted when a cron job runs.

agent.on("cronEvent", (data) => {
  // data.event: CronEvent
  console.log("Cron event:", data.event);
});

vmBooted

Emitted when the VM finishes booting. No payload.

agent.on("vmBooted", () => {
  console.log("VM is ready");
});

vmShutdown

Emitted when the VM is shutting down.

agent.on("vmShutdown", (data) => {
  // data.reason: "sleep" | "destroy" | "error"
  console.log("VM shutting down:", data.reason);
});

Client subscription pattern

Subscribe to events before triggering actions to avoid missing early events.

Event replay

There are two ways to replay session events:

  • getSequencedEvents returns events from the in-memory session. Each event has a sequenceNumber and a notification (the raw JSON-RPC notification). Use this for live reconnection while the VM is running.
  • getSessionEvents returns events from persisted storage (SQLite). Each event has a seq, event, and createdAt. Use this for transcript history, including when the VM is not running.