#[non_exhaustive]pub struct SamplingPolicy {
pub rate: f64,
pub seed: u64,
pub agents: Vec<String>,
pub metadata: Vec<MetadataFilter>,
pub outcomes: Vec<RunOutcome>,
}Expand description
Which finished runs online evaluation samples.
A run is sampled when its agent, request metadata and outcome pass the filters (an empty filter passes everything) and its sample point falls under the rate. The sample point is a deterministic hash of the seed and the run’s invocation id, so the same seed samples the same runs in every process and on every replay, and a different seed samples a different set of the same size.
§Example
use adk_eval::online::{RunOutcome, SamplingPolicy};
let policy = SamplingPolicy::rate(0.25)?
.with_seed(42)
.agent("support")
.tag("tier", Some("gold"))
.outcome(RunOutcome::Completed);
let sampled = (0..1_000)
.filter(|run| policy.sample_point(&format!("inv-{run}")) < 0.25)
.count();
assert!((200..300).contains(&sampled));
assert_eq!(policy.sample_point("inv-7"), policy.sample_point("inv-7"));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.rate: f64Fraction of runs to sample, from 0.0 (none) to 1.0 (every run).
seed: u64Seed of the sample point hash.
agents: Vec<String>Root agents whose runs may be sampled; empty means every agent.
metadata: Vec<MetadataFilter>Request-metadata conditions a run must all meet; empty means any metadata.
outcomes: Vec<RunOutcome>Outcomes a run must end with; empty means any outcome.
Implementations§
Source§impl SamplingPolicy
impl SamplingPolicy
Sourcepub fn rate(rate: f64) -> Result<Self>
pub fn rate(rate: f64) -> Result<Self>
Samples rate of runs, from 0.0 to 1.0, with seed 0 and no filters.
§Errors
Returns EvalError::ConfigError when rate is not between 0.0 and 1.0.
Sourcepub fn agent(self, name: impl Into<String>) -> Self
pub fn agent(self, name: impl Into<String>) -> Self
Admits runs of the agent named name (repeatable).
Sourcepub fn tag(self, key: impl Into<String>, value: Option<&str>) -> Self
pub fn tag(self, key: impl Into<String>, value: Option<&str>) -> Self
Requires request metadata key, with value when one is given (repeatable).
Sourcepub fn outcome(self, outcome: RunOutcome) -> Self
pub fn outcome(self, outcome: RunOutcome) -> Self
Admits runs that end with outcome (repeatable).
Sourcepub fn sample_point(&self, invocation_id: &str) -> f64
pub fn sample_point(&self, invocation_id: &str) -> f64
The run’s deterministic sample point in [0, 1).
Sourcepub fn admits_run(
&self,
agent: &str,
metadata: &HashMap<String, String>,
invocation_id: &str,
) -> bool
pub fn admits_run( &self, agent: &str, metadata: &HashMap<String, String>, invocation_id: &str, ) -> bool
Whether a run of agent with metadata and invocation_id is sampled, before its
outcome is known.
Sourcepub fn admits_outcome(&self, outcome: RunOutcome) -> bool
pub fn admits_outcome(&self, outcome: RunOutcome) -> bool
Whether a run that ended with outcome is evaluated.
Sourcepub fn admits(&self, trace: &RunTrace) -> bool
pub fn admits(&self, trace: &RunTrace) -> bool
Whether trace is sampled: admits_run and
admits_outcome.