ShopNexus's agent runtime. The server calls POST /v1/turns once per turn
with the whole history; the runtime runs the model in a sandbox with a
workspace that lasts for the conversation, streams events back over SSE,
and keeps nothing in memory between turns. The design, and why, is in
ARCHITECTURE.md.
curl -N -H "Authorization: Bearer $AGENT_KEY" http://agent:8080/v1/turns -d '{
"conversation_id": "c-123",
"instructions": "You are ShopNexus'\''s console assistant.",
"history": [{"role": "user", "context": "staff: Lan", "content": "How many orders were cancelled this week?"}],
"token": "<turn token>",
"model": "console-agent", "model_key": "<Bifrost virtual key>"
}'
# event: tool_call ... event: tool_result ... event: step ... event: resultThe model gets three tools, bash, write and edit, in a bubblewrap
sandbox with no network and no secrets. Server tools are the shopnexus
CLI inside it, which reaches the API through a broker that adds the turn's
token.
Context that is missing, extra, wrong, stale or contradictory is what confuses models most, so the runtime controls every byte the model reads.
- The history only grows. Each request is the one before it plus what
is new, so the provider's prompt cache keeps working. Nothing is
omitted, cut or rewritten; only the last turn's reasoning drops out when
a new turn starts. A user message's
context(time, staff member, shop) is stored with it and read in a<context>block. - The harness writes little, and all of it is in one of three places:
the
<harness>section of the system prompt (runtime/harness.go), the sentences in tool results (messages.go,sandbox/messages.go), and tool descriptions (sandbox/tools.go). Errors reach the model as the tool wrote them, with secrets redacted. Only schema errors carry guidance. - You can see exactly what the model reads.
agent.Renderprints a request,testdata/view.goldenholds the view of a sample conversation, and the eval saves every transcript. Rungo test -updateafter a change that touches what the model reads, and review the diff.
Output over 4KB is saved to /workspace/.agent/out/<call>.txt; the model
reads its size, its first and last 20 lines, and the exit code, and
searches the file with rg, jq or fzf --filter instead of running the
command again.
agent.go, view.go the loop, Stop values, the loop check; the history view
messages.go the loop's sentences for the model
excerpt.go first and last lines of a long output; redaction
tool.go, validate.go Tool, NewTool; input checked against the JSON Schema
message.go, render.go Message (the stored format), Model; Render
openai/ Model for OpenAI-compatible APIs (Bifrost)
sandbox/ bwrap sandbox, its supervisor, bash/write/edit
workspace/ workspaces in Garage as tar.zst, cached locally
runtime/ POST /v1/turns, SSE, broker, egress, harness section
cmd/agent/ the service, configured by environment
eval/ real-model scenarios
The root package works on its own: agent.New(agent.Config{Model, Instructions, Tools}) and Run give a stateless loop over any tools,
with no sandbox.
The JSON Schema is the only place shape rules live, as in the server's API.
NewTool[T] builds it with jsonschema.For[T], fields in order, and the
same schema checks every call before Run. The model gets every problem at
once, in the validator's wording and in schema order:
invalid input for search_orders: field "status": value must be one of 'pending', 'shipped', 'cancelled'; additional properties 'limit' not allowed
go test -race ./... # bwrap must be installed; the sandbox and runtime tests use it
# the cgroup test needs a delegated cgroup
systemd-run --user --scope -p Delegate=yes env SANDBOX_TEST_CGROUP=1 go test -run Cgroup ./sandbox
# the workspace store against Garage or any S3
WORKSPACE_TEST_S3=host:3900 WORKSPACE_TEST_BUCKET=... WORKSPACE_TEST_KEY=... WORKSPACE_TEST_SECRET=... go test ./workspaceGolden files show what the model reads, but not how it reads it. The eval
in eval/ runs scenarios against real models: schema errors,
raw errors, context, and, through the real runtime and sandbox, a saved
long output, a failure seen through a pipe, and a background server. A
scenario can start with a made-up first call (first) to reach its path,
and lists what the model must read (hits), so a run that never reaches
its path fails. Checks are code, not a model acting as judge.
EVAL_BASE_URL=http://bifrost:8080/v1 EVAL_API_KEY=... \
go test ./eval -v -count=1 -timeout 40m -parallel 6 -models deepseek-v4-flash,gpt-5.6-terra -runs 3Transcripts go to eval/out/<model>/<scenario>-<n>.txt, the score table to
eval/out/report.txt.
docker build -t agent .
# the seccomp profile lives in the umbrella: infra/stack/seccomp/agent.json
docker run --security-opt seccomp=../infra/stack/seccomp/agent.json --security-opt systempaths=unconfined \
-e AGENT_KEY=... -e MODEL_BASE_URL=http://bifrost:8080/v1 -e MODEL=deepseek-v4-flash -e MODEL_API_KEY=... \
-e S3_ENDPOINT=garage:3900 -e S3_ACCESS_KEY=... -e S3_SECRET_KEY=... \
-p 8080:8080 agentIn the umbrella, docker compose --profile dev up -d agent-dev
runs it with package-proxy and the stack's Garage and Bifrost. The
settings are listed in ARCHITECTURE.md.