# Wiring an agent

> Build an agent with zelk.New, passing each dependency as an option.

[`zelk.New`](/reference/go/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.

```go
// core/example_test.go
// 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
// TaskMessage
```

Two options are required: `WithModel` and `WithPermissionMode`. There is
no default authority, so a host always says which
[permission mode](/concepts/permissions/) 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

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:

```go
// core/guide_example_test.go
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
// Verify
```

`env/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](/go/sandboxing/) builds the launcher and the
requirements.

## What else you pass

| Option | Gives sessions |
|---|---|
| `WithStore`, `WithLease` | durable sessions ([Stores and recovery](/go/stores/)) |
| `WithTools` | your own tools ([Custom tools](/go/tools/)) |
| `WithInputCallback`, `WithInputSuspend` | a way to answer approvals and questions ([Approvals](/go/approvals/)) |
| `WithRules`, `WithProtectedPaths`, `WithAllowedModes`, `WithAllowedTools` | permission rules, the modes a session may switch to and the tools it is offered ([Permissions from Go](/go/permissions/)) |
| `WithVerify` | the project's checks ([Goals and verification](/go/completion/)) |
| `WithBudget`, `WithMaxTurns`, `WithMaxTime` | limits ([Budgets and limits](/go/limits/)) |
| `WithSkills`, `WithSubagents` | skills and subagent types ([Skills and subagents](/go/skills-subagents/)) |
| `WithMCP`, `WithHooks` | MCP servers and hooks ([MCP and hooks from Go](/go/mcp-hooks/)) |
| `WithObserver`, `WithLogger` | telemetry and logs ([Observability](/go/observability/)) |

An agent built once serves many sessions; [Running zelk in a
service](/go/service/) covers how a long-running process holds it.

Every option is in [the `zelk` package reference](/reference/go/zelk/).
The `zelk` command is itself a host built this way, so its wiring in
`cmd/zelk/internal/host` is a full example.

## Next

[Sessions and executions](/go/executions/) runs work on the agent.
