Skip to main content

rs_adk/optimization/
sampler.rs

1//! Sampler trait — provides evaluation examples for optimization.
2
3use async_trait::async_trait;
4
5use super::optimizer::OptimizerError;
6use crate::evaluation::EvalCase;
7
8/// A sample drawn from the evaluation set for optimization.
9#[derive(Debug, Clone)]
10pub struct EvalSample {
11    /// The evaluation cases in this sample.
12    pub cases: Vec<EvalCase>,
13    /// IDs of the sampled cases.
14    pub case_ids: Vec<String>,
15}
16
17/// Trait for sampling evaluation examples during optimization.
18///
19/// Implementations provide training/validation splits and scoring.
20#[async_trait]
21pub trait Sampler: Send + Sync {
22    /// Sample a batch of training examples.
23    async fn sample_training(&self, batch_size: usize) -> Result<EvalSample, OptimizerError>;
24
25    /// Get the full validation set.
26    async fn validation_set(&self) -> Result<EvalSample, OptimizerError>;
27
28    /// Score an agent instruction against a set of evaluation cases.
29    ///
30    /// Returns a score between 0.0 and 1.0.
31    async fn score(
32        &self,
33        instruction: &str,
34        model_id: &str,
35        cases: &[EvalCase],
36    ) -> Result<f64, OptimizerError>;
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    fn _assert_object_safe(_: &dyn Sampler) {}
44}