Skip to main content

What Durable Execution Means for You

When you send a message to the agent, the system guarantees:
  1. Your request will be processed — even if the server handling your request crashes, the work is automatically picked up by another server.
  2. No duplicate responses — each message gets exactly one agent response, even if retries are needed internally.
  3. Automatic recovery — transient failures (network blips, provider timeouts) are retried automatically with exponential backoff.
  4. Observable progress — you can see exactly what the agent is doing in real-time via the streaming connection.

How It Works

The agent system separates orchestration (managing the workflow) from execution (running the agent logic) and streaming (delivering results to you):
  1. The API starts a workflow — your message is recorded and a durable workflow begins. The API returns 202 Accepted immediately.
  2. The orchestration service dispatches to a worker — a healthy worker picks up the task.
  3. The worker runs the agent — fetches your history, runs the AI agent with streaming, and publishes events.
  4. You receive the stream — your browser subscribes to the event stream and receives updates in real-time.
  5. The response is saved — after streaming completes, the worker persists the full message.

Why Not Stream Through the Orchestration Service?

The orchestration layer is designed for durable state management, not real-time streaming. Sending every text token through it would add unnecessary latency and overhead. Instead, streaming goes through a lightweight event stream (Redis) while the orchestration layer handles the durable parts: starting the run, retrying on failure, and ensuring exactly-once execution.

Concurrency and Idempotency

Each conversation thread can have at most one active agent run at a time. This is enforced through a unique workflow identifier per thread:
  • One run per thread: Concurrent requests on the same thread are detected and rejected with 409 Conflict
  • Re-run after completion: After a run finishes, the same thread can start a new run
  • No duplicate processing: If you accidentally send the same message twice, only one workflow runs

Retry and Timeout Configuration

Automatic Retries

If the agent activity fails due to a transient error, it is automatically retried:

Timeouts

If the agent stops sending heartbeats (e.g., the worker crashes), the system detects the failure within 60 seconds and reschedules to another worker — much faster than waiting for the full 5-minute timeout.

Streaming Infrastructure

Event Protocol

Events follow a standard streaming protocol. You receive them as Server-Sent Events (SSE):

Reconnection Support

If your connection drops during streaming:
  1. Reconnect with last_message_id and last_entry_id from the last event you received
  2. The system checks if the message is still streaming
  3. If yes: you resume from where you left off, with missed events replayed
  4. If no: you receive a message_not_streaming event and can fetch the complete message via REST

Event Durability

Events are stored in an append-only stream (Redis Streams) rather than fire-and-forget pub/sub. This means:
  • Events are retained for approximately 30 minutes
  • Multiple clients can watch the same thread simultaneously
  • Replay is supported for reconnecting clients

Complete Request Lifecycle

Step 1: Create a Thread

Step 2: Open the Stream (can happen before Step 3)

Step 3: Send a Message

Step 4: Receive Streaming Events

Step 5: Message Persisted

The complete message is now available via REST: