Zero-config Run
zelk.Run runs one task and returns its result. It wires everything
itself from OPENAI_API_KEY, OPENAI_BASE_URL, HOME, PATH and the
working directory. On Windows, skill discovery falls back to USERPROFILE
when HOME is empty. Run also uses the Windows installation directories
described by zelk.FindGitBash and
zelk.FindPowerShell.
Windows commands also receive the variables Windows programs need to start
(SystemRoot, PATHEXT, COMSPEC, TEMP, USERPROFILE, LocalAppData
and a few more, the ones zelk.CommandEnv
passes on Windows), in addition to PATH and HOME. Git Bash converts path
entries to its own path format and provides a default HOME when none is set.
res, err := zelk.Run(context.Background(), "Summarize README.md in one sentence.")if err != nil { panic(err)}fmt.Println(res.Outcome, res.Text)What it builds:
- an OpenAI-compatible provider at
OPENAI_BASE_URL, or OpenAI’s API, with the modelzelk.DefaultModelunless you passWithModel; - a workspace on the working directory, with the file tools, web fetches
and the skills it finds. Commands run in
/bin/bashon Unix. On Windows they run in PowerShell (7+, else Windows PowerShell 5.1), the primary shell, and in Git for Windows’ Bash, whichever of the two it finds, and it reports both searches if it finds neither; - an in-memory session that ends when
Runreturns; - permission mode
bypass.
Calling Run authorizes zelk to act on the working directory unattended.
Pass zelk.WithPermissionMode(permission.ModePlan) for a session that only
reads. Options you pass apply after the defaults, so any option of
zelk.New can replace one.
When Run finds PowerShell, it reads PowerShell commands for permissions
with PowerShell’s own parser: it starts the analyzer itself and closes it
when Run returns, so read-only commands and argument rules use the parsed
command segments. A host that builds its agent with zelk.New does this
itself: pass the same executable and environment to
zelk.NewPowerShellAnalyzer, provide the analyzer with
zelk.WithPowerShellAnalysis, and close it after the agents sharing it have
closed.
If ctx ends first, the run is interrupted and Run returns what it did,
with the turns and usage it spent, beside ctx’s error. With neither
variable set it returns ErrNoProvider.
A typed result
Section titled “A typed result”RunTyped asks for a value of a Go type. zelk derives a JSON Schema from
the type (struct tags json and desc name and describe the fields), the
run has to deliver a value that fits it, and you get it decoded:
type summary struct { Title string `json:"title" desc:"The document's title."` Lines int `json:"lines" desc:"How many lines it has."`}out, err := zelk.RunTyped[summary](context.Background(), "Describe README.md.")if err != nil { panic(err)}fmt.Println(out.Value.Title, out.Value.Lines)A run that ends without a valid value returns an error saying why, with the
result beside it. RunSchema does the same with a schema you write.
When to move on
Section titled “When to move on”Run suits scripts and first programs. Build an agent with zelk.New
when you need a session that outlives one call, another provider, your own
tools, approvals, a store, or anything else the process environment
shouldn’t decide: Wiring an agent.