build

Add a background subscription

Observe selected durable Reference-agent events after the request that started the work has ended.

SDKintermediate0.7.0 Stable
Verified 2026-07-20View sourceReport a docs issue
TypeScript
const events = agent.subscribe(
  {
    sessionId: "reference-session-001",
    eventTypes: ["task.updated"],
  },
  context,
);
 
for await (const event of events) {
  console.log(event.type, event.sessionId);
}

Every subscription must include a session, run, thread, or event filter. The root SDK does not expose an unfiltered global event stream.

FilterUse it for
sessionIdEvents associated with one durable session
runIdOne specific run
threadIdOne thread lineage within a session
eventTypesOnly named event families needed by the observer

The subscription observes persisted events independently of the browser or request that started the work. It does not replace the live stream used to respond to that request.

Continue with observability or the SDK reference.