Sessions with weft/thread
The core is stateless: a run takes a transcript in and gives one back, and storing it between runs is your job (Continue a conversation). Package weft/thread is the layer above it. A session is a conversation stored as an append-only tree of entries in a backend, with one writer, turns that are durable step by step, and branching, compaction, approvals and child sessions built on the same tree.
Use weft/thread when a conversation must outlive the process, survive a crash mid-turn, or be read by another process while it is written. Stay with weft.Messages when each request carries its whole history and nothing needs to be durable.
What it adds over the core:
- Durability. The prompt is written to the storage before the run starts, each step’s messages as they join the run, and a turn entry at the end. A crash loses at most the step in flight and the turn’s closing entry: the prompt and every finished step are already stored (thread rule T4).
- One writer. A
Sessionvalue is its session’s only writer until it closes; a second writer getsthread.ErrLocked(T1, T2). - A tree, not a list. You branch back, fork into a new session and label entries; nothing is rewritten or deleted in place.
- Busy policies. A message sent while a turn runs is queued, rejected, steered into the turn, interrupts it, or rolls it back, and every message accepted that way is written to the storage first.
- Compaction, approvals and pools. Long sessions are summarized without deleting anything, parked tool calls survive restarts, and child sessions run under a bound.
weft/thread is a package of the framework module, github.com/weftgo/weft, so it comes with go get github.com/weftgo/weft@v0.20.2. It is pre-1.0: its API and stored format may change between minor versions, each change recorded in the CHANGELOG.
The pages
Section titled “The pages”The section has thirteen pages: this one and the twelve below, in reading order.
- What is a session?: the entry tree, one writer per session, and what is durable when.
- Store sessions: JSONL, SQLite or memory: pick a backend, list and delete sessions, tail one live.
- Write your own thread.Storage: the five methods, the optional capabilities, and
threadtest. - Send turns and wait for them:
Send,Wait, events, outcomes and run options. - What happens when you send while a turn runs?: the busy policies, receipts and
Steer. - Label, branch and fork a session: navigate the tree, fork, titles and public ids.
- Keep long sessions inside the context window (compaction): summaries that replace old entries in the context.
- Approvals in sessions: parked calls that survive restarts, grants and approvers.
- Sign approval decisions: decisions that cross a process boundary.
- Run bounded child sessions with a pool: delegation with receipts.
- Operate sessions in production: backups, locks, shutdown and crash recovery.
- The session log format: every entry kind and its fields.
See also
Section titled “See also”- What is a session?
- Continue a conversation: multi-turn without
weft/thread docs/thread-operations.md: the operator’s page- Package thread on pkg.go.dev