Skip to content
Source on GitHub (opens in a new tab)

zelk is a library that runs an agent loop, and the zelk command is a program built on it. This page gives you the words zelk uses, shows how the parts fit inside one another, and names the few ideas everything else rests on. Each idea has its own page, and the map below shows where each one happens.

Part What it is How long it lives In the zelk command
Host The program that embeds zelk. It owns the process and hands zelk each dependency. As long as the program runs The command itself
Agent What zelk.New builds: the configuration and resources its sessions share Until the host closes it One per run of the command
Session One conversation, recorded as a log of events As long as its log is kept A conversation in the terminal UI; zelk -c reopens the last
Execution One stretch of work on a session, until it has nothing left to do From a message until the session is idle or waiting What a message you send starts or joins
Run One request inside an execution, ending with an outcome such as success From its prompt to its outcome One answer to one message
Turn One pass round the loop: ask the model, then do what it asked Seconds to minutes One reply and the tool calls in it

A session keeps the configuration it began with: its system prompt, tools, permission policy and model are recorded in its log. Reopening it later behaves as it did, whatever the agent’s options are by then.

The parts nest. A host holds an agent, the agent holds its sessions, and each session is a loop over its own log. Every page in this section sits at one of the loop’s five stations, where what it explains happens.

host your program, or the zelk command

Owns the process and hands zelk each dependency as an option.

agent zelk.New

Holds the configuration its sessions share.

session one conversation, one log

  1. foldloop.Step

    Folding the log says what comes next, and whether the work is done.

  2. askeffects

    Asking the model: which one, what fits in its window, and what it knows.

  3. record intenteffect_started

    Each call is decided before its intent is recorded.

  4. do itmodel · tools

    Doing it: a model call, a command, a tool of your own.

  5. record resulteffect_finished

    Every result is recorded, so a crash, a handover or a rewind starts from the log.

The loop is what zelk owns. It sends the conversation to a model, runs the tools the model asks for, decides each call against the permission rules, keeps the conversation inside the model’s context window, and decides when a run has really finished.

The host owns everything else: the process, where logs are stored, how commands are isolated, scheduling, transport and who the user is. It hands each of these to zelk as an option, such as a provider, a store, a lease, a workspace environment or an observer. zelk never builds a dependency behind the host’s back, never reads the environment (outside the zero-configuration zelk.Run) and never writes to standard output.

The zelk command is one such host. It uses only the library’s public API, so anything it does, your program can do too. An editor that speaks the Agent Client Protocol drives zelk through zelk acp, another way in to the same host (Editors and ACP).

zelk records a session as an append-only log of events: the user’s messages, each model reply, each tool call with its decision and result, each change of mode or model. A pure function, the reducer, folds that log into the session’s state: its history, its pending work, its budget, its task list. Nothing else holds state that matters. The reducer only decides; a separate driver does what it asks, recording its intent before it acts and the result after (The loop).

That one choice gives zelk its guarantees:

  • A crash leaves a record. What may have happened is in the log, so the next process settles it rather than guessing.
  • A write counts once it is on disk. A torn tail after a crash is repaired; corruption is reported, never dropped.
  • Replay is exact. Reading a log back reproduces the session without calling the model or reading the workspace again. Inspecting a session, resuming it elsewhere and rewinding it all start from a replay.

The store is the host’s choice: an in-memory store by default, which keeps nothing once the agent is gone, or a file store (store/file) for sessions that outlive the process. The zelk command keeps its sessions in files under ~/.local/state/zelk/sessions/. Durability and recovery says what each guarantee covers.

A lease gives one process at a time the right to append to a session. It expires unless renewed, and every append carries the lease’s fencing token, so a process that lost its lease, paused perhaps, can’t write over the one that took over. That is what lets a session move between processes: a server can pick up a session a crashed worker left, and recover its pending work from the log. A store whose logs outlive the process needs a lease whose fences do too, such as lease/file, and zelk.New refuses the pair otherwise.

The pages are grouped in the sidebar the way the map groups them:

The contracts behind these pages are in Internals: the architecture says which package owns what, the durability contract what each guarantee covers, and loop states what a session can be doing at any moment.