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

The agent loop, as a Go library.

zelk runs the loop: model calls, tools, permissions, context and recovery. Your program keeps everything else: the process, storage, isolation, scheduling and who the user is. Embed it in a Go program, run the zelk command from scripts and CI, or try it in a terminal.

  1. 1session_startedtools Read Edit Write Glob Grep Bash
  2. 2command_acceptedfix the failing test in ./pkg/foo
  3. 3run_startedgoal: the request
  4. 4effect_startedcall_provider
  5. 5effect_finishedBash go test ./pkg/foo
  6. 6effect_startedrun_tool Bash
  7. 7effect_finishedexit 1 FAIL TestParseEmpty
  8. 14file_changedpkg/foo/parse.go
  9. 18effect_finishedexit 0 ok pkg/foo
  10. 19report_recordedmet, with the test run as evidence
  11. 20run_finishedmet
Each session is an append-only log. Stop the process at any line, and the next start picks up from the last event recorded.

zelk runs the loop. Your program runs the rest.

Section titled “zelk runs the loop. Your program runs the rest.”

zelk dictates nothing about where it runs. Everything it needs from the outside world arrives as a value you pass in, so the same loop works in a web service, a queue worker, a CI job or a terminal.

Your program a CLI, an HTTP service, a queue worker, a Temporal workflow, a CI job

zelk

  • Model calls, with retries and budgets
  • Tool dispatch and permission checks
  • Context compaction before the window fills
  • Completion checks before a run may end
  • Recovery from the log after a crash
  • The model

    zelk.New(ctx, provider.Provider)

    OpenAI, Anthropic, Gemini, any OpenAI-compatible server, or your own

  • Storage

    WithStore(store.LogStore)

    in memory by default; files, or a database you own

  • Who runs a session

    WithLease(lease.Lease)

    only one process runs a session at a time

  • The workspace

    WithEnvironment(env.Environment, dir)

    a directory, a sandbox, a container

  • Your tools

    WithTools(...*tool.Tool)

    beside Read, Edit, Bash and the rest

  • People

    WithInputCallback(cb)

    questions, plans and approvals, answered live or later

One run, step by step:

  1. The run starts: zelk takes the session’s lease.
  2. The request is appended to the log.
  3. zelk calls the model.
  4. The model’s reply is appended.
  5. The model asks to run go test ./pkg/foo, so zelk asks a person.
  6. The person’s answer is appended.
  7. Approved: zelk hands the call to the tool,
  8. which runs it in the workspace.
  9. The result is appended.
  10. zelk calls the model again with the result.
  11. The model’s report is appended.
  12. The run ends: zelk releases the lease.

The process dies; the log doesn’t. The next Start reads the log back and settles whatever was in flight: a model call is tried again, and a command that may already have acted is never run twice.

  • Killed while a model call is in flight: the next start closes the attempt as lost and starts attempt 2.
  • Killed while a command runs: the command is never run again; it is recorded with outcome unknown, and the model is told to verify before retrying.
  • Killed between events: nothing was in flight, so the next start rebuilds the state from the log and goes on.

Embed the library

The way zelk is meant to be used. One call runs a task with no setup at all. When you need more, zelk.New takes each dependency as an option, and checks the whole configuration before it runs anything. The call is zelk.Run(ctx, task).

Start with Go

Run it from scripts and CI

zelk -p runs one task and prints the answer; zelk exec keeps resumable sessions and structured output; zelk acp serves editors. The command is a host like any other, built only on the public API.

zelk -p -mode plan "…"

Start with the CLI

Try it in a terminal

The quickest look at zelk: a full-screen chat in your repository that asks before it edits. Build it, give it a model and give it a task in a minute.

zelk

Start with the terminal UI

This is the terminal UI, the zelk command’s full-screen mode and the quick way to try zelk. It is not the Go library but a host built on it, one that asks before it edits. Here it works on a Go package with a failing test, from one request to fix it. To embed zelk in your own program instead, follow the Go quickstart, which runs an agent in a few lines.

zelk asks before it runs the tests and before it edits, fixes Count, runs the tests again and reports what it changed. Recorded with Claude Sonnet 5.5 at its real pace; pauses longer than a second and a half are shortened.

New here? Get zelk shows how to add it to a module or build the command, and How zelk works explains the ideas underneath.