Skip to main content

rig_evals/
lib.rs

1//! Evaluations for [Rig](https://github.com/0xPlaygrounds/rig) agents.
2//!
3//! An [`Experiment`] runs a [`Target`] (a Rig agent, an async function, or,
4//! with the `multiagent` feature, a swarm or graph) on every [`Case`] of a
5//! [`Dataset`], scores each run with [`Evaluator`]s, and hands the
6//! [`Report`] to [`Sink`]s.
7//!
8//! ```no_run
9//! use rig_evals::{Dataset, Experiment, JunitFile, evaluators};
10//!
11//! async fn run(agent: rig_agent::Agent) -> Result<(), Box<dyn std::error::Error>> {
12//!     let report = Experiment::new("support-bot")
13//!         .dataset(Dataset::load("evals/cases.jsonl")?)
14//!         .target(agent)
15//!         .evaluator(evaluators::contains("refund"))
16//!         .evaluator(evaluators::no_error())
17//!         .repetitions(3)
18//!         .threshold("contains", 0.8)
19//!         .sink(JunitFile::new("target/evals/junit.xml"))
20//!         .run()
21//!         .await?;
22//!     std::process::exit(if report.passed() { 0 } else { 1 });
23//! }
24//! ```
25//!
26//! A dataset is a `.jsonl` file (one case per line) or a `.json` array. A case
27//! has an `id` and either an `input` (one prompt) or `turns` (a conversation).
28//! `expected`, `trajectory` (`name` and optional `args` per tool call),
29//! `assertions` and `metadata` are optional references. A three-case file:
30//!
31//! ```jsonl
32//! {"id": "refund", "input": "Order 7 arrived broken.", "expected": "A refund was issued.", "trajectory": [{"name": "lookup_order", "args": {"id": 7}}, {"name": "refund"}], "assertions": ["apologizes"]}
33//! {"id": "hours", "input": "What are your opening hours?", "expected": "We are open 9 to 5.", "assertions": ["gives the hours"]}
34//! {"id": "city", "turns": ["My favourite city is Lisbon.", "What is my favourite city?"], "expected": "Lisbon"}
35//! ```
36//!
37//! With the `agentcore` feature, `AgentCore` makes a runtime on AWS Bedrock
38//! AgentCore a target, and AgentCore Evaluations' evaluators evaluators.
39//!
40//! Each run is a `tracing` span `eval.trial` inside an `eval.experiment` span,
41//! and each score an OpenTelemetry GenAI `gen_ai.evaluation.result` event on
42//! it, so a tracing exporter (such as rig-otel) puts the results on the
43//! evaluated agent's trace. The agent's prompts and replies reach that trace
44//! only when it records content, with `AgentBuilder::record_content_telemetry(true)`.
45//! A score's explanation (the judge's text) is recorded only with
46//! `Experiment::record_content(true)`.
47
48#![forbid(unsafe_code)]
49#![cfg_attr(docsrs, feature(doc_cfg))]
50#![cfg_attr(
51    test,
52    allow(
53        clippy::expect_used,
54        clippy::panic,
55        clippy::unwrap_used,
56        clippy::unreachable
57    )
58)]
59
60#[cfg(feature = "agentcore")]
61mod agentcore;
62mod case;
63mod evaluator;
64pub mod evaluators;
65mod experiment;
66mod report;
67mod sink;
68mod target;
69
70#[cfg(feature = "agentcore")]
71pub use agentcore::{AgentCore, AgentCoreError, AgentCoreEvaluator, AgentCoreTarget};
72pub use case::{Case, Dataset, DatasetError, ExpectedCall};
73pub use evaluator::{EvalError, Evaluator, Named, Score};
74pub use evaluators::{LlmJudge, Verdict};
75pub use experiment::{Experiment, ExperimentError};
76pub use report::{
77    CaseChange, Comparison, EvaluatorDelta, EvaluatorSummary, LatencySummary, Report,
78    ThresholdResult, Tokens, Trial, TrialResult,
79};
80pub use sink::{JsonFile, JunitFile, Markdown, Sink, SinkError};
81pub use target::{
82    FnTarget, Target, TargetError, TargetOutput, ToolCall, Turn, TurnFailed, target_fn,
83};
84#[cfg(feature = "multiagent")]
85pub use target::{NodeTarget, node_target};
86
87// The README's AgentCore example needs the `agentcore` feature, so the
88// README is compile-checked only with it enabled (CI uses --all-features).
89#[cfg(all(doctest, feature = "agentcore"))]
90#[doc = include_str!("../README.md")]
91mod readme_doctests {}