Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Runtime Event Bus

The runtime publishes session changes, store writes, bundle reloads, messaging-channel activity, and tool-call activity through GET /api/events. Use these events to refresh data in your application.

Chat responses use a separate POST stream with text_delta, tool_call_start, and done messages. See Runtime Server. The event bus reports state changes across sessions; it does not replace authenticated data queries.

Subscribe

This browser example uses the current origin and its hosted session. A cross-origin or bearer-authenticated client needs an appropriate authenticated connection; native EventSource cannot set an Authorization header.

const events = new EventSource('/api/events');
events.addEventListener('session_created', (message: MessageEvent<string>) => {
  const event = JSON.parse(message.data);
  console.log('Session created:', event.sessionId);
});

Each frame carries an event: line with the event type, so register a named listener for each type the view uses. An onmessage handler receives nothing.

Call events.close() when the view is disposed. The server sends a comment heartbeat every 15 seconds. amodal dev and hosted deployments both serve this route.

Operator credentials, such as the agent's API key, Studio, or a runtime token with neither the user role nor a non-empty scope_id claim, receive every event in full. A token pinned to the agent-level scope (scope_id set to "") counts as an operator here.

Every other subscriber, including the hosted browser session and the React SDK, receives events without their content fields: title, message, error, channelUserId, messagePreview, replyPreview, argsSummary, and targetUrl. Such a subscriber receives an event that names a session only when it may read that session:

  • A token with a scope_id claim receives the events of sessions in that scope that it owns or that have no owner.
  • Any other end user, such as a hosted browser session, receives the events of the sessions it owns.
  • A subscriber with no credential, or a credential the runtime cannot verify, receives no session events. Tokens from an agent's own identity provider fall in this group.
  • Channel events and the events of published runs go to operators only.

Every other event, such as store_updated, reaches every subscriber. amodal dev sends full events to every subscriber.

Native EventSource, and the React SDK's useAgentEvents that uses it, authenticate only through the same-origin session cookie. A cross-origin page without that cookie receives no session events through them.

Reconnect-and-resume

EventSource saves the SSE id and sends it as Last-Event-ID on reconnect. Treat this ID as an opaque cursor:

  • amodal dev uses a process-local sequence and retains the latest 200 events. Its cursor and buffer reset when the process restarts.
  • Hosted deployments routed through the event service use Redis stream IDs, with retention configured by the platform. Do not substitute the event payload's seq for this cursor.

The server replays retained events after the cursor, then streams live events. Missing events outside retention cannot be recovered from this subscription. Refresh the underlying data after a reconnect if your view needs a complete state. A gap in numeric seq can also come from filtered event types, so it is not proof of data loss.

Event catalog

Session events

TypeFieldsWhen
session_createdsessionId, agentId, scopeId, ownerUserId?A new session was created (chat, admin, automation).
session_updatedsessionId, agentId, scopeId, ownerUserId?, title?, status?, answeredBy?A session changed. See below.
session_deletedsessionId, scopeId, ownerUserId?A session was deleted via the API.

scopeId and ownerUserId name who may read the session. Tool-call events carry them too.

session_updated is sent in three cases:

  • A chat was saved, such as when a turn ends or its title changes. It carries the chat's status, such as running or idle.
  • A background run's status changed, such as a new pause or its end. It carries no status; read the session for it.
  • An answer or a cancellation resolved a background run's pause. It carries the run's next status and answeredBy.

Store events

TypeFieldsWhen
store_updatedstoreName, operation, count?A document was written or deleted. operation is "put" or "delete". A purge of expired documents emits "delete" with count set to the number purged, and storeName is "*" when the purge covers every store.

Config events

TypeFieldsWhen
manifest_changedNoneamodal dev reloaded the bundle after a file change. Hosted runtimes do not emit it.
reload_failedmessageA local development bundle reload failed; the server keeps serving the previous bundle.

Channel events

TypeWhen
channel_message_receivedAn inbound message arrived on a messaging channel.
channel_reply_sentThe agent's reply was delivered back to the channel.
channel_session_createdA channel conversation started a new session.
channel_auth_rejectedA channel webhook failed authentication.

Tool-call events

tool_call_started, tool_call_completed, and tool_call_failed report execution activity. amodal dev excludes them by default; add ?include=tool_calls or individual type names to include them. Hosted routes ignore include and send every event type.

Types

All events carry seq, timestamp, and type fields plus the event-specific payload. The React SDK exports AgentEvent, which accepts runtime event fields as unknown values. Narrow those fields before using them:

import type { AgentEvent } from '@amodalai/react';
 
function handleEvent(event: AgentEvent) {
  if (event.type === 'session_updated' && typeof event['sessionId'] === 'string') {
    console.log(event['sessionId'], event['status']);
  }
}

Events and data access

Use events to know when to refresh a session list, automation status, or store-backed view, then fetch the current data through the corresponding HTTP API. Receiving an event is not permission to read the referenced session or store.