Documentation
¶
Overview ¶
Package eval is a deterministic eval / scorer harness for agent turns. A Case names one input; a Scorer grades what a Run produced (the TurnResult plus the captured event stream); a Suite runs a set of Cases against a set of Scorers and returns a structured report.
The harness is model-and-turn-facing, so it lives in agent/ (constraint A6): scorers read a *agent.TurnResult and an []agent.Event, both meaningless without a Runner turn. It depends only on core/ and agent/, adds no third-party dependency, and never prints (constraint A4) — a Suite returns a SuiteReport that a test or CLI renders.
The deterministic scorers (ExactMatch, Contains, ToolCalled, MaxSteps, StepCount, NoError) need no network or live model: drive a Case with agent.NewStubProvider for reproducible evals in CI. The LLM-as-judge scorer lives behind the eval_llm build tag so the default build and CI path carry no model requirement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transcript ¶
Transcript renders a Result as human-readable text: the final answer, the step count, and the tool calls the turn made with their results. The LLM-as-judge scorer feeds this to a model; it is also useful for logging a failed case. Rendering only, no printing (constraint A4).
Types ¶
type Case ¶
type Case struct {
// Name identifies the case in a report. Should be unique within a Suite.
Name string
// Input is a convenience seed: when History is empty and Input is
// non-empty, the turn runs against a single RoleUser message carrying
// Input. History takes precedence when both are set.
Input string
// History is the full input conversation, oldest first. Overrides Input.
History []agent.Message
// Tools overrides RunnerConfig.Tools for this case when non-nil, so a
// case can run under a tool surface tailored to what it exercises.
Tools agent.ToolSource
// Instructions overrides RunnerConfig.Instructions for this case when
// non-empty.
Instructions string
// MaxSteps overrides RunnerConfig.MaxSteps for this case when positive.
MaxSteps int
}
Case is one eval input: a name, the conversation to run, and any per-case overrides applied on top of the base RunnerConfig. It is a plain struct so callers can build tables of them inline.
type CaseReport ¶
type CaseReport struct {
Case string `json:"case"`
Scores []Score `json:"scores"`
Pass bool `json:"pass"`
// RunErr is set when the harness could not build the runner for this
// case (an invalid config); when set, no scorers ran and Pass is false.
RunErr string `json:"runErr,omitempty"`
}
CaseReport is one case's outcome: the per-scorer verdicts and whether the case passed overall (every scorer passed and the run built cleanly).
type Result ¶
type Result struct {
// Case is the input that produced this result.
Case Case
// Turn is the completed turn, or nil when Err is non-nil and the turn
// aborted before completion.
Turn *agent.TurnResult
// Events is every event the Runner emitted, in order.
Events []agent.Event
// Err is the run error: ctx cancellation, provider failure, or the step
// cap (wrapping agent.ErrMaxSteps). Tool failures do not appear here —
// the Runner feeds those back to the model, so they surface as
// tool-error / tool-end(IsError) events instead.
Err error
}
Result is one scored run's transcript: the completed turn (nil when the run failed before producing one), the captured event stream, and the run error (nil on success). Scorers read these fields; NoError inspects Err and the event stream, the text scorers read Turn.Text.
func Final ¶
Final returns the last turn's Result — the graded turn of a scenario. It panics on an empty slice (a scenario always has at least one turn), so a scorer can write Final(results) without a length dance.
func Run ¶
Run executes one Case against a copy of cfg with the Case's overrides applied, wiring an event collector, and packages the transcript into a Result. The returned error is a harness-level failure (an invalid RunnerConfig that NewRunner rejects); a turn that runs and fails carries its error in Result.Err, not the returned error, so scorers can grade it.
func RunScenario ¶
RunScenario executes s against a copy of cfg with the scenario's overrides applied, running each turn in order and threading history plus a shared working-memory source across them. It returns one Result per turn (the last is the graded turn); the returned error is a harness-level failure (an invalid RunnerConfig), while a turn that runs and fails carries its error in that turn's Result.Err.
A single Runner is built and reused for every turn: the Runner is stateless over the history it is handed, so reuse is what makes the shared MemorySource (held in cfg.Tools) persist across turns.
type Scenario ¶
type Scenario struct {
// Name identifies the scenario in a report. Should be unique in a Suite.
Name string
// Turns are the user inputs, oldest first. Each runs as one agent turn
// against the accumulated history; the final turn's Result is the graded
// one.
Turns []string
// Memory, when true, gives the run a working-memory scratchpad (a
// MemorySource) merged with any base Tools, so the model can
// remember/recall across the turns. The backing store is NewMemoryStore
// when set, else a fresh in-memory default. The store is built once per
// RunScenario call — scenarios never share memory.
Memory bool
// NewMemoryStore builds the MemoryStore backing this scenario's working
// memory. Nil uses the in-memory default. Set it to grade a different
// backend (redis, gorm, a future semantic store) through the same
// scenarios — the whole point of an eval harness is comparing impls. It
// is a factory, not a value, so each RunScenario gets its own store and
// scenarios in a suite never cross-contaminate; a caller that WANTS
// shared state across scenarios can close over one store and return it.
// A non-nil NewMemoryStore implies Memory.
NewMemoryStore func() (agent.MemoryStore, error)
// Tools is the base tool surface, merged under the memory tools when
// Memory is set. Nil offers only the memory tools (or none, when Memory
// is false).
Tools agent.ToolSource
// Instructions overrides RunnerConfig.Instructions for this scenario
// when non-empty.
Instructions string
// MaxSteps overrides RunnerConfig.MaxSteps per turn when positive.
MaxSteps int
}
Scenario is a multi-turn eval input: a sequence of user turns that share one conversation and (optionally) one working-memory scratchpad, run in order. It is what the single-turn Case cannot express — memory evals (LongMemEval and kin) build up facts across turns and sessions, then ask a question, so the thing under test is whether earlier turns survive into a later answer.
RunScenario threads history across turns and keeps one MemorySource for the whole run, so a fact remembered on turn 1 is recallable on turn 5. The last turn is the one a Scorer grades; earlier turns are setup.
type Score ¶
type Score struct {
Name string `json:"name"`
Pass bool `json:"pass"`
Value float64 `json:"value"`
Detail string `json:"detail,omitempty"`
}
Score is one scorer's verdict on a Result. Value is a normalized score in [0,1] where 1.0 is a full pass; the deterministic scorers emit 1.0 or 0.0, while a graded scorer (the LLM judge) may report an intermediate value. Pass is the boolean the Suite aggregates. Detail is the human-readable specifics.
type Scorer ¶
Scorer grades a Result. Implementations must be pure functions of the Result and safe for concurrent use; the deterministic ones read no state.
func ExactMatch ¶
ExactMatch passes when the final turn text equals want exactly.
func NoError ¶
func NoError() Scorer
NoError passes when the run itself succeeded and no tool failed: no run error, no error event, no tool dispatch error, and no tool result marked IsError. It catches the failure shapes the Runner folds back into the conversation (which never abort the turn) as well as a hard run error.
func NotContains ¶
NotContains passes when the final turn text does NOT contain substr. It is the abstention / knowledge-supersede check: a memory eval asserts the model did not surface a stale fact (the old value after an update) or did not hallucinate a specific it was never told. A failed run (no turn) fails the scorer — there is no answer to trust.
func NotDenied ¶
func NotDenied() Scorer
NotDenied passes when no tool call was blocked by an approval policy. A denial is deliberately not an error (the Runner emits a distinct tool-denied event, not tool-error), so NoError ignores it; this scorer is the separate check for evals that assert the model never attempted a gated tool. Compose with NoError when a case must be both clean and unblocked.
func ToolCalled ¶
ToolCalled passes when the turn requested the named tool at least once. It scans the event stream for tool-begin (emitted for every dispatched call, including ones that later error or are denied), so it reports intent to call regardless of the call's outcome.
type Suite ¶
type Suite struct {
// Config is the base RunnerConfig shared by every case (Provider is
// required). Per-case overrides in Case are layered on a copy.
Config agent.RunnerConfig
// Cases is the set of inputs to evaluate.
Cases []Case
// Scorers is the set of graders applied to every case's Result.
Scorers []Scorer
}
Suite runs each Case against every Scorer and folds the verdicts into a SuiteReport. Config is the base RunnerConfig; each Case may override its tool surface, instructions, or step cap on top of it.
func (Suite) Run ¶
func (s Suite) Run(ctx context.Context) SuiteReport
Run evaluates every case against every scorer and returns the report. It does not stop on a failing case; a per-case harness failure (bad config) is recorded in that case's RunErr and the suite continues. Ctx cancellation surfaces per case via the Runner (recorded in scores through NoError, or in RunErr for a build failure) rather than aborting the whole suite.
type SuiteReport ¶
type SuiteReport struct {
Cases []CaseReport `json:"cases"`
Passed int `json:"passed"`
Failed int `json:"failed"`
Total int `json:"total"`
}
SuiteReport is the aggregate: one CaseReport per case plus pass/fail counts.
func (SuiteReport) String ¶
func (r SuiteReport) String() string
String renders the report as a plain-text table. It returns the string; it does not print (constraint A4) — a test or CLI writes it. The format is stable enough to eyeball, not a machine contract (marshal the report as JSON for that).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package longmemeval provides fast, self-contained SMOKE scenarios for the Phase 2 memory work, shaped after the LongMemEval benchmark's skill categories.
|
Package longmemeval provides fast, self-contained SMOKE scenarios for the Phase 2 memory work, shaped after the LongMemEval benchmark's skill categories. |