Documentation
¶
Overview ¶
Package agenteval checks that harnessly by itself makes an agent behave (docs/agent-evals.md): a scenario is data, a run happens in a disposable stand, and the run is judged by what it left (tool calls, the right pane's intents, pictures, files), not by the wording of its answer.
Index ¶
- Constants
- Variables
- func Change(k0, n0, k1, n1 int, noise float64) string
- func FakeImagegen(args []string, stdout io.Writer) error
- func MatchPath(glob, p string) bool
- func PassHatK(c, n, k int) float64
- func Passed(v []Verdict) bool
- func ReadSurface(file string) ([]string, error)
- func SandboxAvailable() int
- func SandboxExec(rw, ro, argv []string) error
- func Wilson(k, n int) (lo, hi float64)
- type Call
- type Cell
- type CellStat
- type CheckResult
- type Expect
- type Facts
- type FileExpect
- type FileFact
- type ImageJob
- type Impact
- type Interrupt
- type MadeExpect
- type MadeFact
- type Metrics
- type Model
- type Options
- type PaneExpect
- type PaneIntent
- type Report
- type Result
- type Scenario
- type Setup
- type SetupFile
- type Stand
- func (s *Stand) Chat(agent, model, prompt string) (string, error)
- func (s *Stand) ChatWithEffort(agent, model, effort, prompt string) (string, error)
- func (s *Stand) Collect(agent, tab, keep string) (Facts, error)
- func (s *Stand) Down()
- func (s *Stand) Exec(ctx context.Context, script string, extra []string, timeout time.Duration) (int, string)
- func (s *Stand) Send(tab, text string) error
- func (s *Stand) Settle(ctx context.Context, tab string, quiet time.Duration, deadline time.Time) (time.Time, bool)
- func (s *Stand) Wait(ctx context.Context, tab string, timeout time.Duration) string
- type StandConfig
- type Usage
- type Variant
- type Verdict
Constants ¶
const ( Pass = "pass" Fail = "fail" Infra = "infra" )
States of a run.
const ( SetDev = "dev" SetHeldOut = "heldout" )
const MinEffect = 0.10
MinEffect is the smallest change of a pass rate that is reported as a change, whatever the intervals say.
Variables ¶
var ErrInfra = errors.New("infrastructure")
ErrInfra marks a failure of the stand, not of the agent: such a run is retried and never counted.
Functions ¶
func Change ¶
Change labels a cell against the same cell of an earlier run: "better", "worse", "same" (within noise) or "new". A change counts when the two Wilson intervals do not overlap and the rates differ by at least MinEffect and by the noise threshold measured for the setup (0 when none was measured).
func FakeImagegen ¶
FakeImagegen stands in for `codex exec` when a stand's runtime draws a picture (RUNTIME_IMAGEGEN_BIN): it answers the events the picture service reads and leaves blank pictures where Codex leaves real ones, so an eval checks that the agent asked for a picture and the chat got it, without paying for a drawing.
func MatchPath ¶
MatchPath says whether a repository path matches a glob: path.Match per segment, "**" for any number of segments, and a leading "!" is not handled here (see Affected).
func PassHatK ¶
PassHatK is the unbiased estimate of pass^k (all of k fresh runs pass) from c passes in n runs: C(c,k)/C(n,k).
func ReadSurface ¶
ReadSurface reads the surface file: globs, # comments, blank lines skipped.
func SandboxAvailable ¶
func SandboxAvailable() int
SandboxAvailable says whether Landlock confines a stand here (its ABI version; 0 for none).
func SandboxExec ¶
SandboxExec confines this process (rw: read and write beneath; ro: read and run beneath) and becomes argv.
Types ¶
type Call ¶
type Call struct {
// Session is which transcript the call is in: 0 the person's chat, then the other sessions in the order read.
Session int `json:"session,omitempty"`
Name string `json:"name"`
// At is when the call was made, as the transcript stamps it.
At string `json:"at,omitempty"`
Args json.RawMessage `json:"args,omitempty"`
Error bool `json:"error,omitempty"`
Result string `json:"result,omitempty"`
}
Call is one tool call of the agent or of its subagents.
type CellStat ¶
type CellStat struct {
Scenario string `json:"scenario"`
Set string `json:"set"`
Model string `json:"model"`
Pass int `json:"pass"`
Runs int `json:"runs"`
Infra int `json:"infra"`
Lo float64 `json:"lo"`
Hi float64 `json:"hi"`
PassHat3 float64 `json:"passHat3,omitempty"`
USD float64 `json:"usd"`
CostUnknown bool `json:"costUnknown,omitempty"`
// The medians of the judged runs: work time (s), tokens, dollars; their spread is (max − min) / median.
ActiveS float64 `json:"activeS,omitempty"`
ActiveSpread float64 `json:"activeSpread,omitempty"`
Tokens float64 `json:"tokens,omitempty"`
TokenSpread float64 `json:"tokenSpread,omitempty"`
USDMedian float64 `json:"usdMedian,omitempty"`
// The means of the judged runs: helpers, conflicting and duplicate edits, the person needed, edits of the lead.
Sessions float64 `json:"sessions,omitempty"`
Subagents float64 `json:"subagents,omitempty"`
Delegations float64 `json:"delegations,omitempty"`
Teammates float64 `json:"teammates,omitempty"`
Conflicts float64 `json:"conflicts,omitempty"`
Duplicates float64 `json:"duplicates,omitempty"`
Asks float64 `json:"asks,omitempty"`
BlindAsks float64 `json:"blindAsks,omitempty"`
Steps float64 `json:"steps,omitempty"`
LeadEdits float64 `json:"leadEdits,omitempty"`
Repl float64 `json:"repl,omitempty"`
Messages float64 `json:"messages,omitempty"`
// Timeouts are the judged runs that did not finish in time.
Timeouts int `json:"timeouts,omitempty"`
// Change is against the same cell of the earlier run: better, worse, same, new.
Change string `json:"change,omitempty"`
Before string `json:"before,omitempty"`
}
CellStat is one scenario × model of a report.
type CheckResult ¶
type CheckResult struct {
Command string `json:"command"`
Exit int `json:"exit"`
Output string `json:"output,omitempty"`
}
CheckResult is one check command's outcome.
type Expect ¶
type Expect struct {
Name string `yaml:"name" json:"name,omitempty"`
// Called: a call that did not fail, of a tool whose name matches (whole), with arguments matching Args.
Called string `yaml:"called" json:"called,omitempty"`
// EvenFailed makes Called count a call that failed too: a question to the person times out in a run nobody
// answers, and what is judged is that the agent asked. With NotCalled it forbids the attempt: a question that timed
// out still asked the person.
EvenFailed bool `yaml:"even_failed" json:"evenFailed,omitempty"`
// NotCalled: no call of a matching tool with matching Args ran (a refused or failed call does not count, unless
// EvenFailed).
NotCalled string `yaml:"not_called" json:"notCalled,omitempty"`
// Args are regexps over the call's arguments: argument name → regexp over its value (a string as it is, other JSON
// as its text).
Args map[string]string `yaml:"args" json:"args,omitempty"`
// Pane: the agent asked the right pane to open a tab of a kind matching Tab, at a target matching Target.
Pane *PaneExpect `yaml:"pane" json:"pane,omitempty"`
// Made: the runtime lists a matching thing as made by the person's chat (or, with Absent, none).
Made *MadeExpect `yaml:"made" json:"made,omitempty"`
// Images: at least this many pictures were drawn for the chat.
Images int `yaml:"images" json:"images,omitempty"`
// File: a file of the workspace or the design library.
File *FileExpect `yaml:"file" json:"file,omitempty"`
// Text and TextNot are regexps over everything the agent said to the person.
Text string `yaml:"text" json:"text,omitempty"`
TextNot string `yaml:"text_not" json:"textNot,omitempty"`
// AnyOf holds when one of its expectations does.
AnyOf []Expect `yaml:"any_of" json:"anyOf,omitempty"`
// MaxCalls bounds the agent's tool calls.
MaxCalls int `yaml:"max_calls" json:"maxCalls,omitempty"`
// Check is a shell command run in the workspace after the run, inside the stand's sandbox: it holds when it exits 0.
// It sees EVAL_STARTED_AT and EVAL_INTERRUPT_AT (Unix seconds; empty without an interrupt).
Check string `yaml:"check" json:"check,omitempty"`
}
Expect is one expectation; exactly one of its kinds is set.
type Facts ¶
type Facts struct {
Calls []Call `json:"calls"`
// Said is everything the agent wrote to the person, in order; Final is its last message.
Said []string `json:"said"`
Final string `json:"final"`
// Pane are the right pane's intents the chat left.
Pane []PaneIntent `json:"pane"`
// Made is what the runtime lists as made by the person's chat with its subagents and delegated chats (GET
// …/made): what the chat's «Сделано за ход» and «Документы» are drawn from. MadeError says why it was not read.
Made []MadeFact `json:"made,omitempty"`
MadeError string `json:"madeError,omitempty"`
// Images are the picture jobs of the chat.
Images []ImageJob `json:"images"`
// Files are the workspace's files ("design:" before the design library's), with the text of the small ones.
Files []FileFact `json:"files"`
// Model is what the agent ran on, as the transcript says.
Model string `json:"model,omitempty"`
TokensIn int `json:"tokensIn"`
CacheRead int `json:"cacheRead"`
CacheWrite int `json:"cacheWrite"`
TokensOut int `json:"tokensOut"`
// APIErrors are the provider's errors the transcript recorded (overload, auth): an infrastructure failure.
APIErrors []string `json:"apiErrors,omitempty"`
// Sessions are the agent sessions the run left besides the person's chat: subagents, chats it delegated to,
// teammates. Their calls are in Calls (Session > 0), their tokens in the totals.
Sessions int `json:"sessions,omitempty"`
// LeadTokens are the tokens of the person's chat alone (input, cache, output).
LeadTokens int `json:"leadTokens,omitempty"`
// ByModel are the tokens of each model the sessions ran on.
ByModel map[string]Usage `json:"byModel,omitempty"`
// Checks are the scenario's check commands as they ran in the workspace after the run.
Checks []CheckResult `json:"checks,omitempty"`
}
Facts are what a run left, read after the agent's turn. They are saved with the run, so a run is judged again without running it.
func ReadClaudeTranscript ¶
ReadClaudeTranscript reads a Claude Code session file (and its subagents' files): the calls with their results, what was said, tokens and the provider's errors. Kinds it does not know are skipped: the format grows.
func ReadCodexRollout ¶
ReadCodexRollout reads a Codex session file (~/.codex/sessions/…/rollout-*.jsonl): the function calls with their outputs and what the agent said. Tool names are made the scenario's: an MCP tool is "<server>.<tool>", a shell call is "Bash" with its command, as a Claude transcript has them, so one scenario judges both agents.
type FileExpect ¶
type FileExpect struct {
// Glob is relative to the workspace, or to the design library with the prefix "design:".
Glob string `yaml:"glob" json:"glob"`
Contains string `yaml:"contains" json:"contains,omitempty"`
Absent bool `yaml:"absent" json:"absent,omitempty"`
}
FileExpect is a file that must (or must not) be there.
type FileFact ¶
type FileFact struct {
Path string `json:"path"`
Size int64 `json:"size"`
Text string `json:"text,omitempty"`
}
FileFact is a file the run left.
type ImageJob ¶
type ImageJob struct {
Prompt string `json:"prompt"`
State string `json:"state"`
Images int `json:"images"`
Error string `json:"error,omitempty"`
}
ImageJob is a picture job of the chat.
func ReadImageJobs ¶
ReadImageJobs reads the runtime's picture jobs of one chat (<data>/images/<job>/job.json).
type Impact ¶
type Impact struct {
// Surface are the changed files of the surface.
Surface []string `json:"surface"`
// Scenarios are the scenarios whose covers a changed file matches.
Scenarios []string `json:"scenarios"`
// ScenarioFiles are the changed files of the scenarios' folder.
ScenarioFiles []string `json:"scenarioFiles"`
}
Impact is what a change does to the agent's surface.
func Affected ¶
Affected reads a change (repository paths) against the surface and the scenarios; dir is the scenarios' folder as a repository path (evals/agent).
func (Impact) NeedsScenario ¶
NeedsScenario: the surface changed and no scenario was added or changed with it.
type Interrupt ¶
type Interrupt struct {
AfterS int `yaml:"after_s" json:"afterS"`
Text string `yaml:"text" json:"text"`
}
Interrupt is a message sent into the person's chat after AfterS seconds, while its turn is still going.
type MadeExpect ¶
type MadeExpect struct {
Kind string `yaml:"kind" json:"kind"`
Ref string `yaml:"ref" json:"ref,omitempty"`
From string `yaml:"from" json:"from,omitempty"`
Absent bool `yaml:"absent" json:"absent,omitempty"`
}
MadeExpect is a thing the person's chat must (or must not) list as made, by regexps: Kind over its kind (doc, board, design, task, mr, stand, commit, file; whole), Ref over its address or id, From over who made it ("" the chat itself, subagent, subchat; whole).
type MadeFact ¶
type MadeFact struct {
Kind string `json:"kind"`
Ref string `json:"ref"`
Title string `json:"title,omitempty"`
Op string `json:"op,omitempty"`
From string `json:"from,omitempty"`
}
MadeFact is one thing the runtime lists as made by the person's chat. From is who made it: "" for the chat itself, "subagent" or "subchat" (a delegated chat, at any depth).
type Metrics ¶
type Metrics struct {
// Tokens are all tokens of every session: input, cache read and written, output.
Tokens int `json:"tokens"`
// Sessions are the agent sessions besides the person's chat.
Sessions int `json:"sessions"`
// Subagents, Delegations and Teammates are the calls that started each kind of helper.
Subagents int `json:"subagents"`
Delegations int `json:"delegations"`
Teammates int `json:"teammates"`
// LeadEdits are the file edits of the person's chat itself.
LeadEdits int `json:"leadEdits"`
// Conflicts are files edited from more than one session; Duplicates are the same edit made in more than one.
Conflicts int `json:"conflicts"`
Duplicates int `json:"duplicates"`
// Asks are the times the person was needed: a question tool, a card of the safe asking for a secret, a turn that
// ended waiting for input.
Asks int `json:"asks"`
// BlindAsks is 1 when the person was first asked (a question tool or the safe's card) before any skill was opened:
// the access the agent wanted may well have been described there.
BlindAsks int `json:"blindAsks"`
// Steps are the tool calls of the person's chat: how long the way to the result was.
Steps int `json:"steps"`
// Messages are what agents told each other mid-work (SendMessage, send_to_conversation).
Messages int `json:"messages"`
// Repl are the calls of Code Mode's REPL tool.
Repl int `json:"repl"`
}
Metrics are what a run cost and how its agents worked together, read from its facts: the numbers a comparison of ways to work (subagents, delegated chats, teammates) is made of besides the pass.
type Model ¶
type Model struct {
// Key names the column in the report ("haiku", "codex:gpt-5.6-sol").
Key string `json:"key"`
Agent string `json:"agent"`
Model string `json:"model"`
Effort string `json:"effort,omitempty"`
}
Model is one column of the matrix: an agent CLI and the model it runs.
func ParseModel ¶
ParseModel reads "haiku", "opus", "claude:<id>" or "codex:<model>".
type Options ¶
type Options struct {
Scenarios []*Scenario
Models []Model
// Variants: "canon" (default), "all", or a number of stored variants besides the canonical one.
Variants string
Repeats int
Parallel int
MaxRuns int
MaxUSD float64
// Retries are the extra tries of a run that failed for the stand's reasons.
Retries int
// Setup names the environment under test (a harnessly build, an instruction variant): runs compare within one.
Setup string
// Out is this run's folder; Reuse are earlier results whose runs need not run again.
Out string
Reuse map[string]Result
Stand StandConfig
PortBase int
Log io.Writer
}
Options steer a run of the matrix.
type PaneExpect ¶
type PaneExpect struct {
Tab string `yaml:"tab" json:"tab"`
Target string `yaml:"target" json:"target,omitempty"`
// Place is a regexp over where in the target (a design's board); its target must match too.
Place string `yaml:"place" json:"place,omitempty"`
}
PaneExpect is a tab the agent opened.
type PaneIntent ¶
type PaneIntent struct {
Kind string `json:"kind"`
Tab string `json:"tab,omitempty"`
Target string `json:"target,omitempty"`
// Place is where in the target: a design's board.
Place string `json:"place,omitempty"`
}
PaneIntent is one thing the chat asked the right pane to show.
func ReadPaneIntents ¶
func ReadPaneIntents(file, tab string) []PaneIntent
ReadPaneIntents reads the runtime's pane-intents.json for one chat.
type Report ¶
type Report struct {
Setup string `json:"setup"`
Cells []CellStat `json:"cells"`
Models []string `json:"models"`
Runs int `json:"runs"`
Infra int `json:"infra"`
USD float64 `json:"usd"`
CostUnknown bool `json:"costUnknown,omitempty"`
// Failures are the failed runs, each with its first failed expectation.
Failures []Result `json:"-"`
}
Report is a run summed up.
type Result ¶
type Result struct {
Key string `json:"key"`
Scenario string `json:"scenario"`
Set string `json:"set"`
Variant string `json:"variant"`
Prompt string `json:"prompt"`
Model string `json:"model"`
Effort string `json:"effort,omitempty"`
Rep int `json:"rep"`
Setup string `json:"setup"`
State string `json:"state"`
Error string `json:"error,omitempty"`
Verdicts []Verdict `json:"verdicts,omitempty"`
Facts *Facts `json:"facts,omitempty"`
TurnState string `json:"turnState,omitempty"`
WallS int `json:"wallS"`
// ActiveS is from the start to the last thing an agent of the stand wrote: the work's time, without the wait for
// quiet.
ActiveS int `json:"activeS,omitempty"`
// InterruptAt is when the scenario's interrupt was sent (Unix seconds).
InterruptAt int64 `json:"interruptAt,omitempty"`
USD float64 `json:"usd"`
CostUnknown bool `json:"costUnknown,omitempty"`
Transcript string `json:"transcript,omitempty"`
StartedAt string `json:"startedAt"`
Reused bool `json:"reused,omitempty"`
}
Result is one run as the results file keeps it.
func ReadResults ¶
ReadResults reads a results file.
type Scenario ¶
type Scenario struct {
ID string `yaml:"id" json:"id"`
Title string `yaml:"title" json:"title"`
Set string `yaml:"set" json:"set"`
Tags []string `yaml:"tags" json:"tags,omitempty"`
// Agents are the CLIs the scenario applies to: claude, codex; empty is both.
Agents []string `yaml:"agents" json:"agents,omitempty"`
Setup Setup `yaml:"setup" json:"setup"`
// Prompt is the canonical words of the person; Variants are stored rewordings of the same intent.
Prompt string `yaml:"prompt" json:"prompt"`
Variants []Variant `yaml:"variants" json:"variants,omitempty"`
Expect []Expect `yaml:"expect" json:"expect"`
// Covers are the repository paths (globs, ** for any depth) whose change this scenario checks: a change of one of
// them makes `harnessly eval affected` name the scenario.
Covers []string `yaml:"covers" json:"covers,omitempty"`
// Judge is a rubric for a model, only where no fact can tell.
Judge string `yaml:"judge" json:"judge,omitempty"`
TimeoutS int `yaml:"timeout_s" json:"timeoutS,omitempty"`
// Interrupt is a message the person sends while the agent works: «stop, main is frozen».
Interrupt *Interrupt `yaml:"interrupt" json:"interrupt,omitempty"`
// SettleS: after the person's chat ends its turn, the run goes on until no agent of the stand (subagents, chats it
// delegated to, teammates) wrote to its transcript for this many seconds, and the person's chat is not working. A
// chat that delegates ends its turn and is woken by its chats' answers; without it the run is judged half-way.
SettleS int `yaml:"settle_s" json:"settleS,omitempty"`
// contains filtered or unexported fields
}
Scenario is one file of the scenarios folder.
func ParseScenario ¶
ParseScenario reads one scenario; the error says in words what is wrong.
func (*Scenario) Check ¶
Check checks the facts of a run against the scenario's expectations, in order.
func (*Scenario) Checks ¶
Checks are the check commands of the expectations, any_of included, each once.
func (*Scenario) Fingerprint ¶
Fingerprint changes whenever anything that steers a run changes.
type Setup ¶
type Setup struct {
// Files are written into the workspace: path → content.
Files map[string]string `yaml:"files" json:"files,omitempty"`
// Design are folders (relative to the scenario file) copied into the stand's design library as projects.
Design []string `yaml:"design" json:"design,omitempty"`
// Kits are UI kit folders (relative to the scenario file, each with its design-system.json naming the kit's id and
// version) installed into the stand as kits installed on the machine are: the kit_* tools and design new --kit see them.
Kits []string `yaml:"kits" json:"kits,omitempty"`
// RuntimeEnv adds to the setup's runtime settings for this scenario.
RuntimeEnv map[string]string `yaml:"runtime_env" json:"runtimeEnv,omitempty"`
// Workspace are folders (relative to the scenario file) whose contents are copied into the workspace.
Workspace []string `yaml:"workspace" json:"workspace,omitempty"`
// Run is a shell script run in the workspace, inside the stand's sandbox, after the files are in place (git init).
Run string `yaml:"run" json:"run,omitempty"`
}
Setup is what the stand holds before the person speaks.
type SetupFile ¶
type SetupFile struct {
Name string `yaml:"name"`
RuntimeEnv map[string]string `yaml:"runtime_env"`
AgentEnv map[string]string `yaml:"agent_env"`
ClaudeConfig map[string]any `yaml:"claude_config"`
PromptSuffix string `yaml:"prompt_suffix"`
}
SetupFile is a setup kept as a file: the environment under test, as configuration.
type Stand ¶
type Stand struct {
Dir, Home, Data, Work, Library string
Port int
Workspace string
// contains filtered or unexported fields
}
Stand is one disposable harnessly: its own home, data, workspace, design library, port and tmux socket.
func Up ¶
func Up(cfg StandConfig, name string, port int) (*Stand, error)
Up makes and starts a stand named name on port.
func (*Stand) Chat ¶
Chat starts a chat of agent (claude, codex) on model with the person's words, the platform's way.
func (*Stand) ChatWithEffort ¶
ChatWithEffort starts a chat without silently using the model's default effort.
func (*Stand) Down ¶
func (s *Stand) Down()
Down stops the stand's runtime and agents and removes its folder.
func (*Stand) Exec ¶
func (s *Stand) Exec(ctx context.Context, script string, extra []string, timeout time.Duration) (int, string)
Exec runs a shell script in the workspace inside the stand's sandbox, with the stand's home and extra variables.
func (*Stand) Settle ¶
func (s *Stand) Settle(ctx context.Context, tab string, quiet time.Duration, deadline time.Time) (time.Time, bool)
Settle waits, after the person's chat ended its turn, until no agent of the stand wrote for quiet and the chat is not working, or until the deadline. The answer is when the agents last did something, and whether they went quiet.
type StandConfig ¶
type StandConfig struct {
// Root holds the stands' folders.
Root string
// Runtime is the runtime binary; Harnessly the CLI (the agent's `harnessly`, and the fake picture generator).
Runtime string
Harnessly string
// Tools are folders whose claude and codex the agents run.
Tools []string
// Login holds claude-credentials.json, claude-account.json and codex-auth.json: copies without refresh tokens.
Login string
// RealImages draws pictures with Codex for real; by default a fake generator answers with a blank picture.
RealImages bool
// AgentEnv are variables every agent of the stand gets (a provider's base URL, a model's name).
AgentEnv map[string]string
// LogsDir is where a stand that fails to start leaves its logs before its folder goes; "" keeps none.
LogsDir string
// RuntimeEnv are the runtime's settings (RUNTIME_GITLAB_HOSTS, RUNTIME_TASK_KEY_RE…): the setup under test.
RuntimeEnv map[string]string
// ClaudeConfig are keys merged into the agents' ~/.claude.json: a consent given once, as a person would
// (Code Mode's codeModeCaveatsAcceptedV1 and codeModeAutoModeCaveatAcceptedV1).
ClaudeConfig map[string]any
// PromptSuffix is added to the person's words: an arm of a comparison that names the way to work («use subchats»).
PromptSuffix string
}
StandConfig is what every stand of a machine is made from.
type Usage ¶
type Usage struct {
In int `json:"in"`
CacheRead int `json:"cacheRead"`
CacheWrite int `json:"cacheWrite"`
Out int `json:"out"`
}
Usage are one model's tokens.