Documentation
¶
Overview ¶
Package harness is an embeddable agent harness: a ReAct loop (eino) whose tools run in a remote sandbox (OpenSandbox), with compaction, steering, skills, artifacts, memory and approvals, streaming AG-UI events.
It is a library for hosts that own the user interface: a web server (see package httpserver), a TUI or a desktop app. A host builds a Harness, starts it and then talks to it with a handful of calls:
h, _ := harness.New(harness.Options{Config: cfg})
go h.Run(ctx)
th, _ := h.NewThread(ctx, "alice", "My thread")
run, _ := h.Send(ctx, "alice", th.ID, "Make a chart of …", harness.RunOptions{Model: "gpt-5"})
for ev := range h.Events(ctx, run.ID, 0) { … } // AG-UI events
Without Redis and Postgres everything lives in the process (memory store, event log and queue); pass Options.Store (store/pgstore) and Options.Infra (redisinfra) to share state between processes.
Index ¶
- Constants
- Variables
- func DefaultLocalStoreDir() string
- func Lookup[T any](b *Builder) (T, bool)
- func NewSandboxBackend(cfg *config.Config) (sandbox.Backend, error)
- func OpenLocalStore(dir string) (*filestore.Store, error)
- func Provide[T any](b *Builder, v T) error
- func RegisterMCP(install func(*Builder) error)
- func SandboxSettings(cfg *config.Config) backends.Settings
- func StoreAs[T any](b *Builder) (T, error)
- type Attachment
- type Author
- type Broker
- type Builder
- func (b *Builder) AddTools(ps ...tools.Provider)
- func (b *Builder) After(f func() error)
- func (b *Builder) Background(f func(ctx context.Context))
- func (b *Builder) BeforeTool(h agent.BeforeToolHook)
- func (b *Builder) Configure(f func(*agent.Harness))
- func (b *Builder) ContextSection(s agent.PromptSection)
- func (b *Builder) EndOfRun(h runtime.Hook)
- func (b *Builder) Has(name string) bool
- func (b *Builder) Job(j runtime.Job)
- func (b *Builder) OnSandboxCreate(...)
- func (b *Builder) PrepareSandbox(...)
- func (b *Builder) Require(names ...string) error
- func (b *Builder) RequireSandbox() error
- func (b *Builder) RunStart(h agent.RunStartHook)
- func (b *Builder) SandboxTools(f func(*sandboxtools.Options))
- func (b *Builder) Section(s agent.PromptSection)
- func (b *Builder) SetAnswers(a agent.AnswerChecker) error
- func (b *Builder) SetChecker(c agent.Checker, d agent.DeliverableSource) error
- func (b *Builder) SetImages(i agent.ImageAttacher) error
- func (b *Builder) SetPurger(p runtime.Purger) error
- func (b *Builder) StepNote(n agent.StepNote)
- func (b *Builder) TailSection(s agent.PromptSection)
- func (b *Builder) ToolHook(h agent.ToolHook)
- func (b *Builder) WrapTools(w func(tools.Provider) tools.Provider)
- type CompactResult
- type Coordinator
- type Feature
- func Artifacts() Feature
- func Codecheck(coding bool) Feature
- func Explore() Feature
- func FeatureFunc(name string, install func(*Builder) error) Feature
- func Goals() Feature
- func MCP() Feature
- func Memory() Feature
- func Permissions(coding bool) Feature
- func Plan() Feature
- func ProfileCoding() []Feature
- func ProfileMinimal() []Feature
- func ProfileNamed(name string) []Feature
- func ProfileWork() []Feature
- func ProjectDocs() Feature
- func Sandbox() Feature
- func Skills() Feature
- func Titles() Feature
- func ToolProfile(coding bool) Feature
- func Verify() Feature
- func Workspace() Feature
- type Harness
- func (h *Harness) Cancel(ctx context.Context, user, runID string) error
- func (h *Harness) Compact(ctx context.Context, user, threadID, model string) (*CompactResult, error)
- func (h *Harness) Events(ctx context.Context, runID string, after int64) <-chan store.Event
- func (h *Harness) Fork(ctx context.Context, user, threadID, messageID string) (*store.Thread, error)
- func (h *Harness) HasSandbox() bool
- func (h *Harness) NewThread(ctx context.Context, user, title string) (*store.Thread, error)
- func (h *Harness) Redo(ctx context.Context, user, threadID string) (*HistoryStep, error)
- func (h *Harness) Resume(ctx context.Context, user, threadID string, r ResumeRequest) (*store.Run, error)
- func (h *Harness) Run(ctx context.Context) error
- func (h *Harness) Send(ctx context.Context, user, threadID, text string, o RunOptions) (*store.Run, error)
- func (h *Harness) Steer(ctx context.Context, user, runID, text string) error
- func (h *Harness) SteerAs(ctx context.Context, user, runID, text string, a Author) error
- func (h *Harness) Undo(ctx context.Context, user, threadID string) (*HistoryStep, error)
- type HistoryStep
- type Infra
- type Options
- type ResumeRequest
- type RunMode
- type RunOptions
- type SandboxMode
- type Store
Constants ¶
const ( FeatureSandbox = "sandbox" FeatureCodecheck = "codecheck" FeatureExplore = "explore" FeatureSkills = "skills" FeatureMCP = "mcp" FeaturePlan = "plan" FeatureProjectDocs = "projectdocs" FeatureArtifacts = "artifacts" FeatureWorkspace = "workspace" FeatureTitles = "titles" FeatureVerify = "verify" FeatureGoals = "goals" FeatureMemory = "memory" FeatureToolProfile = "toolprofile" FeaturePermissions = "permissions" )
Names of the built-in features (Feature.Name, Builder.Has, Builder.Require).
const ( // MaxAttachments is the most attachments one message carries (the number of // images one model request carries). MaxAttachments = agent.MaxRequestImages // MaxAttachmentBytes is the largest attachment (the largest image a vision // model is sent). MaxAttachmentBytes = 5 << 20 )
Limits of RunOptions.Attachments.
Variables ¶
var ( // ErrNothingToUndo means the thread has no user message left to remove. ErrNothingToUndo = errors.New("nothing to undo") // ErrNothingToRedo means no undone step is available: none was undone, or a message was sent since. ErrNothingToRedo = errors.New("nothing to redo") // ErrHistoryUnsupported means the Store cannot edit a thread's history (store.HistoryStore). ErrHistoryUnsupported = errors.New("the store cannot edit a thread's history") )
Errors of the history operations (Compact, Undo, Redo, Fork).
var ErrInvalidRequest = errors.New("invalid request")
ErrInvalidRequest wraps the errors caused by the caller's input.
var ErrNoSandbox = errors.New("this run requires a sandbox but the harness has none: set Options.Backend or SANDBOX_BACKEND")
ErrNoSandbox is returned (wrapped in ErrInvalidRequest) by Send when the run asks for SandboxOn and the harness has no sandbox.
Functions ¶
func DefaultLocalStoreDir ¶
func DefaultLocalStoreDir() string
DefaultLocalStoreDir is the state directory OpenLocalStore uses when none is given: $LOCAL_STATE_DIR, else <user dir>/sessions ($HAR_HOME or ~/.har), else (user directory disabled or unknown) $XDG_STATE_HOME/harness, else ~/.local/state/harness.
func NewSandboxBackend ¶
NewSandboxBackend builds the backend the configuration selects (Config.SandboxBackendName): the registered factory of SANDBOX_BACKEND, or of "opensandbox" when only OPENSANDBOX_URL is set, or none (a nil sandbox.Backend). Every process that can create a sandbox goes through it, so every one of them applies the production refusal of unrestricted egress (config.EgressMode) before a backend is built.
func OpenLocalStore ¶
OpenLocalStore opens the durable single-process store for local hosts (CLI, TUI, desktop): threads, messages, runs, plans, summaries, approvals and event logs survive restarts, with no Postgres or Redis. Pass it as Options.Store and Close it on exit.
dir is the state directory; "" uses DefaultLocalStoreDir. Runs that were in progress when the previous process died are marked interrupted. Use Store.Sessions() to list, fork and delete threads. See store/filestore.
func Provide ¶
Provide publishes a service for the features installed after this one (looked up by its type with Lookup). One service per type.
func RegisterMCP ¶ added in v0.3.0
RegisterMCP sets the implementation of the MCP feature; package mcpfeature calls it from an init function.
func SandboxSettings ¶
SandboxSettings maps the configuration (SANDBOX_BACKEND, OPENSANDBOX_*, SANDBOX_*, LOCAL_*) to the settings the registered sandbox backends are built from.
Types ¶
type Attachment ¶
type Attachment struct {
// Name is the file name (its extension is corrected to MIME's).
Name string
// MIME is image/png, image/jpeg, image/gif or image/webp.
MIME string
Data []byte
}
Attachment is an image sent with a message. It is stored in the thread's workspace like an uploaded file and shown to vision models; a model without vision sees the file's path only.
type Broker ¶
Broker is the run queue and the per-run control bus (cancel, steers). The in-process one is queue.NewMemory; the Redis one (redisinfra) shares it between processes. Any other transport (NATS, SQS...) implements the same three interfaces.
type Builder ¶
type Builder struct {
// Config is the environment-driven configuration.
Config *config.Config
// Store is the persistence (Options.Store, default: in memory).
Store Store
// Models builds the chat models.
Models llm.Factory
// Sandboxes manages the sandboxes; Sandboxes.Enabled() reports whether a
// backend is configured.
Sandboxes sandbox.Manager
// Blobs stores artifact contents.
Blobs artifacts.Blobs
// Infra is the infrastructure shared between processes (queue, event log...).
Infra Infra
// Options are the options the host passed to New (read only).
Options Options
// Services of the built-in features, set by the feature that provides them
// and nil until it is installed (so install it earlier in the list).
Artifacts *artifacts.Service
Workspace *workspace.Service
Skills *skills.Registry
Installer *skills.Installer
Memory *memory.Service
Verifier *verify.Verifier
// contains filtered or unexported fields
}
Builder is what a Feature sees while the harness is built: the environment to read, and the contributions it may make. A feature that builds on another finds that feature's services in the exported fields (nil when its feature is not installed) or through Lookup.
func (*Builder) AddTools ¶
AddTools offers tool providers to the agent (nil ones are ignored), in the order features are installed, before Options.Tools.
func (*Builder) After ¶
After registers f to run once every feature is installed (to build what depends on the other features' contributions).
func (*Builder) Background ¶
Background starts f in a goroutine once the harness is built (New returned without error); ctx is never cancelled by the harness, f ends on its own.
func (*Builder) BeforeTool ¶
func (b *Builder) BeforeTool(h agent.BeforeToolHook)
BeforeTool adds a hook that gates tool calls before they run.
func (*Builder) Configure ¶
Configure changes the agent's configuration after every feature contributed (an escape hatch for what the other methods do not cover). Mutators run in installation order.
func (*Builder) ContextSection ¶
func (b *Builder) ContextSection(s agent.PromptSection)
ContextSection adds a dynamic section, rendered in the prompt's final context block (recalled memories, the current goal...).
func (*Builder) Job ¶
Job adds a periodic maintenance job (run by one runtime at a time when the Infra has a Coordinator).
func (*Builder) OnSandboxCreate ¶
func (b *Builder) OnSandboxCreate(f func(ctx context.Context, threadID string, sb sandbox.Sandbox, recreated bool) string)
OnSandboxCreate registers a function run when a sandbox is created; a non-empty result is added to the notice the model sees.
func (*Builder) PrepareSandbox ¶
func (b *Builder) PrepareSandbox(f func(ctx context.Context, threadID string, sb sandbox.Sandbox, recreated bool) string)
PrepareSandbox registers a function run when a sandbox is created, before the OnSandboxCreate ones (restoring history before restoring files).
func (*Builder) Require ¶
Require fails unless the named features are installed (earlier in the list).
func (*Builder) RequireSandbox ¶
RequireSandbox fails unless a sandbox backend is configured (Options.Backend, SANDBOX_BACKEND or OPENSANDBOX_URL).
func (*Builder) RunStart ¶
func (b *Builder) RunStart(h agent.RunStartHook)
RunStart adds a hook run before the first step of every run.
func (*Builder) SandboxTools ¶
func (b *Builder) SandboxTools(f func(*sandboxtools.Options))
SandboxTools changes the options of the sandbox tools (execute_command, read_file...): hook into the lifecycle of a sandbox or of a command. Each feature chains onto what the previous ones set; it applies only when the "sandbox" feature is installed and a backend is configured.
func (*Builder) Section ¶
func (b *Builder) Section(s agent.PromptSection)
Section adds a static system-prompt section (rendered in order).
func (*Builder) SetAnswers ¶
func (b *Builder) SetAnswers(a agent.AnswerChecker) error
SetAnswers sets the reviewer of final answers; only one feature may.
func (*Builder) SetChecker ¶
SetChecker sets the deliverable checker and the source of the deliverables restored after a compaction; only one feature may.
func (*Builder) SetImages ¶
func (b *Builder) SetImages(i agent.ImageAttacher) error
SetImages sets how attached images reach vision models; only one feature may.
func (*Builder) StepNote ¶
StepNote adds a note source asked before every model call of a run (news that appears mid-run, such as the project skills of a sandbox the run started).
func (*Builder) TailSection ¶
func (b *Builder) TailSection(s agent.PromptSection)
TailSection adds a section rendered once per run into the reminder at the end of every request (keeps the system prompt a cacheable prefix).
type CompactResult ¶
type CompactResult struct {
// Compacted is false when there was nothing to summarise.
Compacted bool
TokensBefore int
TokensAfter int
}
CompactResult is the outcome of Compact.
type Coordinator ¶
type Coordinator interface {
sandbox.Coordinator
runtime.Locks
}
Coordinator is the small shared key/value state the processes of one deployment use to cooperate: sandbox creation locks and health streaks (sandbox.Coordinator), the sweeper and job locks and the run liveness marks (runtime.Locks). redisx.NewCoordinator is the Redis one; sandbox.LocalCoordinator keeps it in the process.
type Feature ¶
type Feature interface {
// Name identifies the feature: unique in a harness, used in errors and by
// Builder.Has / Builder.Require.
Name() string
Install(*Builder) error
}
A Feature is an optional capability of the harness: a set of tools, prompt sections, hooks and background jobs that belong together (permissions, memory, skills, goals...). A host picks the features it wants with Options.Features (or a named profile: ProfileCoding, ProfileWork, ProfileMinimal) and may add its own.
Install is called once, in the order of Options.Features, while the harness is being built. It reads the environment from the Builder (configuration, store, models, sandboxes, infrastructure), contributes through the Builder's methods, and returns an error to abort harness.New: an invalid configuration, or a missing capability (see Builder.RequireSandbox, Builder.Require and StoreAs).
func Artifacts ¶
func Artifacts() Feature
Artifacts tracks the files the agent produces (snapshots on tool results, previews, links in answers, image attachments) and purges deleted threads' data after HARNESS_PURGE_AFTER_DAYS. Contents go to Options.Blobs (default: the Store). It publishes Builder.Artifacts.
func Codecheck ¶
Codecheck adds a syntax check to the notice of write_file and edit_file (the coding agent's immediate feedback; AGENT_CODE_CHECKS adds commands). With coding false it only installs when AGENT_CODE_CHECKS is set. It requires the Sandbox feature.
func Explore ¶
func Explore() Feature
Explore offers the explore tool, a read-only sub-agent that searches and reads the workspace and reports back (LLM_EXPLORE_MODEL, default the default model). Without a sandbox it contributes nothing. It requires the Sandbox feature.
func FeatureFunc ¶
FeatureFunc adapts a function to a Feature.
func Goals ¶
func Goals() Feature
Goals lets a thread carry a goal that is judged after every run and, while unmet, continues with another run. It uses Artifacts and Verify, when installed, to show the judge what was produced.
func MCP ¶
func MCP() Feature
MCP offers the tools of the MCP servers of the configuration (MCP_SERVERS). It needs the implementation in package mcpfeature, imported for its side effect (a blank import). Without it, a configuration that names MCP servers is an error, not silently ignored; one that names none installs nothing.
func Memory ¶
func Memory() Feature
Memory gives the agent a long-term memory: the memory tools, the memory prompt and the recall of relevant entries, and a periodic consolidation job. It publishes Builder.Memory.
func Permissions ¶
Permissions puts the permission layer (allow/ask/deny rules, modes; AGENT_PERMISSIONS*) in front of the tools and snapshots the git working tree at the start of runs on the local backend. It applies to the local backend and, with coding true, to the coding agent on a remote sandbox; with neither it contributes nothing (the work profile on a remote sandbox).
The mode is AGENT_PERMISSIONS; without it the local backend asks and the coding agent on a remote sandbox, which is isolated, does not (yolo: deny rules still apply). The interactive approvals gate stays behind it for the tools the policy has no rule for.
func ProfileCoding ¶
func ProfileCoding() []Feature
ProfileCoding is the lean coding agent (AGENT_PROFILE=coding): ProfileWork plus the explore sub-agent, the syntax checks of written files and the permission layer, with the tool allow-list that leaves out the document viewer, the skills (unless the user has some) and the memory.
func ProfileMinimal ¶
func ProfileMinimal() []Feature
ProfileMinimal is the smallest useful agent: the sandbox tools and the plan tools, with no artifacts, memory, skills, goals or titles.
func ProfileNamed ¶
ProfileNamed returns the feature set of a profile name (AGENT_PROFILE): "coding", "minimal", anything else the work profile.
func ProfileWork ¶
func ProfileWork() []Feature
ProfileWork is the full feature set: the sandbox tools, skills, MCP, plan tools, project documents, artifacts, workspace checkpoints, titles, verification, goals and memory. It is what AGENT_PROFILE=work (or unset) runs. Code checks (AGENT_CODE_CHECKS) and permissions (local backend) apply when configured.
func ProjectDocs ¶
func ProjectDocs() Feature
ProjectDocs adds the instructions of the project and of the user (AGENTS.md, CLAUDE.md, GEMINI.md, Cursor and Copilot files, .har/instructions.md; see package projectdocs) to the prompt, and the notes of subdirectories to the results of read_file, write_file and edit_file. The user's own ~/.har/AGENTS.md is read with the local backend, or when HARNESS_USER_INSTRUCTIONS is set.
func Sandbox ¶
func Sandbox() Feature
Sandbox offers the sandbox tools: execute_command, job_output, job_kill, read_file, view_file, search_files, write_file, edit_file, list_files. Other features hook into them through Builder.SandboxTools. Without a configured sandbox backend it contributes nothing.
func Skills ¶
func Skills() Feature
Skills offers the skills (<name>/SKILL.md folders): the load_skill tool, the skills index in the prompt, and their installation into sandboxes. The built-in skills, Options.ExtraSkills and the user directory (SKILLS_DIR) are read; the project skills come from the host with the local backend and from each thread's own /workspace with a remote one (skills.LoadSandbox). It publishes Builder.Skills and Builder.Installer.
func ToolProfile ¶
ToolProfile applies the tool profile: with coding true the lean coding allow-list (no document viewer, skills only when the user has some, no memory unless AGENT_MEMORY_IN_CODING), and in both cases the AGENT_TOOLS overrides. It also drops the prompt sections of the skills and memory features whose tools it hides. It takes effect on the Skills and Memory features whatever the order.
type Harness ¶
type Harness struct {
Store Store
Log eventlog.Log
Queue queue.Queue
Bus queue.Bus
Sandboxes sandbox.Manager
Artifacts *artifacts.Service
Skills *skills.Registry
Workspace *workspace.Service
Runtime *runtime.Runtime
Agent *agent.Agent
// Memory is the memory service (nil without the Memory feature).
Memory *memory.Service
// contains filtered or unexported fields
}
Harness runs agent runs for any number of users and threads.
func New ¶
New wires the harness: the core (store, models, sandboxes, infrastructure, agent loop, runtime) and the features of Options.Features (default: the profile of AGENT_PROFILE, see ProfileWork, ProfileCoding, ProfileMinimal).
func (*Harness) Cancel ¶
Cancel stops a run: a queued one is cancelled at once, a running one gets a cancel signal and ends with a "cancelled" RUN_FINISHED.
func (*Harness) Compact ¶
func (h *Harness) Compact(ctx context.Context, user, threadID, model string) (*CompactResult, error)
Compact summarises the thread's history now with a run of kind compact on model, and waits for it. store.ErrRunActive (wrapped) when the thread has a run in progress.
func (*Harness) Events ¶
Events streams the run's AG-UI events with seq > after, then follows it live until RUN_FINISHED or RUN_ERROR. Each event carries its seq (resume point).
Events takes no user: it trusts the caller to have established that the run belongs to the requesting user (Store.GetUserRun), as hosts/client and hosts/web do. A host that exposes run ids to end users without going through them must make that check itself.
func (*Harness) Fork ¶
func (h *Harness) Fork(ctx context.Context, user, threadID, messageID string) (*store.Thread, error)
Fork copies the thread's messages up to and including messageID ("" is the whole thread, a tool call is kept with its results) into a new thread titled "<old> (fork)".
func (*Harness) HasSandbox ¶
HasSandbox reports whether runs can use a sandbox: a backend is configured and the Sandbox feature is installed.
func (*Harness) Redo ¶
Redo reapplies the step Undo removed last: its messages and, in a git workspace, its files. It is valid until a message is sent. The thread must be idle (store.ErrRunActive).
func (*Harness) Resume ¶
func (h *Harness) Resume(ctx context.Context, user, threadID string, r ResumeRequest) (*store.Run, error)
Resume answers a run's interrupt (a tool approval or an ask_user question) and queues the run that continues the conversation. Follow it with Events.
func (*Harness) Run ¶
Run consumes queued runs until ctx is done, then lets in-flight runs finish (or interrupts them after the shutdown grace).
func (*Harness) Send ¶
func (h *Harness) Send(ctx context.Context, user, threadID, text string, o RunOptions) (*store.Run, error)
Send adds a user message to the thread and queues a run answering it. The run is executed by Run; follow it with Events.
type HistoryStep ¶
type HistoryStep struct {
// Prompt is the user message removed (Undo) or restored (Redo).
Prompt string
// Files are the workspace paths whose content changed; empty without a git workspace.
Files []string
// CanUndo and CanRedo tell whether another step is available.
CanUndo, CanRedo bool
}
HistoryStep is the outcome of Undo and Redo.
type Infra ¶
type Infra struct {
// Log is the per-run event log (default eventlog.NewMemory over the Store).
Log eventlog.Log
// Broker is the run queue and control bus (default queue.NewMemory).
Broker Broker
// Coordinator shares sandbox and sweeper locks (default: none, in-process).
Coordinator Coordinator
// Jobs persists the running background jobs so that a restarted process
// resumes their keep-alives (default: in memory only).
Jobs sandboxtools.JobList
// Installs shares which skill revisions each sandbox holds, and the install
// locks (default: in-process).
Installs skills.InstallState
}
Infra is everything the harness shares between processes. Every field is optional: a missing one falls back to its in-process implementation, so a zero Infra is a self-contained single-process harness. A host that runs several processes injects implementations built on the infrastructure it has (package redisinfra for Redis).
type Options ¶
type Options struct {
// Config is the environment-driven configuration (config.Load).
Config *config.Config
// Store persists threads, runs, messages, artifacts, memory… (default: in memory;
// store/pgstore for Postgres).
Store Store
// Models builds the chat models (default: llm.New over llmOptions(Config), the OpenAI-compatible
// provider, or Anthropic with LLM_PROVIDER=anthropic).
Models llm.Factory
// Backend provides the sandboxes. Default: the backend named by
// SANDBOX_BACKEND (local, opensandbox, none, or one registered with
// backends.Register), else OpenSandbox when OPENSANDBOX_URL is set, else
// none: the agent then has no sandbox tools and a prompt that says so.
Backend sandbox.Backend
// Blobs stores artifact contents (default: in the Store).
Blobs artifacts.Blobs
// Infra holds the implementations of what several processes share: run
// queue and control bus, event log, locks, job list, skill installs. Every
// part is optional and falls back to its in-process version. A host on
// another transport (NATS, SQS...) injects its own; package redisinfra
// builds the Redis one. Without it the harness is single-process.
Infra *Infra
// Features are the capabilities to install, in order (default: the profile
// of AGENT_PROFILE: ProfileWork, ProfileCoding or ProfileMinimal). Compose
// your own list from the constructors (Sandbox(), Memory()...) and your
// own Features; see README "Features and profiles".
Features []Feature
// BuiltinSkills holds <name>/SKILL.md folders (default: skills/skillsfs).
BuiltinSkills fs.FS
// ExtraSkills holds more <name>/SKILL.md folders, added after the built-ins
// and before the user directory (config SKILLS_DIR): the host's own skills.
ExtraSkills fs.FS
// Tools are extra tool providers (host-defined tools).
Tools []tools.Provider
// Hooks run at the end of every run, after the harness' own.
Hooks []runtime.Hook
// Version identifies the host to MCP servers.
Version string
// RuntimeID names this process in run ownership (default: hostname-random).
RuntimeID string
// MemoryKey, when set, names the memory (the key its entries are stored
// under) a run of login on threadID reads and writes; "" means login's own.
// A team host returns "project:<id>" for project threads.
MemoryKey func(ctx context.Context, login, threadID string) string
// MemoryUserKey names the user's private layer inside a shared memory ("" for none), MemoryShared
// says whether a key is a memory shared between people (a project's).
MemoryUserKey func(ctx context.Context, login, threadID string) string
}
Options configures a Harness. Only Config is required.
type ResumeRequest ¶
type ResumeRequest struct {
// InterruptID is the interrupt's id (the approval id for a tool approval).
InterruptID string
// Reason is the interrupt reason: store.ReasonToolApproval or the ask_user reason.
Reason string
// Decision applies to tool approvals: store.DecisionApprove, DecisionDeny or DecisionRespond.
Decision string
// Always approves the tool for the rest of the run chain (scope "run").
Always bool
// Text is the answer to an ask_user question, or the free text of a respond.
Text string
// Model, Interactive and ReasoningEffort are the RunOptions of the resumed run.
Model string
Interactive bool
ReasoningEffort string
// Mode is ModeBuild or ModePlan; empty keeps the mode of the thread's previous run.
Mode RunMode
}
ResumeRequest answers the interrupt a run ended with.
type RunMode ¶
type RunMode string
RunMode is RunOptions.Mode.
const ( // ModeBuild (the default): the run has all the tools its profile allows. ModeBuild RunMode = "build" // ModePlan: the run is read-only. The engine offers it only tools without // side effects (reads, searches, read-only MCP tools) and no command // execution, and its prompt asks for an investigation and a plan. A resumed // run keeps the mode of the thread's previous run. ModePlan RunMode = "plan" )
type RunOptions ¶
type RunOptions struct {
// Model is required: an id the Config allows.
Model string
// ReasoningEffort is low|medium|high|… ("" for the model's default).
ReasoningEffort string
// Skills are skill names requested explicitly for this run.
Skills []string
// Interactive makes risky tool calls wait for Approve/Reject.
Interactive bool
// MessageID makes Send idempotent for that user message (optional).
MessageID string
// Sandbox says whether the run may use a sandbox (default SandboxAuto).
// It is kept in the run record: a resumed run, a goal turn and a
// compaction keep the mode of the thread's latest run.
Sandbox SandboxMode
// Mode is ModeBuild (default) or ModePlan (read-only: no tool may change
// anything). It is kept in the run record, so a worker process honours it.
Mode RunMode
// Attachments are images sent with the message (at most MaxAttachments of
// MaxAttachmentBytes each); they are stored in the thread's workspace.
Attachments []Attachment
// Author is the user who typed the message when it is not the thread's
// owner (a project member), with AuthorKind and OnBehalfOf for a
// supervisor; they are recorded on the message and shown to the model in
// threads with several speakers. Empty means the owner.
Author string
AuthorKind string
OnBehalfOf string
}
RunOptions are the per-run settings of Send.
type SandboxMode ¶
type SandboxMode string
SandboxMode is RunOptions.Sandbox.
const ( // SandboxAuto (the default): the run has the sandbox tools when a backend // is configured and the Sandbox feature is installed; the sandbox is only // created when a tool first needs it. Without a backend the run simply has // no sandbox tools. SandboxAuto SandboxMode = "auto" // SandboxOff: the run has no sandbox tools, gets the no-sandbox prompt and // never creates (or uses) a sandbox, whatever the harness is configured with. SandboxOff SandboxMode = "off" // SandboxOn: like SandboxAuto, but Send fails with ErrInvalidRequest when // the harness cannot provide a sandbox (no backend, or no Sandbox feature). SandboxOn SandboxMode = "on" )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
blobs/s3blobs
Package s3blobs is the S3-compatible artifacts.Blobs backend (Dell ECS, RustFS, AWS).
|
Package s3blobs is the S3-compatible artifacts.Blobs backend (Dell ECS, RustFS, AWS). |
|
errtrack
Package errtrack sends the errors the harness logs to an error tracker that speaks the Sentry protocol (Sentry, Rustrak, GlitchTip…).
|
Package errtrack sends the errors the harness logs to an error tracker that speaks the Sentry protocol (Sentry, Rustrak, GlitchTip…). |
|
redisx
Package redisx builds the Redis client (Sentinel or standalone).
|
Package redisx builds the Redis client (Sentinel or standalone). |
|
store/conformance
Package conformance is the behavioural test suite every store backend (memstore, filestore, pgstore) must pass: the same cases run against each one, so a backend cannot drift from the port's contract (core/store, core/sandbox.Store).
|
Package conformance is the behavioural test suite every store backend (memstore, filestore, pgstore) must pass: the same cases run against each one, so a backend cannot drift from the port's contract (core/store, core/sandbox.Store). |
|
store/filestore
Package filestore is a durable single-process store.Full for local hosts (CLI, TUI, desktop): it wraps store/memstore and persists the conversation state to an append-only JSON-lines journal in a state directory, so a closed terminal (or kill -9) never loses a session.
|
Package filestore is a durable single-process store.Full for local hosts (CLI, TUI, desktop): it wraps store/memstore and persists the conversation state to an append-only JSON-lines journal in a state directory, so a closed terminal (or kill -9) never loses a session. |
|
store/memstore
Package memstore is an in-memory store.Full used by tests (and nothing else).
|
Package memstore is an in-memory store.Full used by tests (and nothing else). |
|
store/pgstore/migrate
Package migrate applies the embedded SQL migrations (mirrors authn/internal/migrate).
|
Package migrate applies the embedded SQL migrations (mirrors authn/internal/migrate). |
|
store/teamstore
Package teamstore implements store.TeamStore: Mem (in memory, optionally persisted to a JSON file, for local and single-process hosts) and PG.
|
Package teamstore implements store.TeamStore: Mem (in memory, optionally persisted to a JSON file, for local and single-process hosts) and PG. |
|
sandbox
module
|
|
|
ai
module
|
|
|
app
module
|
|
|
Package bench runs coding tasks through the real harness (local sandbox, coding profile) against a model and reports pass/fail with the cost: steps, tool calls, tokens, prompt-cache hits, wall time and memory.
|
Package bench runs coding tasks through the real harness (local sandbox, coding profile) against a model and reports pass/fail with the cost: steps, tool calls, tokens, prompt-cache hits, wall time and memory. |
|
coding
|
|
|
codecheck
Package codecheck gives the agent immediate syntax feedback on the files it writes: after write_file or edit_file, a cheap per-extension command checks the file and its complaint is appended to the tool result, so a broken edit is fixed in the next step instead of surfacing at the end of a test run.
|
Package codecheck gives the agent immediate syntax feedback on the files it writes: after write_file or edit_file, a cheap per-extension command checks the file and its complaint is appended to the tool result, so a broken edit is fixed in the next step instead of surfacing at the end of a test run. |
|
gitsafe
Package gitsafe takes restorable snapshots of a git working tree without touching what belongs to the user: no commit on a branch, no change to the index or the stash list.
|
Package gitsafe takes restorable snapshots of a git working tree without touching what belongs to the user: no commit on a branch, no change to the index or the stash list. |
|
sandboxtools
Package sandboxtools exposes the thread sandbox to the model: execute_command (with background jobs: job_output, job_kill), read_file (text, documents, images), view_file (rendered pages), search_files, write_file, edit_file and list_files.
|
Package sandboxtools exposes the thread sandbox to the model: execute_command (with background jobs: job_output, job_kill), read_file (text, documents, images), view_file (rendered pages), search_files, write_file, edit_file and list_files. |
|
sandboxtools/conformance
Package conformance checks that a sandbox adapter runs the harness' sandbox tools (execute_command with background jobs, read/write/edit/list files, search_files) end to end: the scripts those tools send through sandbox.Sandbox.Exec need bash, GNU coreutils, python3 and ripgrep in the sandbox image (docs/sandbox-adapters.md).
|
Package conformance checks that a sandbox adapter runs the harness' sandbox tools (execute_command with background jobs, read/write/edit/list files, search_files) end to end: the scripts those tools send through sandbox.Sandbox.Exec need bash, GNU coreutils, python3 and ripgrep in the sandbox image (docs/sandbox-adapters.md). |
|
Package config loads the service configuration from environment variables.
|
Package config loads the service configuration from environment variables. |
|
core
module
|
|
|
engine
|
|
|
agent
Package agent is the agent loop: an own ReAct loop on eino ToolCallingChatModel that streams AG-UI events and checkpoints messages.
|
Package agent is the agent loop: an own ReAct loop on eino ToolCallingChatModel that streams AG-UI events and checkpoints messages. |
|
approvals
Package approvals implements Work's interactive mode: risky tool calls of an interactive run pause before they execute until the user approves, denies or answers them (agent BeforeToolHook; decisions are applied by the store when the resume run is created and by the agent when it starts).
|
Package approvals implements Work's interactive mode: risky tool calls of an interactive run pause before they execute until the user approves, denies or answers them (agent BeforeToolHook; decisions are applied by the store when the resume run is created and by the agent when it starts). |
|
eventlog
Package eventlog is the per-run AG-UI event log contract and its in-process implementation (MemoryLog).
|
Package eventlog is the per-run AG-UI event log contract and its in-process implementation (MemoryLog). |
|
queue
Package queue holds the Redis-backed run queue, the per-run control channel (cancel) and the per-run steer list.
|
Package queue holds the Redis-backed run queue, the per-run control channel (cancel) and the per-run steer list. |
|
runtime
Package runtime claims queued runs, drives the agent and finishes runs.
|
Package runtime claims queued runs, drives the agent and finishes runs. |
|
syncx
Package syncx holds small concurrency helpers: a keyed mutex whose entries are freed on release and a bounded LRU cache.
|
Package syncx holds small concurrency helpers: a keyed mutex whose entries are freed on release and a bounded LRU cache. |
|
tools
Package tools defines tool providers assembled per run.
|
Package tools defines tool providers assembled per run. |
|
examples
|
|
|
sandbox-adapter
Package example is a worked sandbox adapter for a generic REST service that can create sandboxes and run commands in them.
|
Package example is a worked sandbox adapter for a generic REST service that can create sandboxes and run commands in them. |
|
website
command
Command website shows how a website embeds the harness as a Go library: one process serving its own pages and endpoints next to the agent.
|
Command website shows how a website embeds the harness as a Go library: one process serving its own pages and endpoints next to the agent. |
|
features
|
|
|
artifacts
Package artifacts makes the files the agent produces under /workspace durable: snapshots after file-changing tools (and at run end), versioned and sha256-deduplicated content in a blob store (Postgres or a host-provided Blobs (see artifacts/s3blobs)), workspace restore on sandbox (re)creation, classified downloads, Office → PDF previews and user uploads.
|
Package artifacts makes the files the agent produces under /workspace durable: snapshots after file-changing tools (and at run end), versioned and sha256-deduplicated content in a blob store (Postgres or a host-provided Blobs (see artifacts/s3blobs)), workspace restore on sandbox (re)creation, classified downloads, Office → PDF previews and user uploads. |
|
artifacts/workspace
Package workspace keeps a thread's /workspace history: a local Git repository with an automatic checkpoint before every AI turn, per-file history, diffs and restores, persisted across sandbox expiry (the .git directory is archived into the blob store after each run and restored into every new sandbox of the thread), plus the workspace status / explicit restore of the files panel.
|
Package workspace keeps a thread's /workspace history: a local Git repository with an automatic checkpoint before every AI turn, per-file history, diffs and restores, persisted across sandbox expiry (the .git directory is archived into the blob store after each run and restored into every new sandbox of the thread), plus the workspace status / explicit restore of the files panel. |
|
commands
Package commands loads custom commands: markdown prompt templates a user invokes by name ("/review src/main.go").
|
Package commands loads custom commands: markdown prompt templates a user invokes by name ("/review src/main.go"). |
|
explore
Package exploretools provides the explore tool: a read-only sub-agent that investigates the repository with search_files, list_files and read_file in its own short conversation and returns a short report.
|
Package exploretools provides the explore tool: a read-only sub-agent that investigates the repository with search_files, list_files and read_file in its own short conversation and returns a short report. |
|
goals
Package goals keeps a thread working toward its goal (harness v2 §6): the goal is part of every run's system prompt, each completed run is judged by a short model call, and an unmet goal gets a new run until its turns run out.
|
Package goals keeps a thread working toward its goal (harness v2 §6): the goal is part of every run's system prompt, each completed run is judged by a short model call, and an unmet goal gets a new run until its turns run out. |
|
mcp
Package mcptools exposes tools of configured MCP servers (MCP_SERVERS).
|
Package mcptools exposes tools of configured MCP servers (MCP_SERVERS). |
|
memory
Package memory is the harness's memory service: per-user entries with a path, title, content, tags, importance and metadata, searched with Work's hybrid ranking, written under Work's policy (triggers, warn/strict write mode, secret redaction, soft/hard delete), recalled in the system prompt and consolidated periodically (deduplication, cleanup of deleted entries).
|
Package memory is the harness's memory service: per-user entries with a path, title, content, tags, importance and metadata, searched with Work's hybrid ranking, written under Work's policy (triggers, warn/strict write mode, secret redaction, soft/hard delete), recalled in the system prompt and consolidated periodically (deduplication, cleanup of deleted entries). |
|
memory/memorytools
Package memorytools exposes Work's memory MCP tools (memory_search, memory_get, memory_create, memory_update, memory_delete, memory_create_batch, memory_delete_batch, memory_capabilities) with the same names, input schemas and result shapes, backed by memory.Service.
|
Package memorytools exposes Work's memory MCP tools (memory_search, memory_get, memory_create, memory_update, memory_delete, memory_create_batch, memory_delete_batch, memory_capabilities) with the same names, input schemas and result shapes, backed by memory.Service. |
|
permissions
Package permissions is the safety layer of the local/coding profile: rules (allow / ask / deny) and modes decide, before a tool call runs, whether it is executed, needs the user's approval or is refused.
|
Package permissions is the safety layer of the local/coding profile: rules (allow / ask / deny) and modes decide, before a tool call runs, whether it is executed, needs the user's approval or is refused. |
|
plan
Package harnesstools provides the harness v2 agent tools update_plan and ask_user (the memory tools are in memorytools).
|
Package harnesstools provides the harness v2 agent tools update_plan and ask_user (the memory tools are in memorytools). |
|
projectdocs
Package projectdocs puts the instructions of the project and of the user (AGENTS.md and the files other agent tools read) in front of the agent of the coding profile, so it knows the build and test commands and the conventions without spending a tool call to find them.
|
Package projectdocs puts the instructions of the project and of the user (AGENTS.md and the files other agent tools read) in front of the agent of the coding profile, so it knows the build and test commands and the conventions without spending a tool call to find them. |
|
skills
Package skills is the skill registry: a skill is a folder with a SKILL.md (frontmatter name and description) and optional scripts and references.
|
Package skills is the skill registry: a skill is a folder with a SKILL.md (frontmatter name and description) and optional scripts and references. |
|
skills/skillsfs
Package skillsfs embeds the built-in skills (builtin/<name>/).
|
Package skillsfs embeds the built-in skills (builtin/<name>/). |
|
skills/skilltools
Package skilltools exposes load_skill: it returns a skill's SKILL.md (without frontmatter) and file list, and records the skill as loaded by the run.
|
Package skilltools exposes load_skill: it returns a skill's SKILL.md (without frontmatter) and file list, and records the skill as loaded by the run. |
|
titles
Package titles gives threads a short model-written title after their first completed run (harness v2 §5), unless the user set one.
|
Package titles gives threads a short model-written title after their first completed run (harness v2 §5), unless the user set one. |
|
verify
Package verify runs the deliverable checkers of harness v3 §4: after a tool call changed a file under /workspace/outputs/, the skill checker that matches its extension runs in the thread's sandbox (≤ 60 s) and its result becomes an agent.CheckResult (appended to the tool result, CUSTOM work.verification, the verification StopGuard and the goal judge).
|
Package verify runs the deliverable checkers of harness v3 §4: after a tool call changed a file under /workspace/outputs/, the skill checker that matches its extension runs in the thread's sandbox (≤ 60 s) and its result becomes an agent.CheckResult (appended to the tool result, CUSTOM work.verification, the verification StopGuard and the goal judge). |
|
hosts
|
|
|
clienttest
Package clienttest is the conformance suite of client.Client: any implementation (in process, over HTTP, a future one) must pass Run, so that a front end behaves the same against all of them.
|
Package clienttest is the conformance suite of client.Client: any implementation (in process, over HTTP, a future one) must pass Run, so that a front end behaves the same against all of them. |
|
httpapi
Package httpserver exposes a harness.Harness over HTTP for web front ends: a JSON API for threads, runs, approvals, files and models, the run's AG-UI events as Server-Sent Events (the SSE id is the event seq, so reconnects resume with Last-Event-ID or ?after= without loss or duplicates), and a small built-in browser UI (ui/) served at / and /ui/.
|
Package httpserver exposes a harness.Harness over HTTP for web front ends: a JSON API for threads, runs, approvals, files and models, the run's AG-UI events as Server-Sent Events (the SSE id is the event seq, so reconnects resume with Last-Event-ID or ?after= without loss or duplicates), and a small built-in browser UI (ui/) served at / and /ui/. |
|
worker
Package worker is the headless host that executes agent runs queued by other processes (a web server, an API, a scheduler): it connects to the shared Redis queue and Postgres store, consumes runs, and exposes an admin HTTP server (/healthz, /readyz, /metrics).
|
Package worker is the headless host that executes agent runs queued by other processes (a web server, an API, a scheduler): it connects to the shared Redis queue and Postgres store, consumes runs, and exposes an admin HTTP server (/healthz, /readyz, /metrics). |
|
client
module
|
|
|
tui
module
|
|
|
Package longtest drives the real harness (local sandbox, coding profile) through long scripted sessions: a fake model that behaves like an agent doing 50-200 steps of read_file / search_files / edit_file / execute_command in a generated repository, with realistic tool-output sizes (some 20-60 KB, which trigger spill and masking).
|
Package longtest drives the real harness (local sandbox, coding profile) through long scripted sessions: a fake model that behaves like an agent doing 50-200 steps of read_file / search_files / edit_file / execute_command in a generated repository, with realistic tool-output sizes (some 20-60 KB, which trigger spill and masking). |
|
Package mcpfeature is the implementation of harness.MCP(): the tools of the MCP servers of the configuration (MCP_SERVERS, .mcp.json, mcp.servers in config.yml), connected per run.
|
Package mcpfeature is the implementation of harness.MCP(): the tools of the MCP servers of the configuration (MCP_SERVERS, .mcp.json, mcp.servers in config.yml), connected per run. |
|
modelinfo
module
|
|
|
Package prompts holds the agent's system prompts: a registry of variants selected per model (LLM_PROMPT_VARIANTS), the shared wording of the optional sections, and the assembly order that keeps the request cache-stable — the static instructions first, the dynamic context (date, user, goal, recalled memories, conversation summary) last (harness v3 §5, §6).
|
Package prompts holds the agent's system prompts: a registry of variants selected per model (LLM_PROMPT_VARIANTS), the shared wording of the optional sections, and the assembly order that keeps the request cache-stable — the static instructions first, the dynamic context (date, user, goal, recalled memories, conversation summary) last (harness v3 §5, §6). |
|
Package redisinfra builds the harness.Infra of a deployment that shares Redis between processes: the run queue and control bus, the event log, locks, the background-job list and the skill installs.
|
Package redisinfra builds the harness.Infra of a deployment that shares Redis between processes: the run queue and control bus, the event log, locks, the background-job list and the skill installs. |