rig-evals 0.47.2

Evaluations for Rig agents: datasets of cases, built-in and LLM-judge evaluators, repetitions and pass-rate thresholds, JSON, JUnit and Markdown reports, OpenTelemetry GenAI evaluation events.
Documentation
# rig-evals

Evaluations for [Rig](https://github.com/0xPlaygrounds/rig) agents: run an agent on a
dataset of cases, score every run, and fail CI when a pass rate drops.

```rust
use rig_evals::{Dataset, Experiment, JunitFile, LlmJudge, Markdown, evaluators};
use rig_evals::evaluators::TrajectoryMode;

let report = Experiment::new("support-bot")
    .dataset(Dataset::load("evals/support.jsonl")?)
    .target(agent)
    .evaluator(evaluators::trajectory(TrajectoryMode::InOrder))
    .evaluator(evaluators::budget().max_total_tokens(4_000))
    .evaluator(LlmJudge::new(judge, "Is the answer correct and polite?").threshold(0.7))
    .repetitions(5)
    .concurrency(4)
    .threshold("llm_judge", 0.8)
    .sink(JunitFile::new("target/evals/junit.xml"))
    .sink(Markdown::stdout())
    .run()
    .await?;
std::process::exit(if report.passed() { 0 } else { 1 });
```

## Cases

A case has an `id`, an `input`, and the references evaluators check a run against: an
`expected` answer, an expected `trajectory` of tool calls, and `assertions` in plain
language. These are the reference inputs of AWS Bedrock AgentCore evaluations and the
fields of Strands Evals' cases. `Dataset::load` reads `.json` (an array) or `.jsonl`.

```json
{"id": "refund", "input": "Order 7 arrived broken.", "expected": "A refund was issued.",
 "trajectory": [{"name": "lookup_order", "args": {"id": 7}}, {"name": "refund"}],
 "assertions": ["apologizes", "gives the refund amount"]}
```

## Targets

A `Target` runs a case. Rig agents are targets: the trial gets the answer, the tool calls
from the run's transcript, and the run's token usage. `target_fn` wraps an async
function. With the `multiagent` feature, `node_target` wraps a rig-multiagent swarm,
graph or node (answer and usage; nodes do not report tool calls).

## Evaluators

An `Evaluator` scores a trial from 0 to 1 and says whether it passed.

| Evaluator | Passes when |
|---|---|
| `contains`, `contains_all` | the answer contains every string |
| `regex` | the answer matches the pattern |
| `equals` | the trimmed answer equals `expected` |
| `json` | the answer is JSON, with the `require`d keys |
| `trajectory` | the tool calls match the trajectory: `Exact`, `InOrder` or `AnyOrder`; given args match as a subset |
| `budget` | output tokens, total tokens and latency stay within limits |
| `no_error` | the target did not fail |
| `LlmJudge` | a judge agent scores the answer against a rubric at least at the threshold |

A failed target run still gets scored, and the built-ins fail it. An evaluator that
errors (a case without `expected`, a judge without a verdict) gives a failed score
labelled `error`; the experiment carries on. `named` renames an evaluator, to use two of
a kind.

## CI

Each evaluator has a threshold: the share of trials it must pass. It is 1 unless set with
`threshold(name, min_pass_rate)`; with repetitions, a lower one tolerates a
nondeterministic agent. `Report::passed()` is false when any evaluator misses its
threshold: use it as the exit code. The JUnit report has one test case per trial and per
threshold, so CI test views show the failures.

## Sinks

A `Sink` receives the report. `JsonFile`, `JunitFile` and `Markdown` (a file, such as
`$GITHUB_STEP_SUMMARY`, or stdout) are built in; `Report::to_json`, `to_junit` and
`to_markdown` give the same text. A sink that fails returns its error with the report.

## OpenTelemetry

The experiment is an `eval.experiment` span, and each trial an `eval.trial` span
(`eval.case`, `eval.repetition`) that the agent's own spans nest in. Each score is a
`gen_ai.evaluation.result` event on the trial span, with `gen_ai.evaluation.name`,
`gen_ai.evaluation.score.value`, `gen_ai.evaluation.score.label` (the label, or
`pass`/`fail`) and `gen_ai.evaluation.explanation`: the event of the OpenTelemetry GenAI
semantic conventions (development status). The crate only emits `tracing` data; with
[rig-otel](https://crates.io/crates/rig-otel) installed, any OTel backend shows the results on the evaluated
run's trace.

## Providers

### AWS Bedrock AgentCore

With the `agentcore` feature, an agent deployed on AgentCore Runtime is a target, and
AgentCore Evaluations' evaluators (`Builtin.Correctness`, `Builtin.Helpfulness`,
`Builtin.GoalSuccessRate`, the trajectory matchers, or a custom evaluator id) are
evaluators. They follow AWS's
[on-demand evaluation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/getting-started-on-demand.html)
flow:

1. `AgentCoreTarget` invokes the runtime (`InvokeAgentRuntime`, HTTP protocol, payload
   `{"prompt": <input>}`) in a fresh session per trial and answers the reply's `response`.
   The trial carries the session id.
2. `AgentCoreEvaluator` waits for the session's spans in CloudWatch Logs: it queries
   `aws/spans` and the runtime's `/aws/bedrock-agentcore/runtimes/<runtime-id>-<endpoint>`
   group with Logs Insights every 10 seconds, up to 5 minutes, until an `invoke_agent`
   span is in and the span count stops growing.
3. It sends the spans to `Evaluate` with the case's references: `assertions` and the tool
   names of the `trajectory` for the session, `expected` for the last invocation's trace.
   The score is the mean of the results (one per trace for trace-level evaluators), with
   their labels and explanations; it passes at the threshold (0.5 unless set). A result
   that is an error makes an error score.

The spans are downloaded once per session and shared by every AgentCore evaluator of the
same `AgentCore`.

```rust
use rig_evals::{AgentCore, Dataset, Experiment, Markdown, evaluators};

let agentcore = AgentCore::from_env().await; // or AgentCore::new(&sdk_config)
let report = Experiment::new("rig-lab")
    .dataset(Dataset::load("evals/math.jsonl")?)
    .target(agentcore.target("arn:aws:bedrock-agentcore:us-east-1:123456789012:runtime/rig_lab-AbCdE12345"))
    .evaluator(agentcore.evaluator("Builtin.Correctness").threshold(0.8))
    .evaluator(agentcore.evaluator("Builtin.Helpfulness"))
    .evaluator(evaluators::no_error())
    .sink(Markdown::stdout())
    .run()
    .await?;
```

The agent must leave spans AgentCore Evaluations can read: deploy it with
[rig-agentcore](https://crates.io/crates/rig-agentcore), export with [rig-otel](https://crates.io/crates/rig-otel)'s `aws` feature,
and record content (`record_content(true)`), so the spans carry the prompts and answers.
Transaction Search must be on in the account.

The caller needs `bedrock-agentcore:InvokeAgentRuntime` on the runtime,
`bedrock-agentcore:Evaluate`, and `logs:StartQuery` and `logs:GetQueryResults` on both log
groups. `.ingestion_timeout`, `.poll_interval` and `.runtime_log_group` (for trials of
another target, given a session id) tune the evaluator; `.qualifier` picks another
runtime endpoint.

Langfuse scores as a `Sink` come next.

## Testing

`cargo test --all-features` runs keyless: agents on scripted models, a scripted judge, and
in-memory OpenTelemetry exporters for the evaluation events. The AgentCore suite runs
against a real runtime only when `RIG_EVALS_AGENTCORE_RUNTIME_ARN` is set (with AWS
credentials and region), and skips otherwise.