condensate

Threads and the runtime

Send messages, read events, survive restarts and coordinate threads.

On this page

Send a message to an agent, read what it did, and keep the record after the agent's process is gone.

What a thread is

A thread is the record of one task. It holds every message you sent, every tool call the agent made and every result, in order. The runtime is the service that runs agents and keeps their threads. An engine session, running Claude Code, Codex or Condensate's own engine, does the work. The thread is what remains when that session is gone.

A browser tab can close and reopen, and the task is still there. Your app can show what happened in a task that finished an hour ago. A restart loses no message, because each message is on disk before any model runs on it.

How it works

One message, from acceptance to result
  1. 01
    Your app sends a messagePOST /threads/:id/messages
    Request
  2. 02
    The runtime accepts and records it202 · seq · ts
    Durable
  3. 03
    An engine executes the turn

    Model → tool → result → model

    Running
  4. 04
    Events reach your interface

    Live deltas for responsiveness; stored events for recovery.

    Streaming
  5. 05
    Your app reads the outcome

    A completed or failed turn is distinct from acceptance.

    Settled
202 acknowledges the message. The later turn outcome tells you whether the work succeeded.

You post a message. The runtime writes it to the thread's log and answers at once with a sequence number. That answer means the message is stored, not that the agent has acted on it. The engine session then runs one turn, which is one message to the agent and its full reply, tool calls included. Each step lands in the log with the next sequence number. You read the log forward from the number you were given, or keep a connection open and let the events stream to you.

Try it

You need a running runtime and one thread. POST /spawn creates a thread and returns its threadId. This example sends real work to the thread and spends model usage.

export THREAD_ID='replace-with-an-existing-thread-id'

curl -i "http://127.0.0.1:4741/threads/$THREAD_ID/messages" \
  -H 'content-type: application/json' \
  -d '{"text":"Summarize the current task and its next step."}'

You should see HTTP 202 and a JSON body with seq and ts. Keep seq. Now read what the agent did after that point:

export AFTER='replace-with-the-acknowledged-sequence-number'

curl -fsS \
  "http://127.0.0.1:4741/threads/$THREAD_ID/tail?after=$AFTER&limit=20"

You should see events, a nextAfter cursor and hasMore. Pass nextAfter back to read the next page. GET /threads/:id/turn tells you whether a turn is running, which messages are still queued, and whether the thread is degraded.

What happens when

A message arrives during a running turn

A message posted during a running turn is added to that turn as guidance. Post with "hold": true to keep it behind the running turn instead. A held message cannot also carry to or from. Until it is delivered, you can edit it with PATCH /threads/:id/messages/:seq or withdraw it with DELETE /threads/:id/messages/:seq. POST /threads/:id/interrupt stops the running turn and any turns it delegated to child threads, drops queued messages and cancels any pending retry. Held messages stay held until you send the next message.

You need one awaited answer

POST /threads/:id/send holds the request until the turn finishes and returns the reply. Send "async": true to get the same 202 acknowledgment as /messages.

The runtime is stopping

While the runtime finishes its running work before a restart, POST /threads/:id/messages answers 503 with the code draining. Nothing is recorded, so retry once the runtime is open again.

The runtime restarts mid-turn

The turn that was running is marked lost, and nothing retries it. At boot the runtime writes an error message to each affected thread, starting "This turn was lost to a host restart". The thread waits until you press Resume or send a new message. The messages themselves stay in the log. Held messages and scheduled retries are stored as rows, so the runtime delivers the held messages and re-arms the retries at boot. The agent's session is recreated on its next turn from the engine's resume state and the log.

When you move a deployment, back up the thread database, its archive, the blob directory and the engine state together. Without the engine state, sessions cannot resume their provider conversations. The paths are in Reference.

You open a long thread at its end

Read the reverse page with before. Omit it to start from the newest event. The page returns events newest first, plus prevBefore and hasMore for the next older page.

A forward read from sequence 0 can include a snapshot that stands in for older events, and events then starts after it. Add history=1 to read the full event history behind the snapshot.

You build a live interface

Acknowledge a send as soon as /messages answers. Render live deltas from GET /threads/:id/stream while the turn runs, then reconcile against the stored events. Live deltas have no replay and no sequence numbers, so treat them as a preview and read the final text from /tail or /follow.

To keep a connection open instead of polling, use GET /threads/:id/follow?after=<seq>. It streams events as server-sent events, and the Last-Event-ID header works as the cursor. The SDK provides a follower, agents.follow, that manages reconnects and falls back to polling where streaming is unavailable.

You coordinate several tasks

A child thread has its own history, so its work can be inspected on its own. POST /spawn with parent: { threadId, atSeq?, forSeq? } starts one under a parent. The other routes for working across threads, fork, subscriptions, approvals and handoff, are in the table under Reference. Start with one thread and its event stream before building a coordinator.

You archive a thread

DELETE /threads/:id marks a thread archived. Nothing is deleted. POST /threads/:id/restore brings it back.

An agent ends its turn with unpushed commits

When an agent that writes code ends a turn with commits GitHub does not have, the runtime asks the pull request review server to push them. The runtime never runs git push itself, and the review server chooses the GitHub identity. If the push is refused, the commits stay in the agent's working copy and the agent is told why, with the instruction to fix the cause rather than push by hand. Security says what the review server checks before it pushes.

Reference

Routes

RouteWhat it does
POST /spawnCreates a thread and answers with its threadId. With parent, starts a child thread.
POST /threads/:id/messagesRecords a message and answers 202 with seq and ts. "hold": true keeps it behind the running turn. Answers 503 draining while the runtime is stopping.
PATCH /threads/:id/messages/:seq, DELETE /threads/:id/messages/:seqEdit or withdraw a held message before it is delivered.
POST /threads/:id/sendHolds the request until the turn finishes and returns the reply. "async": true answers 202 instead.
GET /threads/:id/tailStored event pages. after=<seq> reads forward; before=<seq> reads the reverse page; wait=<ms> holds an empty page open; history=1 reads behind a snapshot.
GET /threads/:id/follow?after=<seq>The same events as server-sent events.
GET /threads/:id/streamLive deltas, with no replay and no sequence numbers.
GET /threads/:id/turnWhether a turn is active, the queued messages, and whether the thread is degraded.
GET /threadsThread summaries. Each carries location, where its agent runs now, or null while none runs.
POST /threads/:id/interruptStops the running turn and its delegated child turns, drops queued messages and cancels any pending retry.
POST /threads/:id/forkForks a thread at a point in its history.
POST /threads/:id/subscriptionsWatches another thread and starts a turn on its events.
POST /threads/:id/approvals/:approvalIdAllows or denies a pending approval, with decision: "allow" or "deny".
POST /threads/:id/handoffHands work to another thread, which accepts or declines it.
DELETE /threads/:id, POST /threads/:id/restoreArchive a thread, and bring it back.

Page sizes and waits

SettingValue
Default page size of GET /threads/:id/tail200 events
Maximum page size1000 events
Longest wait on an empty page30 seconds
Subscriptions per thread8 by default; CONDENSATE_AGENTS_MAX_SUBSCRIPTIONS changes it

Storage

WhatWhereSetting
Thread records and ordered eventsthreads.db under ~/.condensate/agents-hostCONDENSATE_AGENTS_DATA_DIR moves the directory
Older event bodies of a compacted threadthreads-archive.db in the same directory
Event bodies larger than 64 KiBContent-addressed files in blobs/. The database keeps only their hash.CONDENSATE_AGENTS_BLOB_THRESHOLD changes the size
Engine resume pointers~/.condensate/engine by default

Settings

SettingWhat it does
CONDENSATE_AGENTS_PORTThe port the runtime listens on. The default address is 127.0.0.1:4741.
CONDENSATE_HEALTH_EXIT_MSOnce the runtime has answered its own GET /health, it checks again every 30 seconds. When no check has answered for this many milliseconds it exits with code 70, so Docker's restart policy starts it again. 0, the default, turns this off. The Docker install sets 90000.