workbench

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 39 Imported by: 1 module, 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

Agent Workbench

A Surface module for making and improving Nanite agents: create, edit, version, import and export an agent; run eval suites against it; ask a model for edits that would fix the failures; accept or reject each; run again and compare. Apps include it from their own surface.yaml (Basalisk does; examples/demo here).

The agent is an agent directory as libs agent/agentdir v0.3.0 and Nanite 0.7.0 read it. The Workbench keeps its own state about an agent in a sidecar beside the directory, never inside it. Everything Nanite-specific goes through Runtime (runtime.go), which uses Nanite's public agent and evals packages only.

What is real today, and what is recorded for later

Part Today
Library, templates, duplicate, delete to trash real
Validation on every save (agentdir.Load, plus Nanite's variant and providers.yaml rules, its limits, literal-secret checks, the sidecar) real; nothing that does not validate is saved
Versions (a full copy, a digest, a note), diff, rollback real
Prompt, skills, tools (.mcp.json, permissions.yaml), variants, providers.yaml, context files, host.yaml runtime knobs real: these are Nanite's own files
compact_at a runtime option: Nanite takes it only in code (agent.Options.CompactAt). Kept in the sidecar and passed on every eval run; a host that opens the agent passes it the same way. A host.yaml key comes in a later agentdir release
Reflexes, triggers, presets agent/steer configuration in the sidecar, applied via agent.Options.Steering during evals. Reminder and halt actions execute; Surface command/tool actions need a connected host.
Base prompt shown read-only (Nanite's Universal slot) on the Prompt and Assembled prompt tabs
Boot prompts and boot profiles not here: they are Tether catalog concepts, not part of an agent directory
Slot budgets, slot placement, the context window, a compaction summary prompt not offered: engine-owned, set by the model, or not a knob Nanite has
Import and export real: .tar.gz export; .tar.gz, .tgz and .zip import; a directory copied in read-only
Eval runs, offline real: Nanite's eval harness with each case's script standing in for the model. A harness check, not evidence
Eval runs, live real, on the owner's action only, through the app's gateway, within a dollar cap and token budgets. Tested only against a fake gateway
Improvement proposals real, on the owner's action only; each edit is accepted or rejected by the owner

Layout

<root>/<id>/agent/                  the agent directory: what Nanite opens
<root>/<id>/workbench/              the sidecar
    meta.json                       source, template, created
    steering.json                   reflexes, triggers, presets (steer v0.1.0)
    options.json                    runtime options: compact_at
    versions/000001/tree/...        every file of each saved state
    versions/000001/meta.json       n, digest, agentdir digest, note, author, created
    evals/<suite>.yaml              eval suites
    runs/<run>.json                 eval runs
    proposals/<id>.json             improvement proposals
<root>/.trash/<id>-<time>/          deleted agents

<root> is the setting workbench.root, by default agents/ in the module's data directory. Other settings: eval_max_usd (default 10, at most 50), eval_turn_tokens (150,000), eval_run_tokens (500,000).

The agent's files

Authored paths only: agent.md, host.yaml, .mcp.json, permissions.yaml, providers.yaml, context/<name>.md, variants/<name>.md, skills/<name>/... (SKILL.md and its resources). Nothing else is read, written, versioned or exported; in particular never .nanite/ (conversations, traces, nanite.db*, agent.lock, transcripts/, jobs/). A file is at most 1 MiB, an agent at most 512 files and 16 MiB.

Credentials: a value passes a credential only by reference, when it is entirely ${VARIABLE}, Bearer ${VARIABLE}, or a keychain://, file:// or env:// reference. Checked in .mcp.json env, headers, arguments (and the value after a credential flag) and URLs; host.yaml runtime.env; providers.yaml key_ref, base_url and headers. A field named like a credential (*KEY*, *TOKEN*, *SECRET*, *AUTH*, *PASSWORD*, *_PAT) with a literal value is refused, and so is any value shaped like a known credential (sk-, sk-ant-, ghp_/github_pat_, xox?-, AKIA…, a private key, user:password@ in a URL, api_key=/token= in a query, Bearer and a 20-character token), in a field's value, in a command, or behind a reference (file://sk-…). A URL with a user part (token@host) is refused in configuration and a warning in prose; providers.yaml key_env must name a variable. Every other file (prompts, skills and their resources, context, suites) is scanned too: a known credential shape is a warning when saved and refuses an export; a credential-like assignment is a warning (sent with an export in X-Workbench-Warnings).

Validation, by file, on every save (and as you type, without saving):

  • agentdir.Load over the directory (agent.md's schema-2 front matter, host.yaml's profile, .mcp.json, skills).
  • variants/*.md through nanite/agent/authored: the name, strict front matter, read_only with can_spawn, last_n 1–50, budgets, tool patterns.
  • providers.yaml with Nanite's own ProviderSpec.Validate; key_ref must be a reference.
  • runtime.subtask_limit at most 8 (Nanite refuses the agent above it); a warning above about 5,900 for subtask_result_cap.
  • No literal credential in .mcp.json env or headers or host.yaml runtime.env: use ${VARIABLE} or a reference (keychain://, file://, env://). An export is refused while one is there.

Digests. digest is the Workbench's SHA-256 over every file of the agent and its sidecar files (steering, options), length-prefixed in path order like agentdir's own. It covers what agentdir_digest (agentdir.Load's) leaves out: variants, providers.yaml, skill resources and the sidecar. Runs are keyed by digest.

Saving

Before a save or a rollback writes anything, authored files changed on disk by hand since the last version (added, edited or removed) are kept as a version of their own (unsaved changes on disk, kept before: <note>, author disk), so nothing is overwritten without a copy. The new version is then recorded first and the files written after it: if the app stops in the middle, the last version is what was being saved, the disk may hold a mix of old and new files, and the next save keeps that mix as its own version before writing; roll back to either to finish.

A save writes the agent's changed authored files in place, each through a temporary file (.wb-tmp-*) and a rename, and removes the authored files the new state lacks. Nothing else in the directory is touched: Nanite's .nanite/ (nanite.db*, agent.lock, transcripts/, jobs/), notes, backups. The directory itself is never moved, so a host running the agent from it keeps running. At start the Workbench removes its own interrupted write's temporary files (.wb-tmp-* only, never inside a hidden directory such as .nanite/ or .git/), puts back an agent directory an older version left aside, and marks runs left running as interrupted.

Versions

Every save that changes something writes a version: a full copy of the files, the digest, the agentdir digest, a note, who saved it (owner, or agent for a tool) and when. A save names the digest it was edited from and is refused if the agent changed since. Rollback saves an old version's files as a new version. Accepting a proposal saves a version whose note names the proposal.

steering.json (steer v0.1.0 config)

{
  "workbench_format": 1,
  "presets": [
    {"name": "review", "about": "...", "instructions": "...", "reflexes": ["cite-sources"],
     "slots": [], "tools": [], "rules": [], "output_style": "", "delivery": "", "dispatch": ["subtask"]}
  ],
  "reflexes": [
    {"name": "cite-sources", "about": "...",
     "trigger_kind": "text", "trigger": {"pattern": "(?i)\\bsource\\b"},
     "action_kind": "remind", "action": {"body": "Name where each fact came from."},
     "cooldown_seconds": 60, "enabled": false}
  ]
}

presets and reflexes are steer.Preset and steer.Reflex (libs agent/steer v0.1.0), checked with Reflex.Validate against a vocabulary of steer's remind and halt plus Surface's run_command and call_tool, and Preset.Validate. Trigger kinds: text ({"pattern"}), predicate (a libs agent/core/reflexes predicate), event ({"topic"}), focus ({"view"}). Action kinds: remind ({"body"}) and halt ({"message"}, text and predicate triggers only) are steer's own; run_command ({"command"}) and call_tool ({"tool"}) are the kinds a Surface host registers. A preset may only name reflexes the file defines. Only the owner sets a mode; no tool does.

options.json (runtime options)

{"workbench_format": 1, "compact_at": 120000}

compact_at is agent.Options.CompactAt: the request size in tokens (system blocks, tools and conversation) at which Nanite compacts; 0 is 80% of the model's context window.

evals/.yaml

name: basics                 # the file's name
description: ...
mode: direct                 # direct (default) or subtask: the nanite/evals arm
cases:
  - id: reads-the-note
    turns:                   # the owner's messages; every one but the last on one line
      - "We are planning the launch."
      - "What does notes/launch.md say the launch date is?"
    fixtures:                # the workspace: path -> content
      notes/launch.md: "The launch moved from 2026-12-01 to 2026-12-08.\n"
    writes: false            # offer the file-writing tools
    script:                  # the stand-in model in an offline run (for the last turn)
      - calls: [{tool: read_file, args: {path: notes/launch.md}}]
      - say: "The launch moved a week.\nANSWER: 2026-12-08"
    graders:                 # one check each
      - contains: "2026-12-08"
      - not_contains: "2026-12-01"
      - regex: "(?m)^ANSWER: "
      - answer_line: "2026-12-08"            # the last "ANSWER:" line, Nanite's convention
      - json_path: {path: "$.status", equals: ok}   # the answer, or its first ```json block
      - json_path: {path: "$.error", exists: false} # absent; equals: null wants a JSON null
      - tool_called: {tool: read_file, args: {path: notes/launch.md}}  # args: a subset
      - no_tool_called: {}                   # or {tool: bash}
      - max_steps: 4
      - max_tokens: 20000                    # the task turn and its subtasks
      - file: {path: out.md, contains: "Reviewed"}  # the workspace after the run
      - rubric: "States the new date."       # model-graded; live runs only

Each case becomes a nanite/evals scenario: the agent's files (without .mcp.json: no MCP server is started in an eval), the fixtures, task.md (the last turn) and prelude.txt (the earlier turns). The case's graders are the scenario's Grade. Steps and tokens come from the turn's trace record (libs agent/trace v0.2.0: the turn's own usage plus subtasks[].usage); the tool calls and their arguments, and the transcript, from the model's replies. compact_at from options.json is passed as agent.Options.CompactAt.

Runs execute in process through nanite/evals.Run. Nanite sets agent.Options.WorkDir to each case’s private workspace; the server never changes its working directory. Cancellation interrupts the provider request and temporary workspaces are removed. One live run and two offline runs may run at a time. MCP servers are omitted; any future stdio MCP support must use absolute paths.

Offline (the default) plays each case's script: earlier turns are answered "Noted.", a subtask returns at once, no model is called and nothing is spent. Live runs only when the owner presses Run live and confirms (or a confirm-level tool call). The page shows the case count, the model, an estimate of the tokens and the caps first. The module declares Manifest.Gateway to be given the gateway (Host.Agent().Gateway). A live run sends every request through the app's gateway (model, gateway_url, key_file in the app's agent config; the key is read per request and never logged), with:

  • nanite/evals' dollar cap (eval_max_usd, default 10, at most 50; each request reserves its most expensive outcome at a conservative price before it is sent);
  • a per-case token cap (agent.Options.TurnTokenBudget = eval_turn_tokens);
  • a run token budget (eval_run_tokens): every request first reserves its most expensive outcome (its input and its whole output allowance), so requests running side by side cannot together pass it; a request that would is refused and the run is stopped.

Only the owner, at the page, can change anything through the routes: an agent's files, create, duplicate, delete, import (an archive or a directory), save or delete a suite, start a live run or re-run, cancel a run, ask for a proposal, accept or reject one, roll back. A request with no Origin (MCP, the HTTP tools, the CLI) is an outside client and is refused there; reads and offline runs stay open. Outside clients use the agent tools, where the owner is asked.

runs/.json

id, agent, suite, digest, version, mode (offline or live), model, started, finished, status (running, done, stopped, failed), stopped (why), spent_usd (an estimate; 0 offline), tokens, caps, passed, failed, previous (the run this one re-ran), and cases[]: id, pass, why, graders[] (kind, pass, skipped, detail), answer, transcript[] (sent, reply, calls, subtask, tokens), steps, tokens, cost_usd, wall_ms. Compare two runs case by case: fixed, broken, tokens and steps.

proposals/.json

From a live or offline run with failures, Propose (live: it calls a model, after the owner confirms) sends the failed cases (turns, graders, answer, the end of the transcript) and the agent's prompt, skills, variants, context and steering, with a fixed meta-prompt (proposals.go), and asks for JSON: {"proposals": [{"file", "diff", "rationale"}]} (or content for a new file). At most five edits; only the prompt, skills, variants, context and steering may be changed. Each edit is checked: the diff must apply strictly (each hunk's body has exactly the lines its header counts, at least one kept line unless the file is new, and it matches at its stated line or at exactly one place within 50 lines; one bad hunk refuses the whole edit) and the agent must still validate, or it is marked invalid. Stored as id, run, digest, model, tokens, items[] (n, file, diff, rationale, status: pending, accepted, rejected, invalid, stale; version once accepted). Accepting applies the edit to the agent as it is now (stale if it no longer applies) and saves a version over exactly the state it was applied to; one decision at a time per proposal, so an edit cannot be accepted twice. Re-run runs the suite again and compares.

workbench.json (the export manifest)

{"workbench_format": 1, "name": "...", "id": "...", "digest": "...", "agentdir_digest": "...",
 "created": "RFC 3339", "workbench_version": "0.1.0", "source": "template:embedded", "version": 3,
 "files": ["agent.md", "host.yaml", "..."], "suites": ["basics"]}

The archive holds the agent's files at its root (it unpacks into a directory Nanite opens as it is), workbench.json, and workbench/steering.json, workbench/options.json, workbench/evals/*.yaml. Import takes .tar.gz, .tgz or .zip and refuses absolute paths, .., links and special files, more than 1,000 entries, a file over 1 MiB, more than 24 MiB unpacked or 32 MiB uploaded; it skips (and lists) anything that is not part of an agent, and the files must validate. An imported agent gets a free id; a digest that differs from the manifest's is reported. Import from a directory (an absolute path) reads only its authored files and never changes it.

HTTP (under /api/m/workbench/)

GET templates · GET|POST agents · GET|DELETE agents/{id} · POST agents/{id}/duplicate · PUT agents/{id}/files ({changes: {path: text|null}, edits: [{file, set: {"runtime.max_steps": 30}, body}], base, note, dry_run}) · GET agents/{id}/versions/{n}/diff?to=current|m · POST agents/{id}/versions/{n}/rollback · GET agents/{id}/preview · GET agents/{id}/export · POST import (raw bytes, or {name, data: base64, id}) · POST import-dir ({path, id}) · GET|PUT agents/{id}/suites · DELETE agents/{id}/suites/{name} · GET agents/{id}/suites/{name}/estimate · POST agents/{id}/suites/{name}/run ({mode, confirm}; live needs confirm: true) · GET agents/{id}/runs[/{run}] · POST agents/{id}/runs/{run}/cancel|rerun|propose · GET agents/{id}/compare?a=&b= · GET agents/{id}/proposals · POST agents/{id}/proposals/{p}/{n}/accept|reject.

Agent tools

workbench_list, _get, _validate, _versions, _suites, _estimate, _runs, _run_get, _compare, _proposals (read); workbench_create, _write_file (the prompt, skills, variants, context, steering, options), _write_suite (write; the writes wait while the owner has unsaved changes to that agent and save over the state they read); workbench_write_config (host.yaml, .mcp.json, permissions.yaml, providers.yaml: what the agent may run and reach), workbench_import_dir (it reads from disk), workbench_run_eval and workbench_propose (confirm: asked every time). No tool accepts or rejects a proposal, rolls back, deletes or sets a mode: those are the owner's.

The Workbench's own profile: the Agent Architect

profile/ is the agent the app uses when the Workbench leads: the Agent Architect, an expert in setting up Nanite agents for Surface. It designs an agent or a module profile with the owner, builds it through the workbench_* tools, writes its evals, and reviews it against what worked in Surface Desk, Basalisk and Nanite.

It is a module profile: a Nanite agent directory without host.yaml or .mcp.json (the app owns the runtime, identity, MCP and permissions), with steering.json (agent/steer v0.1.0 presets and reflexes) and evals/ at its root. agent.md and context/ stand alone, for a runtime that loads only those. Skills, variants and steering add to it under the Nanite runner. TestProfileValidates checks it with the Workbench's validation and parses its suites. The app will select it once Surface core has module profiles. Until then it can be used as an agent directory: copy it with a host.yaml into the app's agent directory, or import it into the Workbench.

Known gaps

Nanite integration uses agent/providers for Anthropic and OpenAI gateways, agent/authored for variants and providers.yaml, and evals.Scenario.Stubs for canned host tools. Keys remain file references and resolve per request; resolved keys join the scope used by Workbench's error scrubber.

Cases can define stubs in the suite editor/API:

stubs:
  - name: lookup_note
    description: Read a fixture note.
    read_only: true
    schema: {type: object, properties: {id: {type: string}}}
    results:
      - when: {id: launch}
        text: "Launch is Tuesday."
      - text: "No matching note."
        is_error: true

Matching when answers take precedence. Other results are consumed in order, repeating the last; use argument matching for deterministic concurrent calls. Built-in names and mcp__ names are refused. Each case result includes stub_calls from Nanite.

Documentation

Overview

Package workbench is the Agent Workbench: a Surface module for making and improving Nanite agents. An agent is an agent directory (libs agent/agentdir: agent.md, host.yaml, .mcp.json, permissions.yaml, providers.yaml, skills/, context/, variants/) kept in a library, with the Workbench's own sidecar beside it: steering (reflexes, triggers, presets), host options, versions, eval suites, runs and improvement proposals.

The owner creates agents from templates or imports them (an archive, or a directory copied read-only), edits each part with validation on every save (agentdir.Load and Nanite's own rules), keeps every saved state as a version, exports an agent as an archive, runs eval suites through Nanite's eval harness against the app's model gateway (only when the owner starts a run, within a dollar cap and token budgets), asks a model for edits that would fix the failures, accepts or rejects each, and runs again to compare.

Everything Nanite-specific is behind Runtime (runtime.go). See README.md for the formats.

Index

Constants

View Source
const WorkbenchVersion = "0.1.0"

WorkbenchVersion is the Workbench's version, written into each export's manifest.

Variables

View Source
var (

	// ErrNotFound: no agent with that id.
	ErrNotFound = errors.New("workbench: no such agent")
	// ErrExists: an agent with that id is already in the library.
	ErrExists = errors.New("workbench: an agent with that id already exists")
)

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Meta
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Digest      string `json:"digest"`
	Version     int    `json:"version"`
	Updated     string `json:"updated"`
	OK          bool   `json:"ok"`
}

Agent is an agent as the library lists it.

type AgentView

type AgentView struct {
	Agent    Agent             `json:"agent"`
	Files    map[string]string `json:"files"`
	Report   Report            `json:"report"`
	Versions []Version         `json:"versions"`
	Dir      string            `json:"dir"`
}

AgentView is an agent as the editor loads it.

type Bundle

type Bundle struct {
	Tree     Tree
	Suites   map[string][]byte
	Manifest *Manifest
	// Skipped are entries that are not part of an agent (state, notes), left out.
	Skipped []string
}

Bundle is what an archive holds: the tree, the eval suites and the manifest.

type Caps

type Caps struct {
	MaxUSD     float64 `json:"max_usd"`
	TurnTokens int     `json:"turn_tokens"`
	RunTokens  int     `json:"run_tokens"`
}

Caps bound a run.

type Case

type Case struct {
	ID string `yaml:"id" json:"id"`
	// Turns are the owner's messages in order; the last is the task, the rest are sent first.
	// Every turn but the last must be one line (Nanite's prelude takes one message a line).
	Turns []string `yaml:"turns" json:"turns"`
	// Fixtures are workspace files the agent can read (path: content).
	Fixtures map[string]string `yaml:"fixtures,omitempty" json:"fixtures,omitempty"`
	// Writes offers the file-writing tools (the case changes the workspace).
	Writes bool   `yaml:"writes,omitempty" json:"writes,omitempty"`
	Stubs  []Stub `yaml:"stubs,omitempty" json:"stubs,omitempty"`
	// Script is what the stand-in model does in an offline run, step by step, for the last
	// turn (earlier turns are answered "Noted."). Without one, an offline run answers once
	// and stops. It is a harness check, not evidence about a model.
	Script  []ScriptStep `yaml:"script,omitempty" json:"script,omitempty"`
	Graders []Grader     `yaml:"graders" json:"graders"`
}

Case is one eval case.

type CaseCompare

type CaseCompare struct {
	ID      string `json:"id"`
	A       *bool  `json:"a,omitempty"`
	B       *bool  `json:"b,omitempty"`
	ATokens int    `json:"a_tokens"`
	BTokens int    `json:"b_tokens"`
	ASteps  int    `json:"a_steps"`
	BSteps  int    `json:"b_steps"`
	Change  string `json:"change"` // fixed, broken, same, new, gone
}

CaseCompare is one case in two runs.

type CaseOutput

type CaseOutput struct {
	StubCalls map[string]int
	ID        string
	Answer    string
	Graders   []GraderResult
	// Ran: the case reached grading. Why says why it did not, or why it failed.
	Ran     bool
	Why     string
	Skipped string
	Steps   int
	Tokens  int
	CostUSD float64
	WallMS  int64
}

CaseOutput is one case's run, before the rubric graders.

type CaseResult

type CaseResult struct {
	StubCalls  map[string]int `json:"stub_calls,omitempty"`
	ID         string         `json:"id"`
	Pass       bool           `json:"pass"`
	Why        string         `json:"why,omitempty"`
	Skipped    string         `json:"skipped,omitempty"`
	Graders    []GraderResult `json:"graders"`
	Answer     string         `json:"answer"`
	Transcript []Exchange     `json:"transcript"`
	Steps      int            `json:"steps"`
	Tokens     int            `json:"tokens"`
	CostUSD    float64        `json:"cost_usd"`
	WallMS     int64          `json:"wall_ms"`
}

CaseResult is one case's outcome.

type Comparison

type Comparison struct {
	A     RunInfo       `json:"a"`
	B     RunInfo       `json:"b"`
	Cases []CaseCompare `json:"cases"`
	// Fixed and Broken count cases that went from fail to pass, and from pass to fail.
	Fixed  int `json:"fixed"`
	Broken int `json:"broken"`
}

Comparison is two runs side by side, case by case.

type DiffLine

type DiffLine struct {
	Op   string `json:"op"`
	Text string `json:"text"`
}

DiffLine is one line of a diff: " " kept, "-" removed, "+" added.

type Edit

type Edit struct {
	N         int    `json:"n"`
	File      string `json:"file"`
	Diff      string `json:"diff"`
	Rationale string `json:"rationale"`
	// Status is pending, accepted, rejected, invalid (does not apply or validate) or stale
	// (the file changed since).
	Status  string `json:"status"`
	Problem string `json:"problem,omitempty"`
	// Version is the version an accepted edit was saved as.
	Version int `json:"version,omitempty"`
}

Edit is one proposed change to one file.

type ErrInvalid

type ErrInvalid struct{ Report Report }

ErrInvalid is a save refused because the files do not validate; the report says why.

func (*ErrInvalid) Error

func (e *ErrInvalid) Error() string

type Estimate

type Estimate struct {
	Agent  string `json:"agent"`
	Suite  string `json:"suite"`
	Cases  int    `json:"cases"`
	Model  string `json:"model"`
	Digest string `json:"digest"`
	// PromptTokens is the assembled first request (system prompt and tools), estimated.
	PromptTokens int `json:"prompt_tokens"`
	// Tokens is the estimate for the whole run: per case, three model requests carrying the
	// prompt, the case's turns and fixtures, and an output allowance each. Rubric graders
	// add one request each.
	Tokens int `json:"tokens"`
	// Caps are the bounds a run starts with (the settings, unless the request names lower).
	Caps Caps `json:"caps"`
	// WorstUSD is the estimate priced at nanite/evals' conservative price, and never more
	// than the dollar cap: what the run is expected to cost at most.
	WorstUSD float64 `json:"worst_usd"`
	Gateway  string  `json:"gateway"`
	Ready    bool    `json:"ready"`
	NotReady string  `json:"not_ready,omitempty"`
}

Estimate is what a run would cost, worked out before it is started.

type Exchange

type Exchange struct {
	// Sent is what the model was last given: the owner's turn, or the tool results.
	Sent string `json:"sent"`
	// Reply is the model's text; Calls its tool calls.
	Reply string    `json:"reply,omitempty"`
	Calls []ToolUse `json:"calls,omitempty"`
	// Subtask marks a request of a subtask's conversation.
	Subtask bool `json:"subtask,omitempty"`
	Tokens  int  `json:"tokens"`
}

Exchange is one model request's last message and the reply.

type FileCheck

type FileCheck struct {
	Path     string `yaml:"path" json:"path"`
	Contains string `yaml:"contains,omitempty" json:"contains,omitempty"`
}

FileCheck is a workspace file that must exist and contain a text.

type FileDiff

type FileDiff struct {
	File   string     `json:"file"`
	Change string     `json:"change"` // added, removed, changed
	Lines  []DiffLine `json:"lines"`
}

FileDiff is one file's change between two states.

type Grader

type Grader struct {
	// Contains and NotContains look for text in the final answer (case-insensitive).
	Contains    string `yaml:"contains,omitempty" json:"contains,omitempty"`
	NotContains string `yaml:"not_contains,omitempty" json:"not_contains,omitempty"`
	// Regex matches the final answer (Go syntax; (?i) for case-insensitive).
	Regex string `yaml:"regex,omitempty" json:"regex,omitempty"`
	// AnswerLine checks the answer's last "ANSWER:" line contains this (Nanite evals'
	// convention), case-insensitive.
	AnswerLine string `yaml:"answer_line,omitempty" json:"answer_line,omitempty"`
	// JSONPath reads the answer as JSON (or its first “`json block) and checks a value.
	JSONPath *JSONCheck `yaml:"json_path,omitempty" json:"json_path,omitempty"`
	// ToolCalled passes when the agent called the tool, with at least these arguments.
	ToolCalled *ToolCheck `yaml:"tool_called,omitempty" json:"tool_called,omitempty"`
	// NoToolCalled passes when no tool was called ({}), or not this one ({tool: bash}).
	NoToolCalled *ToolCheck `yaml:"no_tool_called,omitempty" json:"no_tool_called,omitempty"`
	// MaxSteps and MaxTokens bound the task turn: model steps, and tokens across the turn
	// and its subtasks.
	MaxSteps  int `yaml:"max_steps,omitempty" json:"max_steps,omitempty"`
	MaxTokens int `yaml:"max_tokens,omitempty" json:"max_tokens,omitempty"`
	// File checks a workspace file after the run.
	File *FileCheck `yaml:"file,omitempty" json:"file,omitempty"`
	// Rubric is graded by a model: it is told the rubric, the task and the answer and
	// answers PASS or FAIL. It costs a model call and counts against the run's budget.
	Rubric string `yaml:"rubric,omitempty" json:"rubric,omitempty"`
}

Grader is one check of a case's outcome. Exactly one field is set.

func (Grader) Kind

func (g Grader) Kind() string

Kind names the grader's check.

type GraderResult

type GraderResult struct {
	Kind string `json:"kind"`
	Pass bool   `json:"pass"`
	// Skipped: not graded (a rubric in an offline run); it does not count either way.
	Skipped bool   `json:"skipped,omitempty"`
	Detail  string `json:"detail,omitempty"`
}

GraderResult is one grader's verdict.

type JSONCheck

type JSONCheck struct {
	Path   string `yaml:"path" json:"path"`
	Equals any    `yaml:"equals,omitempty" json:"equals,omitempty"`
	Exists *bool  `yaml:"exists,omitempty" json:"exists,omitempty"`
	// HasEquals records that equals was given, so that equals: null is a check for null.
	HasEquals bool `yaml:"-" json:"has_equals,omitempty"`
}

JSONCheck is a value at a path in the answer read as JSON: "$.a.b[0]" or "a.b.0". equals compares the value (equals: null wants a JSON null); exists: false wants the path absent; with neither, the path must exist.

func (*JSONCheck) UnmarshalYAML

func (c *JSONCheck) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads a JSONCheck strictly and notes whether equals was given.

type Library

type Library struct {
	// contains filtered or unexported fields
}

Library keeps agents under a root directory.

func NewLibrary

func NewLibrary(root func() string) *Library

NewLibrary returns a library whose root is read from root at each use (a live setting).

func (*Library) AgentDir

func (l *Library) AgentDir(id string) (string, error)

AgentDir is the agent directory of id, as a host would open it.

func (*Library) Create

func (l *Library) Create(id string, t Tree, meta Meta, note, author string) (Agent, Report, error)

Create adds a new agent with the given files, which must validate. It records version 1.

func (*Library) Delete

func (l *Library) Delete(id string) (string, error)

Delete moves an agent to the library's trash; nothing is removed.

func (*Library) FreeID

func (l *Library) FreeID(want string) (string, error)

FreeID returns want, or want-2, want-3, ... whichever is not taken.

func (*Library) Get

func (l *Library) Get(id string) (Agent, error)

Get returns one agent's listing.

func (*Library) List

func (l *Library) List() ([]Agent, error)

List returns every agent, by id.

func (*Library) Recover

func (l *Library) Recover() error

Recover puts the library right after a crash: an agent directory left aside by an older Workbench's directory swap is put back, and temporary files of an interrupted write are removed. Only the library's own leftovers are touched.

func (*Library) Rollback

func (l *Library) Rollback(id string, n int, author string) (Version, Report, error)

Rollback saves version n's files as a new version.

func (*Library) Root

func (l *Library) Root() (string, error)

Root is the library's directory, created when missing.

func (*Library) Save

func (l *Library) Save(id string, t Tree, base, note, author string) (Version, Report, error)

Save replaces an agent's authored files with t when t validates, keeping every saved state in its versions. Only authored files are written or removed. base, when not empty, is the digest the caller edited from; a save over a newer state is refused.

func (*Library) Sidecar

func (l *Library) Sidecar(id string) (string, error)

Sidecar is the Workbench's directory for id.

func (*Library) Tree

func (l *Library) Tree(id string) (Tree, error)

Tree reads id's authored and sidecar files.

func (*Library) VersionTree

func (l *Library) VersionTree(id string, n int) (Tree, error)

VersionTree reads the files of version n.

func (*Library) Versions

func (l *Library) Versions(id string) ([]Version, error)

Versions lists id's versions, oldest first.

type Manifest

type Manifest struct {
	Format           int      `json:"workbench_format"`
	Name             string   `json:"name"`
	ID               string   `json:"id"`
	Digest           string   `json:"digest"`
	AgentdirDigest   string   `json:"agentdir_digest,omitempty"`
	Created          string   `json:"created"`
	WorkbenchVersion string   `json:"workbench_version"`
	Source           string   `json:"source,omitempty"`
	Version          int      `json:"version,omitempty"`
	Files            []string `json:"files"`
	Suites           []string `json:"suites,omitempty"`
}

Manifest is workbench.json.

type Meta

type Meta struct {
	ID       string `json:"id"`
	Created  string `json:"created"`
	Source   string `json:"source"` // template:<name>, import:<archive>, dir:<path>, duplicate:<id>
	Template string `json:"template,omitempty"`
}

Meta is what the library keeps about an agent besides its files.

type Options

type Options struct {
	Format int `json:"workbench_format"`
	// CompactAt is agent.Options.CompactAt: the request size in tokens (system blocks, tools
	// and conversation) at which the conversation is compacted. 0: 80% of the model's
	// context window.
	CompactAt int `json:"compact_at,omitempty"`
}

Options are runtime options: settings Nanite takes only in code (agent.Options), with no agent-directory file yet. The Workbench keeps them in its sidecar (workbench/options.json) and passes them when it runs the agent (eval runs); a host that opens the agent would pass them the same way. Of them, only CompactAt is exposed: slot budgets and placement are the engine's own.

type Outcome

type Outcome struct {
	Answer    string
	Workspace string // the run's copy of the workspace
	Calls     []ToolUse
	Steps     int
	Tokens    int
	// ReadFile reads a workspace file; nil reads from Workspace.
	ReadFile func(rel string) ([]byte, error)
}

Outcome is what a case's graders look at.

type Preview

type Preview struct {
	System string        `json:"system,omitempty"`
	Slots  []PreviewSlot `json:"slots"`
	Tools  []string      `json:"tools"`
	Tokens int           `json:"tokens"`
}

Preview is an agent's assembled first request.

type PreviewSlot

type PreviewSlot struct {
	Name     string `json:"name"`
	Content  string `json:"content"`
	Tokens   int    `json:"tokens"`
	ReadOnly bool   `json:"read_only"` // engine-owned (the base prompt): shown, not edited
}

PreviewSlot is one block of the system prompt.

type Problem

type Problem struct {
	File     string `json:"file,omitempty"`
	Message  string `json:"message"`
	Severity string `json:"severity"` // error or warning
}

Problem is one thing wrong (or worth knowing) about an agent's files.

type Proposal

type Proposal struct {
	ID      string `json:"id"`
	Agent   string `json:"agent"`
	Run     string `json:"run"`
	Digest  string `json:"digest"`
	Created string `json:"created"`
	Model   string `json:"model"`
	Tokens  int    `json:"tokens"`
	// Error is set when the model's reply could not be read.
	Error string `json:"error,omitempty"`
	Items []Edit `json:"items"`
}

Proposal is one improvement request's outcome: a set of edits for the owner to review.

type ProposeEstimate

type ProposeEstimate struct {
	Model       string  `json:"model"`
	InputTokens int     `json:"input_tokens"`
	MaxOutput   int     `json:"max_output"`
	WorstUSD    float64 `json:"worst_usd"`
	CapUSD      float64 `json:"cap_usd"`
	Failed      int     `json:"failed"`
}

ProposeEstimate is what a proposal would cost, worked out before the owner agrees.

type Report

type Report struct {
	OK bool `json:"ok"`
	// Digest is the Workbench's digest of every authored and sidecar file (Tree.Digest);
	// AgentdirDigest is agentdir.Load's, over the files agentdir reads.
	Digest         string    `json:"digest"`
	AgentdirDigest string    `json:"agentdir_digest,omitempty"`
	Problems       []Problem `json:"problems"`
	// Summary is what the files define, for the page.
	Summary *Summary `json:"summary,omitempty"`
}

Report is the outcome of validating an agent.

func Validate

func Validate(t Tree) Report

Validate checks a tree as Nanite will read it: agentdir.Load over the directory, then the files agentdir does not read (variants/*.md and providers.yaml, as Nanite parses them), the limits Nanite enforces when the agent opens, the sidecar files, and literal secrets where only references belong.

type Run

type Run struct {
	ID       string `json:"id"`
	Agent    string `json:"agent"`
	Suite    string `json:"suite"`
	Digest   string `json:"digest"`
	Version  int    `json:"version"`
	Model    string `json:"model"`
	Started  string `json:"started"`
	Finished string `json:"finished,omitempty"`
	// Status is running, done, stopped (a cap or the budget ended it) or failed.
	Status   string       `json:"status"`
	Stopped  string       `json:"stopped,omitempty"`
	SpentUSD float64      `json:"spent_usd"`
	Tokens   int          `json:"tokens"`
	Caps     Caps         `json:"caps"`
	Passed   int          `json:"passed"`
	Failed   int          `json:"failed"`
	Cases    []CaseResult `json:"cases"`
	// Previous is the run this one re-ran, for the comparison.
	Previous string `json:"previous,omitempty"`
	// Mode is offline (each case's script stands in for the model: a harness check, no
	// model is called, nothing is spent) or live (the app's gateway; costs money).
	Mode string `json:"mode"`
}

Run is one eval run, as stored in runs/<id>.json.

type RunInfo

type RunInfo struct {
	ID       string  `json:"id"`
	Mode     string  `json:"mode"`
	Suite    string  `json:"suite"`
	Digest   string  `json:"digest"`
	Version  int     `json:"version"`
	Status   string  `json:"status"`
	Started  string  `json:"started"`
	Passed   int     `json:"passed"`
	Failed   int     `json:"failed"`
	Tokens   int     `json:"tokens"`
	SpentUSD float64 `json:"spent_usd"`
	Stopped  string  `json:"stopped,omitempty"`
	Previous string  `json:"previous,omitempty"`
}

RunInfo is a run as listed (no transcripts).

type RunOutput

type RunOutput struct {
	Model    string
	SpentUSD float64
	// Stopped says why the run ended early, if it did.
	Stopped string
	Cases   []CaseOutput
}

RunOutput is what a suite run produced.

type RunSpec

type RunSpec struct {
	Tree  Tree
	Suite Suite
	// Model is written into the run's host.yaml for every case.
	Model string
	// Provider makes the model provider for one case. Every request of the case, its
	// subtasks' included, goes through it.
	Provider func(caseID string) llmcontracts.Provider
	// MaxUSD caps the whole run's estimated spend (nanite/evals' dollar cap, priced at its
	// conservative price). Required: a run is never uncapped.
	MaxUSD float64
	// TurnTokens caps one case's task turn, its subtasks included.
	TurnTokens int
	// Timeout bounds one case.
	Timeout time.Duration
	// Progress, when set, is told each case's id once it is graded.
	Progress func(caseID string)
}

RunSpec says what to run and within what bounds.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner keeps suites and runs for the library's agents.

func (*Runner) Cancel

func (x *Runner) Cancel(runID string) bool

Cancel stops a run in progress.

func (*Runner) Compare

func (x *Runner) Compare(agent, a, b string) (Comparison, error)

Compare compares two runs of an agent.

func (*Runner) Decide

func (x *Runner) Decide(agent, propID string, n int, accept bool) (Proposal, error)

Decide accepts or rejects one edit of a proposal. Accepting applies it to the agent as it is now and saves a new version. Only the owner decides: this is not an agent tool.

func (*Runner) DeleteSuite

func (x *Runner) DeleteSuite(id, name string) error

DeleteSuite removes a suite.

func (*Runner) Estimate

func (x *Runner) Estimate(ctx context.Context, id, suiteName string, want Caps) (Estimate, error)

Estimate works out a run's size and bounds without calling a model.

func (*Runner) EstimatePropose

func (x *Runner) EstimatePropose(ctx context.Context, agent, runID string) (ProposeEstimate, error)

EstimatePropose works out a proposal's size and worst cost without calling a model.

func (*Runner) GetProposal

func (x *Runner) GetProposal(agent, id string) (Proposal, error)

GetProposal reads a proposal.

func (*Runner) GetRun

func (x *Runner) GetRun(agent, runID string) (Run, error)

GetRun reads a run.

func (*Runner) Proposals

func (x *Runner) Proposals(agent string) ([]Proposal, error)

Proposals lists an agent's proposals, newest first.

func (*Runner) Propose

func (x *Runner) Propose(ctx context.Context, agent, runID string) (Proposal, error)

Propose asks the model for edits that would fix a run's failures. It is a model call: the owner's action only (the page, or a confirm-level tool).

func (*Runner) Runs

func (x *Runner) Runs(agent string) ([]RunInfo, error)

Runs lists an agent's runs, newest first.

func (*Runner) SaveSuite

func (x *Runner) SaveSuite(id string, raw []byte) (Suite, error)

SaveSuite writes a suite after checking it; its file name is its name.

func (*Runner) Start

func (x *Runner) Start(ctx context.Context, agent, suiteName, mode string, want Caps, previous string) (Run, error)

Start begins a run and returns it while it runs; it is saved as it goes and when done. The caller has already asked the owner: the page's Run button, or a confirm-level tool.

mode is "offline" (the default: no model is called) or "live".

func (*Runner) Suites

func (x *Runner) Suites(id string) ([]SuiteInfo, error)

Suites lists an agent's suites, parsed; a suite that does not parse is listed with its error.

func (*Runner) Wait

func (x *Runner) Wait()

Wait waits for every run in progress.

type Runtime

type Runtime interface {
	// RunSuite runs a suite's cases against an agent's files, through the model the spec
	// names, within its caps, and returns each case's outcome for grading.
	RunSuite(ctx context.Context, spec RunSpec) (RunOutput, error)
	// Preview assembles the agent's first request without calling a model: the system
	// prompt slot by slot (Nanite's base prompt included) and the tools offered.
	Preview(ctx context.Context, t Tree) (Preview, error)
}

Runtime is what the Workbench needs from the agent runtime.

type ScanFinding

type ScanFinding struct {
	File   string `json:"file"`
	Line   int    `json:"line"`
	What   string `json:"what"`
	Refuse bool   `json:"refuse"` // a high-confidence shape: an export is refused
}

ScanFinding is a credential-like text in one of the agent's files.

type ScriptStep

type ScriptStep struct {
	Say   string      `yaml:"say,omitempty" json:"say,omitempty"`
	Calls []ToolCheck `yaml:"calls,omitempty" json:"calls,omitempty"`
}

ScriptStep is one stand-in model response: tool calls, or a final answer.

type Steering

type Steering struct {
	// Format is the sidecar format's version.
	Format   int            `json:"workbench_format"`
	Presets  []steer.Preset `json:"presets,omitempty"`
	Reflexes []steer.Reflex `json:"reflexes,omitempty"`
}

Steering is Workbench's sidecar configuration, applied through Nanite's agent.Options.Steering in eval runs.

func (Steering) Validate

func (s Steering) Validate() error

Validate checks every reflex and preset with steer's own validation, that names are not repeated, and that presets name reflexes the file defines.

type Stub

type Stub struct {
	Name        string         `yaml:"name" json:"name"`
	Description string         `yaml:"description" json:"description"`
	Schema      map[string]any `yaml:"schema,omitempty" json:"schema,omitempty"`
	ReadOnly    bool           `yaml:"read_only,omitempty" json:"read_only,omitempty"`
	Results     []StubResult   `yaml:"results" json:"results"`
}

Stub is the YAML/JSON editing form of a Nanite eval stub. Schema is an object so YAML authors need not encode a JSON string inside their suite.

type StubResult

type StubResult struct {
	When    map[string]any `yaml:"when,omitempty" json:"when,omitempty"`
	Text    string         `yaml:"text" json:"text"`
	IsError bool           `yaml:"is_error,omitempty" json:"is_error,omitempty"`
}

type Suite

type Suite struct {
	Name        string `yaml:"name" json:"name"`
	Description string `yaml:"description,omitempty" json:"description,omitempty"`
	// Mode is the Nanite evals arm the cases run in: direct (the default; the agent does the
	// work itself) or subtask (the subtask tool is offered too).
	Mode  string `yaml:"mode,omitempty" json:"mode,omitempty"`
	Cases []Case `yaml:"cases" json:"cases"`
}

Suite is one eval suite: workbench/evals/<name>.yaml in the agent's sidecar, outside the agent directory. Each case becomes a Nanite eval scenario (nanite/evals): the agent's directory, the case's fixtures as the workspace, its last turn as task.md and its earlier turns as prelude.txt. Its graders become the scenario's Grade.

func ParseSuite

func ParseSuite(raw []byte) (Suite, error)

ParseSuite reads a suite strictly and checks it.

func (Suite) Validate

func (s Suite) Validate() error

Validate checks a suite.

type SuiteInfo

type SuiteInfo struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Cases       int    `json:"cases"`
	Error       string `json:"error,omitempty"`
	Source      string `json:"source"`
}

SuiteInfo is a suite as listed.

type Summary

type Summary struct {
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Kind        string   `json:"kind"`
	Model       string   `json:"model,omitempty"`
	Skills      []string `json:"skills"`
	Context     []string `json:"context"`
	Variants    []string `json:"variants"`
	MCPServers  []string `json:"mcp_servers"`
	Providers   []string `json:"providers"`
	Reflexes    int      `json:"reflexes"`
	Presets     int      `json:"presets"`
}

Summary is what a valid agent defines.

type Template

type Template struct {
	Name  string `json:"name"`
	About string `json:"about"`
}

Template describes a starter.

func Templates

func Templates() []Template

Templates lists the starters.

type ToolCheck

type ToolCheck struct {
	Tool string         `yaml:"tool,omitempty" json:"tool,omitempty"`
	Args map[string]any `yaml:"args,omitempty" json:"args,omitempty"`
}

ToolCheck names a tool and, optionally, arguments its call must include.

type ToolUse

type ToolUse struct {
	Name  string         `json:"name"`
	Input map[string]any `json:"input,omitempty"`
}

ToolUse is one tool call the model made.

type Tree

type Tree map[string][]byte

Tree is an agent's authored files by relative path, sidecar files included.

func (Tree) Clone

func (t Tree) Clone() Tree

Clone copies the tree.

func (Tree) Digest

func (t Tree) Digest() string

Digest is a SHA-256 over every file in path order, length-prefixed like agentdir's own digest so that no two trees share one by concatenation. It covers what agentdir's digest leaves out (variants/, providers.yaml, skill resources) and the sidecar files.

func (Tree) Paths

func (t Tree) Paths() []string

Paths are the tree's paths, sorted.

type Version

type Version struct {
	N              int    `json:"n"`
	Digest         string `json:"digest"`
	AgentdirDigest string `json:"agentdir_digest,omitempty"`
	Note           string `json:"note"`
	Author         string `json:"author"`
	Created        string `json:"created"`
	Files          int    `json:"files"`
}

Version is one saved state of an agent.

Jump to

Keyboard shortcuts

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