Documentation
¶
Overview ¶
Package bench runs coding tasks through the real harness (local sandbox, coding profile) against a model and reports pass/fail with the cost: steps, tool calls, tokens, prompt-cache hits, wall time and memory.
A Task is a small repository (Files), a prompt, and a check that decides whether the job was done: Verify, a shell command run in the repository after the agent finished (exit 0 = pass), after Hidden files — the original tests — are written back so an agent cannot pass by weakening them; and/or Answer, regular expressions that must all match the final answer (questions about the code). Solution is a reference fix: the offline tests apply it to prove each task is solvable and fails before the fix.
Offline (scripted model) the package is a regular test; against a live model use cmd/bench or `go test -tags live ./bench`.
Index ¶
- Constants
- func Check(ctx context.Context, t Task, dir, answer string) (ok bool, output string)
- func Compare(w io.Writer, before, after Report)
- func Markdown(w io.Writer, rs []Result)
- func MarkdownWith(w io.Writer, rs []Result, p Prices)
- func Materialize(dir string, files ...map[string]string) error
- func Missing(t Task) []string
- func Names() string
- func WriteJSON(path, model string, rs []Result) error
- func WriteJSONWith(path, model string, rs []Result, p Prices) error
- type Options
- type Prices
- type Report
- type Result
- type Suite
- type Summary
- type Task
- type TaskStats
Constants ¶
const ( TierEasy = "easy" TierHard = "hard" // TierLong tasks need 50+ steps (compaction, masking); `-tier long` runs them. TierLong = "long" )
Difficulty tiers.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check applies t's hidden files in dir and reports whether the task's checks hold for answer.
func Compare ¶
Compare renders the change from a baseline report to a new one, per task and in total (pass rate, mean steps, mean input tokens, cache hit %, uncached tokens per step, seconds, and cost when either report has prices), for before/after runs of a harness change.
func Markdown ¶
Markdown renders results as a table with a total row, then a per-task table of pass rates.
func MarkdownWith ¶
MarkdownWith is Markdown with the estimated cost at p (shown when any price is set).
func Materialize ¶
Materialize writes files under dir.
func Names ¶
func Names() string
Names returns the task names of the built-in set, comma separated (for flag help).
Types ¶
type Options ¶
type Options struct {
// Timeout bounds the whole task (default 10 minutes).
Timeout time.Duration
// MaxSteps overrides AGENT_MAX_STEPS (0: keep).
MaxSteps int
// Keep leaves the working directory in place and records it in Result.Dir.
Keep bool
// NoCacheKey sends no prompt_cache_key (some routers route on it).
NoCacheKey bool
}
Options tune a run.
type Prices ¶
type Prices struct {
In float64 `json:"in"`
Cached float64 `json:"cached"`
Out float64 `json:"out"`
}
Prices are USD per million tokens; the zero value means "unpriced" (no cost is shown).
type Report ¶
type Report struct {
Model string `json:"model"`
Prices *Prices `json:"prices,omitempty"`
Summary Summary `json:"summary"`
Tasks []TaskStats `json:"tasks,omitempty"`
Results []Result `json:"results"`
}
Report is the JSON written by WriteJSON. Results keeps every run (repeats included); Tasks is the per-task aggregate.
func ReadReport ¶
ReadReport loads a report written by WriteJSON.
type Result ¶
type Result struct {
Task string `json:"task"`
Model string `json:"model"`
// Passed: the run finished and the task's checks held.
Passed bool `json:"passed"`
// Status is "finished", or the RUN_ERROR code / failure that ended the run.
Status string `json:"status"`
// Detail is the last warning the harness logged for the run (why a run failed; the event only says "model_error").
Detail string `json:"detail,omitempty"`
VerifyOutput string `json:"verifyOutput,omitempty"`
FinalAnswer string `json:"finalAnswer,omitempty"`
Steps int `json:"steps"`
ToolCalls int `json:"toolCalls"`
ToolErrors int `json:"toolErrors"`
Tools map[string]int `json:"tools,omitempty"`
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CachedTokens int `json:"cachedTokens"`
CacheHitPct float64 `json:"cacheHitPct"`
// UncachedTokens is InputTokens - CachedTokens; UncachedPerStep divides it by Steps.
UncachedTokens int `json:"uncachedTokens"`
UncachedPerStep float64 `json:"uncachedPerStep"`
WallSeconds float64 `json:"wallSeconds"`
// HeapMiB and SysMiB are the Go heap in use and memory obtained from the OS at the end of the run;
// MaxRSSMiB is the process peak so far (it only grows across the tasks of one process).
HeapMiB float64 `json:"heapMiB"`
SysMiB float64 `json:"sysMiB"`
MaxRSSMiB float64 `json:"maxRSSMiB"`
Dir string `json:"dir,omitempty"`
}
Result is what one run of one task cost and achieved.
type Suite ¶
type Suite struct {
Config *config.Config
// ModelsFor returns the model factory of a run (nil: the real model from Config). It is called once
// per run, possibly from several goroutines.
ModelsFor func(Task) llm.Factory
Options Options
// Parallel is the number of runs in flight (default 1).
Parallel int
// Skip is called (serialized) for each task skipped because a program it needs is missing.
Skip func(t Task, missing []string)
// Progress is called (serialized) when a run finishes; run is 1-based.
Progress func(t Task, run, n int, r Result)
}
Suite runs tasks, N times each, optionally several at once.
Parallel runs share one process: wall time is still per run, but MaxRSSMiB (and to a lesser degree HeapMiB/SysMiB) are process-wide and cannot be attributed to a single run.
type Summary ¶
type Summary struct {
Runs int `json:"runs"`
Passed int `json:"passed"`
PassRate float64 `json:"passRate"`
Steps int `json:"steps"`
ToolCalls int `json:"toolCalls"`
ToolErrors int `json:"toolErrors"`
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CachedTokens int `json:"cachedTokens"`
CacheHitPct float64 `json:"cacheHitPct"`
UncachedTokens int `json:"uncachedTokens"`
UncachedPerStep float64 `json:"uncachedPerStep"`
// CostUSD is the estimated cost; zero unless prices were given.
CostUSD float64 `json:"costUSD,omitempty"`
WallSeconds float64 `json:"wallSeconds"`
MaxRSSMiB float64 `json:"maxRSSMiB"`
}
Summary aggregates the results of a benchmark.
func SummarizeWith ¶
SummarizeWith is Summarize plus the estimated cost at p.
type Task ¶
type Task struct {
Name string
// Tier is TierEasy (the default when empty) or TierHard; see TierOf.
Tier string
Prompt string
// Files is the starting repository (path → content).
Files map[string]string
// Hidden files are written over the repository before Verify runs.
Hidden map[string]string
// Verify is a bash command run in the repository; exit 0 means the task is done. Empty: only Answer counts.
Verify string
// Answer regexps must all match the final answer.
Answer []string
// Solution files, applied over Files, make Verify (and Hidden) pass.
Solution map[string]string
// SolutionAnswer is a final answer that satisfies Answer.
SolutionAnswer string
// Needs lists the programs the task needs on PATH (go, python3, make).
Needs []string
}
Task is one benchmark job.
func FilterTier ¶
FilterTier keeps the tasks of one tier ("easy", "hard" or "long"). An empty tier or "all" keeps the easy and hard tasks: the long ones need 50+ steps and are only run when asked for.
func LongTasks ¶
func LongTasks() []Task
LongTasks returns the long-session tasks: they need 50+ steps and, with a small context window, compaction and masking (set LLM_CONTEXT_WINDOWS=<model>=32000 to force it). They are generated programmatically so the repositories are big enough to be explored and edited file by file.
type TaskStats ¶
type TaskStats struct {
Task string `json:"task"`
Runs int `json:"runs"`
Passed int `json:"passed"`
// PassRate is Passed/Runs.
PassRate float64 `json:"passRate"`
MeanSteps float64 `json:"meanSteps"`
MedianSteps float64 `json:"medianSteps"`
MeanTokens float64 `json:"meanTokens"` // input + output
MedianTokens float64 `json:"medianTokens"` // input + output
MeanUncached float64 `json:"meanUncachedPerStep"`
MeanCostUSD float64 `json:"meanCostUSD,omitempty"`
}
TaskStats aggregates the repeated runs of one task.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package swebench turns SWE-bench instances (https://www.swebench.com) into bench tasks and scores the resulting repositories the way SWE-bench does.
|
Package swebench turns SWE-bench instances (https://www.swebench.com) into bench tasks and scores the resulting repositories the way SWE-bench does. |