worker

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hosts/worker

app/cmd/harness-worker (package hosts/worker) is a headless process that executes runs queued by other processes: a web server or API calls Send (it never calls Run), and any number of workers consume the shared Redis queue and Postgres store, each with its own sandboxes. Intelligence and sandboxes scale independently of the front end.

Setting Meaning
REDIS_*, POSTGRES_* the shared queue/event log and store (the same values as the sending process; migrations are applied at start)
LLM_*, OPENSANDBOX_URL / SANDBOX_BACKEND models and sandbox backend of this worker
RUNTIME_CONCURRENCY or -concurrency N maximum concurrent runs (default 16)
RUNTIME_SHUTDOWN_GRACE_SECONDS on SIGINT/SIGTERM the worker stops claiming and lets runs finish this long; the rest end interrupted (never lost)
HARNESS_WORKER_ADDR or -addr admin server, default 127.0.0.1:9090
-once process queued runs until none is queued or running, then exit 0 (batch, CI)
-standalone allow a private in-memory queue/store; without it the worker refuses to start unless Redis and Postgres are configured
-id worker id recorded as the run owner (default hostname-random)

Admin endpoints: GET /healthz (process is up), GET /readyz (200 while the queue loop reads; 503 when the consumer group cannot be created, the loop is stuck, or the worker is draining), GET /metrics (Prometheus text: harness_worker_up, _ready, _draining, _uptime_seconds, _concurrency, _runs_in_flight, _runs_started_total, _runs_finished_total{status}). The startup log names the store, queue and sandbox backend and the model list.

A docker-compose deployment is one redis and one postgres service, a web service built on the library (environment: the same REDIS_HOST/POSTGRES_HOST), and a worker service running harness-worker with those variables plus LLM_API_KEY and OPENSANDBOX_URL, HARNESS_WORKER_ADDR=0.0.0.0:9090, a health check on /readyz, stop_grace_period longer than RUNTIME_SHUTDOWN_GRACE_SECONDS, and deploy.replicas set to the number of workers wanted.

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

View Source
const DefaultAddr = "127.0.0.1:9090"

DefaultAddr is the admin address when neither Options.Addr nor HARNESS_WORKER_ADDR is set.

Variables

View Source
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

func Run(ctx context.Context, o Options) error

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.

type Wiring

type Wiring struct {
	Store   string // postgres | memory | the Go type of a custom store
	Queue   string // redis | memory
	Sandbox string // opensandbox | local | custom | none
}

Wiring says what the harness of a worker is connected to.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL