gemini_adk_rs/evaluation/
evaluator.rs

1//! Core evaluator trait — base interface for all evaluators.
2
3use async_trait::async_trait;
4
5use super::eval_case::Invocation;
6use super::eval_result::EvalResult;
7
8/// Errors from evaluation operations.
9#[derive(Debug, thiserror::Error)]
10pub enum EvalError {
11    /// The evaluator encountered an error during evaluation.
12    #[error("Evaluation error: {0}")]
13    Evaluation(String),
14    /// The LLM call failed.
15    #[error("LLM error: {0}")]
16    Llm(String),
17    /// Invalid input.
18    #[error("Invalid input: {0}")]
19    InvalidInput(String),
20    /// I/O error (file read/write).
21    #[error("IO error: {0}")]
22    Io(String),
23    /// Parse error (JSON, config, evalset).
24    #[error("Parse error: {0}")]
25    Parse(String),
26}
27
28/// Trait for evaluating agent invocations against expected results.
29///
30/// Mirrors ADK-Python's `Evaluator` abstract class.
31#[async_trait]
32pub trait Evaluator: Send + Sync {
33    /// Evaluate agent invocations.
34    ///
35    /// # Arguments
36    /// * `actual` — The agent's actual invocations.
37    /// * `expected` — Optional expected (golden) invocations for comparison.
38    ///
39    /// # Returns
40    /// An [`EvalResult`] containing per-metric and overall scores.
41    async fn evaluate(
42        &self,
43        actual: &[Invocation],
44        expected: Option<&[Invocation]>,
45    ) -> Result<EvalResult, EvalError>;
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    fn _assert_object_safe(_: &dyn Evaluator) {}
53
54    #[test]
55    fn evaluator_is_object_safe() {
56        // Compile-time check only
57    }
58
59    #[test]
60    fn eval_error_display() {
61        let err = EvalError::Evaluation("test".into());
62        assert!(err.to_string().contains("test"));
63    }
64}