1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Online evaluation: judge a sampled fraction of production runs after they finish.
//!
//! Offline evaluation replays an eval set; online evaluation scores the runs real users
//! started. An [`OnlineEvaluator`] decides at the start of each run whether to sample it
//! ([`SamplingPolicy`]: a seeded rate plus filters by agent, request metadata and outcome),
//! buffers the sampled run's events, and once the run has finished hands a [`RunTrace`] to a
//! background worker. The worker scores it with reference-free criteria, records an
//! [`OnlineEvalRecord`] in an [`OnlineEvalStore`] and as `gen_ai.evaluation.result` telemetry,
//! and never touches the request path: the run's own stream only pays for a channel send.
//!
//! | Criterion | Source | Needs a judge |
//! |-----------|--------|---------------|
//! | `rubric_quality_score` with `rubric_config` | [`LlmJudge::evaluate_rubrics`](crate::LlmJudge::evaluate_rubrics), the user message as context | yes |
//! | `safety_score` | [`LlmJudge::evaluate_safety`](crate::LlmJudge::evaluate_safety) | yes |
//! | `hallucination_score` | [`LlmJudge::detect_hallucinations`](crate::LlmJudge::detect_hallucinations), no ground truth | yes |
//! | [`OnlineEvalConfig::min_trajectory_efficiency`] | [`TraceAnalyzer`](crate::TraceAnalyzer) over the run's tool calls | no |
//! | [`OnlineEvalConfig::thread`] | [`ConversationScorer`](crate::ConversationScorer) over the whole session: context retention, goal completion, coherence, topic drift | yes |
//!
//! Criteria that compare against an expected answer (`tool_trajectory_score`,
//! `response_similarity`, `semantic_match_score`) cannot apply to production traffic and
//! are refused when the evaluator is built.
//!
//! # Governance
//!
//! - **Opt-in.** Nothing is sampled until an application builds an evaluator and installs
//! its [`plugin`](OnlineEvaluator::plugin) on a runner, or calls
//! [`submit`](OnlineEvaluator::submit) itself.
//! - **Its own budget.** Every judge call counts against the evaluator's
//! [`OnlineEvalConfig::budget`] (one tracker for the evaluator's lifetime) and, when one is
//! set, a spend ledger under the agent [`ONLINE_EVAL_AGENT_NAME`]; a refused call stops that
//! evaluation and records nothing. Once the budget is spent, runs are no longer sampled.
//! - **Kill switch.** The evaluator's own controls and the run's
//! ([`RunConfig::governance`](adk_core::RunConfig::governance)) are checked when a run is
//! sampled, before it is evaluated, and before every judge call.
//!
//! # Example
//!
//! ```rust,no_run
//! use std::sync::Arc;
//!
//! use adk_core::{Llm, RunBudget};
//! use adk_eval::EvaluationCriteria;
//! use adk_eval::online::{
//! InMemoryOnlineEvalStore, OnlineEvalConfig, OnlineEvaluator, RunOutcome, SamplingPolicy,
//! };
//! use adk_plugin::PluginManager;
//!
//! async fn install(judge: Arc<dyn Llm>) -> adk_eval::Result<Arc<PluginManager>> {
//! // Judge 10% of the support agent's completed runs, at most 200 judge calls.
//! let sampling = SamplingPolicy::rate(0.10)?
//! .with_seed(7)
//! .agent("support")
//! .outcome(RunOutcome::Completed);
//! let config = OnlineEvalConfig::new(sampling)
//! .with_criteria(EvaluationCriteria { safety_score: Some(0.9), ..Default::default() })
//! .with_min_trajectory_efficiency(0.5)
//! .with_budget(RunBudget::new().max_model_calls(200));
//! let evaluator = OnlineEvaluator::builder(config)
//! .judge(judge)
//! .store(Arc::new(InMemoryOnlineEvalStore::new(1_000)))
//! .start()?;
//! // Runner::builder().plugin_manager(manager) ...
//! Ok(Arc::new(PluginManager::new(vec![evaluator.plugin()])))
//! }
//! ```
pub use ;
pub use ;
pub use ;
/// Telemetry attribute names of the OpenTelemetry GenAI evaluation event
/// (`gen_ai.evaluation.result`), which online evaluation emits once per scored criterion.