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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! swarm-engine-eval - Evaluation Framework for SwarmEngine
//!
//! Evaluation framework for multi-agent systems.
//! Builds and executes SwarmApp from TOML scenario definitions for reproducible evaluation.
//!
//! ## Design Philosophy
//!
//! Inspired by Python evaluation frameworks (lm-evaluation-harness, RAGAS, etc.),
//! providing a comprehensive evaluation foundation for Rust/SwarmEngine:
//!
//! 1. **Declarative Scenario Definition**: Describe evaluation conditions and success criteria in TOML
//! 2. **Reproducibility**: Deterministic evaluation execution through seed management
//! 3. **Extensibility**: Plugin architecture via Registry pattern
//! 4. **Statistical Analysis**: Aggregation of N runs, pass@k, confidence intervals
//!
//! ## Architecture
//!
//! ```text
//! ┌────────────────────────────────────────────────────────────────┐
//! │ scenarios/*.toml │
//! │ ┌────────────┐ ┌─────────────┐ ┌────────────┐ ┌─────────┐ │
//! │ │ meta │ │ app_config │ │ agents │ │conditions│ │
//! │ └────────────┘ └─────────────┘ └────────────┘ └─────────┘ │
//! └────────────────────────────────────────────────────────────────┘
//! │
//! ▼
//! ┌────────────────────────────────────────────────────────────────┐
//! │ ScenarioRunner │
//! │ ┌─────────────────┐ ┌──────────────────┐ ┌───────────────┐ │
//! │ │ SwarmRegistry │ │EnvironmentRegistry│ │ Seed Manager │ │
//! │ │ (Agent Factory)│ │ (Fixture Factory)│ │(Reproducibility)│
//! │ └─────────────────┘ └──────────────────┘ └───────────────┘ │
//! │ │ │
//! │ ▼ │
//! │ ┌──────────────────────────────────────────────────────────┐ │
//! │ │ SwarmApp │ │
//! │ │ Workers + Manager + Hooks → Orchestrator → Outcome │ │
//! │ └──────────────────────────────────────────────────────────┘ │
//! │ │ │
//! │ ▼ │
//! │ ┌──────────────────────────────────────────────────────────┐ │
//! │ │ Condition Evaluation Engine │ │
//! │ │ success / failure conditions / timeout / milestone │ │
//! │ └──────────────────────────────────────────────────────────┘ │
//! └────────────────────────────────────────────────────────────────┘
//! │
//! ▼
//! ┌────────────────────────────────────────────────────────────────┐
//! │ EvalReport │
//! │ ConfigSummary + runs[] + AggregatedResults + Assertions │
//! │ ↓ JSON output │
//! │ report.json │
//! └────────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Features
//!
//! - **N-Run Statistical Processing**: Mean, standard deviation, 95% confidence interval
//! - **pass@k Calculation**: Success probability accounting for non-determinism
//! - **Tick-Level Metrics**: latency p95/p99, jitter, miss rate
//! - **Coordination Metrics**: Manager intervention rate, delegation efficiency
//! - **Condition Evaluation**: success/failure conditions, timeout handling, milestones
//! - **Fault Injection**: Effect-based declarative fault injection (TODO)
//!
//! ## Key Components
//!
//! | Module | Description |
//! |--------|-------------|
//! | [`runner`] | ScenarioRunner - Integrated evaluation framework |
//! | [`scenario`] | EvalScenario, Conditions, Milestone definitions |
//! | [`environment`] | EnvironmentRegistry - Evaluation environment factory |
//! | [`swarms`] | SwarmRegistry - Agent generation factory |
//! | [`metrics`] | Task, Coordination, Performance metrics |
//! | [`aggregator`] | Statistical aggregation (pass@k, confidence intervals) |
//! | [`reporter`] | EvalReport, JSON output |
//!
//! ## Usage Examples
//!
//! ### Running Evaluation from TOML Scenario
//!
//! ```ignore
//! use swarm_engine_eval::prelude::*;
//! use swarm_engine_eval::runner::ScenarioRunner;
//!
//! // Load scenario from TOML file
//! let content = std::fs::read_to_string("scenarios/simple_task.toml")?;
//! let scenario: EvalScenario = toml::from_str(&content)?;
//!
//! // Execute evaluation with ScenarioRunner
//! let runner = ScenarioRunner::new(scenario, runtime.handle().clone())
//! .with_runs(5) // Run 5 times
//! .with_seed(42); // Fix seed for reproducibility
//!
//! let report = runner.run()?;
//!
//! // Display results
//! println!("Success rate: {:.1}%", report.aggregated.success_rate * 100.0);
//! println!("Pass@1: {:.1}%", report.aggregated.pass_at_1 * 100.0);
//!
//! // JSON output
//! report.to_json_file("report.json")?;
//! ```
//!
//! ### Programmatic Scenario Definition
//!
//! ```ignore
//! use swarm_engine_eval::scenario::*;
//!
//! let scenario = EvalScenario {
//! meta: ScenarioMeta {
//! name: "My Evaluation".to_string(),
//! id: ScenarioId::new("my:eval:v1"),
//! // ...
//! },
//! app_config: AppConfigTemplate::default(),
//! agents: AgentsConfig {
//! workers: vec![WorkerTemplate {
//! id_pattern: "worker_{i}".to_string(),
//! count: 4,
//! role: "counter".to_string(),
//! config: serde_json::json!({"total_tasks": 10}),
//! }],
//! managers: vec![],
//! },
//! conditions: EvalConditions {
//! success: vec![Condition::new("done", "task.completed_count", CompareOp::Gte, 40)],
//! failure: vec![],
//! on_timeout: TimeoutBehavior::Fail,
//! },
//! // ...
//! };
//! ```
//!
//! ## Future Extensions
//!
//! - [ ] SwarmRegistry: Manager support
//! - [ ] EnvironmentRegistry: task_queue, shared_workspace, etc.
//! - [ ] Comparator: Multi-scenario/configuration comparison
//! - [ ] FaultInjector: Fault injection framework
/// Prelude - commonly used types for convenient import
// Re-exports
pub use ;