Documentation
¶
Overview ¶
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). Several workers can run in parallel, each with its own sandboxes.
Index ¶
Constants ¶
const DefaultAddr = "127.0.0.1:9090"
DefaultAddr is the admin address when neither Options.Addr nor HARNESS_WORKER_ADDR is set.
Variables ¶
var ErrPrivateQueue = errors.New("worker: the run queue is in memory, private to this process, so no other process can queue work for it (connect Redis, or pass Standalone)")
ErrPrivateQueue: the worker's run queue lives in its own memory, so it could never receive work.
Functions ¶
func Run ¶
Run builds the harness, serves the admin endpoints and consumes runs until ctx is done (or, with Once, until the queue is drained). On ctx done it stops claiming, lets in-flight runs finish for RUNTIME_SHUTDOWN_GRACE_SECONDS (then the runtime interrupts them and records why) and returns nil.
Types ¶
type Options ¶
type Options struct {
// Config is the environment configuration (default: config.Load()).
Config *config.Config
// Addr is the admin listen address (default: HARNESS_WORKER_ADDR, else 127.0.0.1:9090).
Addr string
// Standalone allows a private in-memory queue and store (a single process; mostly for tests and demos).
Standalone bool
// Once processes the queued runs until none is queued or running, then returns.
Once bool
// IdleFor is how long the queue must stay empty in Once mode (default 1 s).
IdleFor time.Duration
// RuntimeID names this worker in run ownership (default: hostname-random).
RuntimeID string
// Overrides, mostly for tests; nil builds them from Config.
Store harness.Store
Redis redis.UniversalClient
Models llm.Factory
Backend sandbox.Backend
// Features builds the capabilities of the worker's harness once its store is known (nil: the profile of
// AGENT_PROFILE, as for any harness). The returned func releases what the features opened and runs when the
// worker stops. A worker has to install the features whose end-of-run hooks, tools or policies must apply to
// the runs it executes (the agent factory is one): a run is finished by the process that ran it.
Features func(ctx context.Context, cfg *config.Config, st harness.Store) ([]harness.Feature, func(), error)
// MCPServers supplies the MCP servers of the marketplace for each run (harness.Options.MCPServers), built once
// the worker's store is known; nil adds none. The returned func releases what it opened and runs when the worker
// stops, or when building the harness fails.
MCPServers func(ctx context.Context, cfg *config.Config, st harness.Store) (harness.MCPServersFunc, func(), error)
// OnListening is called with the admin address once the server accepts connections.
OnListening func(addr string)
}
Options configures Run. The zero value reads everything from the environment.