agenteval

package
v0.16.341 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0 modules, 0 packages

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

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

View Source
const (
	Pass  = "pass"
	Fail  = "fail"
	Infra = "infra"
)

States of a run.

View Source
const (
	SetDev     = "dev"
	SetHeldOut = "heldout"
)
View Source
const MinEffect = 0.10

MinEffect is the smallest change of a pass rate that is reported as a change, whatever the intervals say.

Variables

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

func Change(k0, n0, k1, n1 int, noise float64) string

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

func FakeImagegen(args []string, stdout io.Writer) error

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

func MatchPath(glob, p string) bool

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

func PassHatK(c, n, k int) float64

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 Passed

func Passed(v []Verdict) bool

Passed says whether every expectation held.

func ReadSurface

func ReadSurface(file string) ([]string, error)

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

func SandboxExec(rw, ro, argv []string) error

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.

func Wilson

func Wilson(k, n int) (lo, hi float64)

Wilson is the 95% Wilson score interval of k passes in n runs.

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 Cell

type Cell struct {
	Scenario *Scenario
	Variant  Variant
	Model    Model
	Rep      int
}

Cell is one run of the matrix.

func (Cell) Key

func (c Cell) Key(setup string) string

Key is what makes two runs the same run: the cache's key.

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

func ReadClaudeTranscript(paths ...string) (Facts, error)

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

func ReadCodexRollout(path string) (Facts, error)

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.

func ReadFiles

func ReadFiles(root, prefix string) []FileFact

ReadFiles lists a folder's files under a prefix, with the text of the small ones; dot folders other than the root's own files are skipped.

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

func ReadImageJobs(dir, tab string) []ImageJob

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

func Affected(changed, surface []string, scenarios []*Scenario, dir string) Impact

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

func (i Impact) NeedsScenario() bool

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

func ParseModel(s string) (Model, error)

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.

func (Options) Cells

func (o Options) Cells() []Cell

Cells expands 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.

func Summarize

func Summarize(results, against []Result, noise float64) Report

Summarize sums up results; against are an earlier run's, for the change column (nil: none).

func (Report) Markdown

func (rep Report) Markdown(title string) string

Markdown is the report as a page: the table scenario × model, then the failures.

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

func ReadResults(path string) ([]Result, error)

ReadResults reads a results file.

func Run

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

Run runs the matrix and writes results.jsonl into o.Out as it goes.

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 Load

func Load(dir string) ([]*Scenario, error)

Load reads the scenarios of a folder (*.yaml, one level), by id.

func ParseScenario

func ParseScenario(name string, raw []byte) (*Scenario, error)

ParseScenario reads one scenario; the error says in words what is wrong.

func (*Scenario) AppliesTo

func (s *Scenario) AppliesTo(agent string) bool

AppliesTo says whether the scenario runs on an agent CLI.

func (*Scenario) Check

func (s *Scenario) Check(f Facts) []Verdict

Check checks the facts of a run against the scenario's expectations, in order.

func (*Scenario) Dir

func (s *Scenario) Dir() string

Dir is the folder of the scenario's file.

func (*Scenario) Fingerprint

func (s *Scenario) Fingerprint() string

Fingerprint changes whenever anything that steers a run changes.

func (*Scenario) Prompts

func (s *Scenario) Prompts() []Variant

Prompts are the canonical prompt (id "canon") and the stored variants.

func (*Scenario) Timeout

func (s *Scenario) Timeout() int

Timeout is the scenario's wall time for one run, in seconds.

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.

func ReadSetup

func ReadSetup(path string) (SetupFile, error)

ReadSetup reads a setup file; only RUNTIME_* settings reach the runtime.

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

func (s *Stand) Chat(agent, model, prompt string) (string, error)

Chat starts a chat of agent (claude, codex) on model with the person's words, the platform's way.

func (*Stand) Collect

func (s *Stand) Collect(agent, tab, keep string) (Facts, error)

Collect reads the facts of a chat and copies its transcript to keep.

func (*Stand) Down

func (s *Stand) Down()

Down stops the stand's runtime and agents and removes its folder.

func (*Stand) Wait

func (s *Stand) Wait(ctx context.Context, tab string, timeout time.Duration) string

Wait waits until the chat's turn is over; the answer is the last state ("timeout" when the time ran out).

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.

type Variant

type Variant struct {
	ID   string `yaml:"id" json:"id"`
	Kind string `yaml:"kind" json:"kind,omitempty"`
	Text string `yaml:"text" json:"text"`
}

Variant is a stored rewording of the prompt.

type Verdict

type Verdict struct {
	Name string `json:"name"`
	OK   bool   `json:"ok"`
	Why  string `json:"why,omitempty"`
}

Verdict is one expectation's outcome.

Jump to

Keyboard shortcuts

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