Skip to main content

Crate rig_evals

Crate rig_evals 

Source
Expand description

Evaluations for Rig agents.

An Experiment runs a Target (a Rig agent, an async function, or, with the multiagent feature, a swarm or graph) on every Case of a Dataset, scores each run with Evaluators, and hands the Report to Sinks.

use rig_evals::{Dataset, Experiment, JunitFile, evaluators};

async fn run(agent: rig_agent::Agent) -> Result<(), Box<dyn std::error::Error>> {
    let report = Experiment::new("support-bot")
        .dataset(Dataset::load("evals/cases.jsonl")?)
        .target(agent)
        .evaluator(evaluators::contains("refund"))
        .evaluator(evaluators::no_error())
        .repetitions(3)
        .threshold("contains", 0.8)
        .sink(JunitFile::new("target/evals/junit.xml"))
        .run()
        .await?;
    std::process::exit(if report.passed() { 0 } else { 1 });
}

A dataset is a .jsonl file (one case per line) or a .json array. A case has an id and either an input (one prompt) or turns (a conversation). expected, trajectory (name and optional args per tool call), assertions and metadata are optional references. A three-case file:

{"id": "refund", "input": "Order 7 arrived broken.", "expected": "A refund was issued.", "trajectory": [{"name": "lookup_order", "args": {"id": 7}}, {"name": "refund"}], "assertions": ["apologizes"]}
{"id": "hours", "input": "What are your opening hours?", "expected": "We are open 9 to 5.", "assertions": ["gives the hours"]}
{"id": "city", "turns": ["My favourite city is Lisbon.", "What is my favourite city?"], "expected": "Lisbon"}

With the agentcore feature, AgentCore makes a runtime on AWS Bedrock AgentCore a target, and AgentCore Evaluations’ evaluators evaluators.

Each run is a tracing span eval.trial inside an eval.experiment span, and each score an OpenTelemetry GenAI gen_ai.evaluation.result event on it, so a tracing exporter (such as rig-otel) puts the results on the evaluated agent’s trace. The agent’s prompts and replies reach that trace only when it records content, with AgentBuilder::record_content_telemetry(true). A score’s explanation (the judge’s text) is recorded only with Experiment::record_content(true).

Re-exports§

pub use evaluators::LlmJudge;
pub use evaluators::Verdict;

Modules§

evaluators
The built-in evaluators.

Structs§

AgentCoreagentcore
The AWS clients AgentCore targets and evaluators share, and the spans downloaded so far, so several evaluators of one run download them once.
AgentCoreEvaluatoragentcore
An AgentCore Evaluations evaluator; see AgentCore::evaluator.
AgentCoreTargetagentcore
A runtime on AgentCore Runtime; see AgentCore::target.
Case
One input to run the target on, with the references evaluators check the run against: the expected answer, the expected tool calls, and assertions in plain language (for an LLM judge).
CaseChange
A case whose outcome changed between the two reports.
Comparison
How a candidate run differs from a baseline run of the same experiment.
Dataset
The cases of an experiment.
EvaluatorDelta
One evaluator in a Comparison.
EvaluatorSummary
One evaluator’s results over all trials.
ExpectedCall
A tool call a case expects.
Experiment
An evaluation: a target run on every case of a dataset, a number of times, each run scored by every evaluator; the report goes to the sinks.
FnTarget
A target made of an async function; see target_fn.
JsonFile
Writes the report as JSON (Report::to_json) to a file.
JunitFile
Writes the report as JUnit XML (Report::to_junit) to a file, for CI test reports.
LatencySummary
Run latencies over all trials.
Markdown
Writes the report as Markdown (Report::to_markdown) to a file (such as $GITHUB_STEP_SUMMARY) or to standard output.
Named
An evaluator renamed by Evaluator::named.
NodeTargetmultiagent
A rig-multiagent node (a swarm, a graph, an agent) as a target; see node_target.
Report
What an experiment found.
Score
One evaluator’s verdict on one run.
TargetOutput
What one target run produced.
ThresholdResult
Whether an evaluator’s pass rate reached its threshold.
Tokens
Model tokens over all trials.
ToolCall
A tool call the target made, and the result the tool returned when the target recorded it.
Trial
One run of the target on a case.
TrialResult
A trial and its scores.
Turn
One user turn of a multi-turn run and the answer it got.
TurnFailed
A multi-turn run that failed at one of its turns. The error of the turn is prefixed turn <n>:; the completed turns, their tool calls and usage (and the session id, if any) are kept in partial, and the experiment puts them in the failed trial.

Enums§

AgentCoreErroragentcore
Why an AgentCore target or evaluator failed.
DatasetError
Why a dataset could not be read.
EvalError
Why an evaluator could not score a run. An experiment records it as a failed score labelled "error" and carries on.
ExperimentError
Why an experiment could not run, or could not deliver its report.
SinkError
Why a sink could not record a report.

Traits§

Evaluator
Scores runs.
Sink
Receives an experiment’s report when it finishes.
Target
Something to evaluate: runs a case’s input and reports what it did.

Functions§

node_targetmultiagent
Evaluate a rig-multiagent Node: its answer and usage. Nodes do not report their tool calls, so trials have none.
target_fn
A target that runs f on each case: a wrapper around an agent pipeline, a remote service, or a stub. f returns a TargetOutput or anything that converts into one (a String).

Type Aliases§

TargetError
Why a target run failed: a boxed error, Send + Sync except on wasm.