Wiring an agent
zelk.New builds an agent from a provider and
options. It reads no environment variables and no files of its own: what
the agent can do is what you pass it.
// Any provider will do; a scripted one keeps the example offline.model, err := replay.New(provider.Caps{MaxOutputTokens: 8192})if err != nil { panic(err)}agent, err := zelk.New(context.Background(), model, zelk.WithPermissionMode(permission.ModeBypass), zelk.WithModel("my-model"))if err != nil { panic(err)}// Without WithEnvironment the built-in tools are those that need no// workspace: asking the user, reporting a run's outcome, and// delegating to subagents.for _, d := range agent.Tools() { fmt.Println(d.Name)}// Output:// AskUserQuestion// ReportOutcome// Task// TaskOutput// TaskStop// TaskContinue// TaskList// TaskMessageTwo options are required: WithModel and WithPermissionMode. There is
no default authority, so a host always says which
permission mode sessions start in.
New checks the whole configuration and fails rather than build an agent
that would fail later: a missing model or mode, a shell without a
workspace, two tools with one name, a durable store with a lease that
isn’t, a hard budget on a model whose limits it can’t know.
A workspace and a shell
Section titled “A workspace and a shell”Without an environment, sessions have only the tools that need none: asking the user, reporting the outcome, and subagents. Give them a workspace for the file tools, and a shell for Bash:
ctx := context.Background()root, err := os.Getwd()if err != nil { panic(err)}workspace, err := local.New(ctx, root)if err != nil { panic(err)}defer workspace.Close()p, err := replay.New(provider.Caps{})if err != nil { panic(err)}a, err := zelk.New(ctx, p, zelk.WithModel("m"), zelk.WithPermissionMode(permission.ModeAcceptEdits), zelk.WithEnvironment(workspace, filepath.ToSlash(root)), zelk.WithShell(zelk.Shell{Path: "/bin/bash", Env: []string{"PATH=/usr/local/go/bin:/usr/bin:/bin", "HOME=" + os.TempDir()}}), zelk.WithVerify(zelk.Check{Name: "test", Command: "go test ./..."}))if err != nil { panic(err)}defer a.Close(ctx)for _, d := range a.Tools() { if d.Name == "Bash" || d.Name == "Verify" { fmt.Println(d.Name) }}// Output:// Bash// Verifyenv/local is the workspace on this machine’s filesystem; another
env.Environment can put it in a container or a remote sandbox. To confine
its commands on this machine, pass local.WithLauncher a launcher from
env/launcher: NewBwrap on Linux, NewSeatbelt on macOS or NewMXC on
Windows. On Windows, give the session PowerShell as well, with
zelk.WithPowerShell and a path from zelk.FindPowerShell, and
zelk.WithPowerShellAnalysis so its permission rules read PowerShell
commands; the two shells share one working directory. The
shell’s Env is the commands’ whole environment: nothing is inherited, so
keep credentials out of it. WithRequirements makes New fail unless
the environment enforces what you need, such as a network policy.
Sandboxing from Go builds the launcher and the
requirements.
What else you pass
Section titled “What else you pass”| Option | Gives sessions |
|---|---|
WithStore, WithLease |
durable sessions (Stores and recovery) |
WithTools |
your own tools (Custom tools) |
WithInputCallback, WithInputSuspend |
a way to answer approvals and questions (Approvals) |
WithRules, WithProtectedPaths, WithAllowedModes, WithAllowedTools |
permission rules, the modes a session may switch to and the tools it is offered (Permissions from Go) |
WithVerify |
the project’s checks (Goals and verification) |
WithBudget, WithMaxTurns, WithMaxTime |
limits (Budgets and limits) |
WithSkills, WithSubagents |
skills and subagent types (Skills and subagents) |
WithMCP, WithHooks |
MCP servers and hooks (MCP and hooks from Go) |
WithObserver, WithLogger |
telemetry and logs (Observability) |
An agent built once serves many sessions; Running zelk in a service covers how a long-running process holds it.
Every option is in the zelk package reference.
The zelk command is itself a host built this way, so its wiring in
cmd/zelk/internal/host is a full example.
Sessions and executions runs work on the agent.