A Thread is an identified conversation shared across Runs. Its lifetime belongs to the
application’s history or durable host. Reusing a Thread ID continues that conversation;
it does not by itself make execution durable or authorize access.
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Provides dependencies to an effect using layers or a context. A layer already
built by an enclosing provide or runtime is reused. Sibling provide calls
build their own copies. Use options.local to build a fresh layer subtree.
Provides dependencies to an effect using layers or a context. A layer already
built by an enclosing provide or runtime is reused. Sibling provide calls
build their own copies. Use options.local to build a fresh layer subtree.
Provides dependencies to an effect using layers or a context. A layer already
built by an enclosing provide or runtime is reused. Sibling provide calls
build their own copies. Use options.local to build a fresh layer subtree.
Run agents and attached subagents with in-memory conversation history.
Provide once around the parent program and all child handler Layers so siblings
share history and one reservation ledger. Reuse a Thread ID to continue a conversation.
Each parent Run releases its reservation pool after its attached children finish cleanup.
Conversations have no per-Thread history quota; individual messages and total host memory are bounded.
Use scoped for disposable request workflows within this shared store.
Each independent Layer build owns fresh state; state is released when its Scope closes.
Process loss loses history and active execution; this Layer provides no crash recovery.
Models, tool handlers, and provider clients remain application-supplied. Default
IDs need no Layer; enclosing ID and context-preparation overrides are preserved.
For storage-backed history, provide PersistentHistory.layer and a shared
SubagentReservationsMemoryLive instead. Durable hosts own their own assembly.
layer));
One Layer surrounds both Runs. In a server, keep the application Layer in one
ManagedRuntime. The runnable Node snippets
show the imported definition and services.
Incremental complete messages and tool batches, including before a later failure
Application Scope or process loss
InMemory.scoped inside that Layer
Conversations created by one owned workflow, including attached children
Workflow success, failure, or interruption
PersistentHistory.layer with storage
Each successful Run as one atomic history commit
Application retention policy
Durable host
Committed conversation plus accepted-work and recovery state
Explicit lifecycle and retention operations
In-memory storage bounds apply to individual messages and the whole host.
Capacity errors leave existing conversations intact.
Finishing a Run does not release its history. Use InMemory.scoped for disposable workflows
and consume streams or handles before that scope closes.
Persistent history retains successful Runs but cannot resume interrupted execution. A storage
error can occur after commit; inspect the retained history before retrying. Serialize callers
when repeating external work would be unsafe: a conflicting history append can reject a stale
writer after its tools have already run.
The durable host admits a submission, returns a receipt, and owns its execution history and
settlement. Keep ordinary persistent-history Threads and durable-admission Threads on separate
IDs. Use its API for durable work instead of layering ordinary history hooks around it.
See durability and storage choices.
The model reads a selected context window. Recovery reads active Run state and necessary
evidence. A history UI reads ordered ranges. Compaction can shorten model context without
erasing conversation history; archival can relocate old records without resolving open work.
A Thread’s lifetime is unbounded: history, sends and child invocations have no cumulative
per-Thread quota. Payloads, individual Runs, live work and host storage have limits.
Thread.Store.snapshot inspects an in-memory conversation; Thread.toPrompt turns it into
an Effect AI Prompt. Durable ThreadStore and ThreadReader expose journal reads instead.
Authorize tenant and Thread access at the host boundary for both.