oxios_kernel/
agent_group.rs1use serde::{Deserialize, Serialize};
9use uuid::Uuid;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13pub enum OxiosAgentGroupStatus {
14 Pending,
16 Running,
18 Completed,
20 Failed,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct OxiosGroupAgent {
27 pub id: Uuid,
29 pub goal: String,
31 pub status: OxiosAgentGroupStatus,
33 pub result: Option<String>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct OxiosAgentGroup {
40 pub id: Uuid,
42 pub parent_seed_id: Uuid,
44 pub agents: Vec<OxiosGroupAgent>,
46}
47
48impl OxiosAgentGroup {
49 pub fn pending_agents(&self) -> Vec<&OxiosGroupAgent> {
51 self.agents
52 .iter()
53 .filter(|a| a.status == OxiosAgentGroupStatus::Pending)
54 .collect()
55 }
56
57 pub fn completed_agents(&self) -> Vec<&OxiosGroupAgent> {
59 self.agents
60 .iter()
61 .filter(|a| a.status == OxiosAgentGroupStatus::Completed)
62 .collect()
63 }
64
65 pub fn failed_agents(&self) -> Vec<&OxiosGroupAgent> {
67 self.agents
68 .iter()
69 .filter(|a| a.status == OxiosAgentGroupStatus::Failed)
70 .collect()
71 }
72
73 pub fn all_completed(&self) -> bool {
75 self.agents
76 .iter()
77 .all(|a| a.status == OxiosAgentGroupStatus::Completed)
78 }
79
80 pub fn any_failed(&self) -> bool {
82 self.agents
83 .iter()
84 .any(|a| a.status == OxiosAgentGroupStatus::Failed)
85 }
86
87 pub fn completion_pct(&self) -> f64 {
89 if self.agents.is_empty() {
90 return 0.0;
91 }
92 let completed = self
93 .agents
94 .iter()
95 .filter(|a| a.status == OxiosAgentGroupStatus::Completed)
96 .count();
97 completed as f64 / self.agents.len() as f64
98 }
99
100 pub fn combined_results(&self) -> String {
102 self.completed_agents()
103 .iter()
104 .filter_map(|a| a.result.as_ref())
105 .map(|r| r.as_str())
106 .collect::<Vec<_>>()
107 .join("\n\n")
108 }
109}
110
111#[cfg(test)]
112mod tests {
113 use super::*;
114
115 #[test]
116 fn test_completion_pct_empty_group() {
117 let group = OxiosAgentGroup {
118 id: Uuid::new_v4(),
119 parent_seed_id: Uuid::new_v4(),
120 agents: vec![],
121 };
122 assert!((group.completion_pct() - 0.0).abs() < f64::EPSILON);
123 }
124}