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 Expect
- type Facts
- type FileExpect
- type FileFact
- type ImageJob
- type Impact
- type Model
- type Options
- type PaneExpect
- type PaneIntent
- type Report
- type Result
- type Scenario
- type Setup
- type SetupFile
- type Stand
- type StandConfig
- 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 with Landlock (rw: read and write beneath; ro: read and run beneath; everything else refused, for every process it starts too) and becomes argv. It does not return when it succeeds.
Types ¶
type Call ¶
type Call struct {
Name string `json:"name"`
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"`
// 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 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"`
// NotCalled: no call of a matching tool with matching Args ran (a refused call does not count).
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"`
// 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"`
}
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"`
// 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"`
}
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 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"`
}
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"`
// 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"`
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"`
USD float64 `json:"usd"`
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"`
// 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) 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"`
// RuntimeEnv adds to the setup's runtime settings for this scenario.
RuntimeEnv map[string]string `yaml:"runtime_env" json:"runtimeEnv,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"`
}
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.
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
// RuntimeEnv are the runtime's settings (RUNTIME_GITLAB_HOSTS, RUNTIME_TASK_KEY_RE…): the setup under test.
RuntimeEnv map[string]string
}
StandConfig is what every stand of a machine is made from.