Task lifecycle, status model, events, subscriptions, and cleanup.
A task represents a single conversation thread between your application and an agent or workforce. When you send a message, the SDK returns a Task — everything that happens next flows through it.
The current SDK has a TypeScript type mismatch on this event — the declared event map key differs from the string dispatched at runtime. The "update" string shown above is correct and events fire as expected. If the type checker complains, add // @ts-expect-error above the line until the upstream fix lands.
The first call to addEventListener on a task activates its subscription. There’s no need to call subscribe manually.Once subscribed, the SDK keeps the task up to date by polling for new messages and metadata changes, and opens a streaming connection when available to deliver real-time thinking and typing events. See Streaming for details.The SDK manages the polling frequency internally — faster when the task is active, slower when idle. This is transparent to the application.
Always call unsubscribe when a task is no longer needed. This stops the polling loop and closes any active connections, freeing network and memory resources.
task.unsubscribe();
Failing to unsubscribe from tasks that have left scope is a common source of resource leaks. In component-based UI frameworks, call unsubscribe from the cleanup or teardown handler.