@condensate/agents-sdk is a TypeScript client for the runtime. With it you can list threads, follow their events, send work, and start and control threads. Its methods return Effect values, which Effect.runPromise executes, and every response is decoded against a schema before you see it.
The SDK ships with early access. It is a workspace package inside the Condensate repository and is not published to npm, so the examples import it the way code inside the repository does. They are runnable files in apps/docs/src/examples, and the docs TypeScript check compiles them.
1. Configure the client
The client layer provides the runtime's address. The default local runtime listens on port 4741, which Run locally starts.
import { Agents, agentsConfigLayer } from "@condensate/agents-sdk"
import { Layer } from "effect"
export const client = Agents.Default.pipe(
Layer.provide(agentsConfigLayer({ baseUrl: "http://127.0.0.1:4741" }))
)
To read the settings from the environment instead, provide AgentsConfigLive.
| Variable | Default | Meaning |
|---|---|---|
CONDENSATE_AGENTS_URL | http://127.0.0.1:4741 | The runtime origin, with an optional path prefix |
CONDENSATE_AGENTS_POLL_MS | 2000 | How often a follower polls when the runtime has no push route, and the first reconnect delay |
CONDENSATE_AGENTS_TAIL_LIMIT | 200 | Events per tail page. The runtime caps a page at 1000 |
2. List threads
This example asks for up to 20 thread summaries and prints the paging fields.
import { Agents } from "@condensate/agents-sdk"
import { Effect } from "effect"
import { client } from "./client.js"
const page = await Effect.runPromise(
Effect.gen(function* () {
const agents = yield* Agents
return yield* agents.threadPage({ limit: 20 })
}).pipe(Effect.provide(client))
)
console.log(page.threads, page.nextAfter, page.hasMore)
bun apps/docs/src/examples/list.ts
When hasMore is true, pass nextAfter back as the next request's after. The cursor is opaque. A page holds at most 200 summaries, and allThreads(query) walks every page for you. Load one thread's detail with thread(threadId) rather than downloading every conversation for a sidebar.
The runtime limits how often one client reads the first page. It identifies a client by its address plus the x-condensate-client header, or the user agent when that header is missing, and a client that repeats the request quickly gets a 429 with the code thread-list-rate-limited and a retry-after header. Read the first page once, then follow cursors, or use followWorkspace to learn what changed.
3. Follow events
A follower reads from a position in the thread's log, then waits for more. This example prints ten events and exits.
import { Agents } from "@condensate/agents-sdk"
import { Effect, Stream } from "effect"
import { client } from "./client.js"
const threadId = process.argv[2]
if (threadId === undefined) throw new Error("Pass an existing thread ID")
await Effect.runPromise(
Effect.gen(function* () {
const agents = yield* Agents
yield* agents.follow(threadId, { after: 0 }).pipe(
Stream.take(10),
Stream.runForEach((event) => Effect.sync(() => console.log(event)))
)
}).pipe(Effect.provide(client))
)
bun apps/docs/src/examples/follow.ts THREAD_ID
If fewer than ten events arrive the command stays open; Ctrl+C stops it. after: 0 starts from the beginning, which may use a snapshot for long histories; history(threadId) reads the complete history behind snapshots when you need it.
For an application, store the last event's sequence and pass it as after when you resume. The follower uses the runtime's push route when it exists and polls tail when it does not, and it reconnects from the stored cursor, so a dropped connection neither repeats nor skips events. tailReverse(threadId, { before, limit }) opens a long thread at its end, newest first, with a prevBefore cursor for older pages.
stream(threadId, onFrame, options) is different. It delivers live text frames that are never stored, and reports live, lost, unsupported or gone through a status callback. Use follow when you need a record and stream when you only need what is happening now.
4. Send a message
This example sends a real message to an existing thread, and the agent may start model and tool work under that thread's configuration.
import { Agents } from "@condensate/agents-sdk"
import { Effect } from "effect"
import { client } from "./client.js"
const threadId = process.argv[2]
if (threadId === undefined) throw new Error("Pass an existing thread ID")
const accepted = await Effect.runPromise(
Effect.gen(function* () {
const agents = yield* Agents
return yield* agents.enqueue(threadId, "Summarize the current task and its next step.")
}).pipe(Effect.provide(client))
)
console.log("Message accepted at sequence", accepted.seq)
bun apps/docs/src/examples/send.ts THREAD_ID
enqueue returns as soon as the message is accepted, with the sequence number of the recorded event, and you follow the log to watch what happens. send(threadId, text) waits for the reply to settle and returns it. Both take an options object with to, which addresses one member of a group thread; without it the message goes to every member.
Methods on Agents
| Method | Use it for |
|---|---|
threadPage({ limit, after }) | One page of thread summaries |
allThreads(query) | Every matching summary, read page by page |
children(threadId, { after, limit }) | One page of a thread's live direct children |
thread(threadId) | One thread's detail |
tail(threadId, { after, limit }) | One page of events |
tailReverse(threadId, { before, limit }) | The newest events first |
history(threadId, after) | Every event, including those behind snapshots |
follow(threadId, { after }) | An ongoing stream of stored events |
stream(threadId, onFrame, options) | Live frames that are not stored |
followWorkspace(name, options) | Every event in one workspace, in runtime-wide cursor order |
enqueue(threadId, text) | Send and return at once |
send(threadId, text) | Send and wait for the reply |
spawn(request) | Open a thread from a spec (workspace, title, role, engine, model, permissions) and return its id. Fields you leave out come from the workspace defaults |
fork(threadId, atSeq, spec?) | Start a child thread from an event in a parent's log |
interrupt(threadId, by) | Stop the thread's current reply |
approve(threadId, callId, "allow" | "deny") | Answer a tool call that is waiting for approval |
gate(threadId, options) | Run the admission check and return a verdict with any refusal reasons. A refusal is a result, not an error |
loop(threadId, request) | Run up to maxRounds rounds of a prompt. It waits at human gates and returns the settled outcome. loopStatus, loopContinue and loopStop manage a running loop |
merge(childId, result, options) | Merge a child's result into its parent. A repeated merge reports alreadyMerged |
subscribe(threadId, request) | Wake the subscribing thread when a watched thread records matching events |
memory(workspace) | The workspace's memory bank: recall, retain, reflect and browse |
complete(request) | An OpenAI-compatible chat completion on the workspace's accounts |
A spec's engine is claude, codex, condensate or pi. Engines says what each runs and how the runtime picks one from a model id when you leave it out.
retain answers once the note is in the runtime's outbox, before the bank receives it, with queued: true and the entry's id. A runtime without an outbox answers after extraction, and the SDK decodes that with queued: false and ids, so narrow on queued before you read either.
Other services
Every service except Heads is exported from @condensate/agents-sdk. Workspaces, Github, GithubThreads, Rooms, Questions and Attention also have subpath exports such as @condensate/agents-sdk/rooms. Heads is exported only from @condensate/agents-sdk/heads.
| Service | Use it for |
|---|---|
Accounts | The model logins the runtime holds, their health, and short-lived access tokens. Refresh tokens stay on the runtime |
Workspaces | The registered workspaces, and starting a build or fix thread on a pull request with startOnPr |
Github | Pull requests, diffs, comments, checks and merge receipts through the runtime's cache |
GithubThreads | Replying to and resolving pull request review threads |
Rooms | Starting a review of a pull request, running its rounds, and reading and finalizing the verdict |
Questions | A thread's open questions, and answering, dismissing or continuing them |
Heads | A workspace's lead agents |
Attention | The items that wait on a person, and changes to them |
Operations | A progress record for a long action, with milestones and an outcome |
Code | Read-only code search, outlines and file reads for TypeScript and JavaScript roots |
X | Public X posts, read without a runtime |
steps | Running a workflow definition, one thread per step |
A workflow is an ordered list of steps. Each step spawns a thread, a step can fork from a named earlier step, and a parallel step runs its children together up to a concurrency limit. Each step's gate is auto or human, and a run waits at a human gate.
Errors
The services fail through the Effect error channel with one of three tagged errors. AgentsTransportError means the request failed before a usable response arrived. AgentsRejected means the runtime refused it, and carries status, a code when the runtime sent one, detail, and details with the rest of the refusal body. AgentsDecodeError means the response did not match its schema. Some services add their own, such as RoomConflict or GithubWriteUnconfirmed; the SDK error catalog lists all of them with whether a retry can help.
By default the client sends each request once. Pass retry: { maxRetries: 2 } to agentsConfigLayer to repeat a failed GET after a transport error or a 429, 502, 503 or 504. The wait follows retry-after on a 429 or 503, and otherwise backs off from about 500 milliseconds, doubling each time, never past 8 seconds. A refusal's details.resetAt sets the earliest time the wait may end, and a reset more than 8 seconds away ends the retries. Writes never repeat, because they carry no idempotency key yet.
follow and followWorkspace report errors through the stream, so handle them where you handle the rest. stream has no typed errors and reports connection problems through its status callback.