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//! # async fn run(agent: rig_agent::Agent) -> Result<(), Box<dyn std::error::Error>> {
11//! let report = Experiment::new("support-bot")
12//!     .dataset(Dataset::load("evals/cases.jsonl")?)
13//!     .target(agent)
14//!     .evaluator(evaluators::contains("refund"))
15//!     .evaluator(evaluators::no_error())
16//!     .repetitions(3)
17//!     .threshold("contains", 0.8)
18//!     .sink(JunitFile::new("target/evals/junit.xml"))
19//!     .run()
20//!     .await?;
21//! std::process::exit(if report.passed() { 0 } else { 1 });
22//! # }
23//! ```
24//!
25//! With the `agentcore` feature, `AgentCore` makes a runtime on AWS Bedrock
26//! AgentCore a target, and AgentCore Evaluations' evaluators evaluators.
27//!
28//! Each run is a `tracing` span `eval.trial` inside an `eval.experiment` span,
29//! and each score an OpenTelemetry GenAI `gen_ai.evaluation.result` event on
30//! it, so a tracing exporter (such as rig-otel) puts the results on the
31//! evaluated agent's trace.
32
33#![forbid(unsafe_code)]
34#![cfg_attr(docsrs, feature(doc_cfg))]
35#![cfg_attr(
36    test,
37    allow(
38        clippy::expect_used,
39        clippy::panic,
40        clippy::unwrap_used,
41        clippy::unreachable
42    )
43)]
44
45#[cfg(feature = "agentcore")]
46mod agentcore;
47mod case;
48mod evaluator;
49pub mod evaluators;
50mod experiment;
51mod report;
52mod sink;
53mod target;
54
55#[cfg(feature = "agentcore")]
56pub use agentcore::{AgentCore, AgentCoreError, AgentCoreEvaluator, AgentCoreTarget};
57pub use case::{Case, Dataset, DatasetError, ExpectedCall};
58pub use evaluator::{EvalError, Evaluator, Named, Score};
59pub use evaluators::{LlmJudge, Verdict};
60pub use experiment::{Experiment, ExperimentError};
61pub use report::{
62    EvaluatorSummary, LatencySummary, Report, ThresholdResult, Tokens, Trial, TrialResult,
63};
64pub use sink::{JsonFile, JunitFile, Markdown, Sink, SinkError};
65pub use target::{FnTarget, Target, TargetError, TargetOutput, ToolCall, target_fn};
66#[cfg(feature = "multiagent")]
67pub use target::{NodeTarget, node_target};