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 agents: Vec<OxiosGroupAgent>,
44}
45
46impl OxiosAgentGroup {
47 pub fn pending_agents(&self) -> Vec<&OxiosGroupAgent> {
49 self.agents
50 .iter()
51 .filter(|a| a.status == OxiosAgentGroupStatus::Pending)
52 .collect()
53 }
54
55 pub fn completed_agents(&self) -> Vec<&OxiosGroupAgent> {
57 self.agents
58 .iter()
59 .filter(|a| a.status == OxiosAgentGroupStatus::Completed)
60 .collect()
61 }
62
63 pub fn failed_agents(&self) -> Vec<&OxiosGroupAgent> {
65 self.agents
66 .iter()
67 .filter(|a| a.status == OxiosAgentGroupStatus::Failed)
68 .collect()
69 }
70
71 pub fn all_completed(&self) -> bool {
73 self.agents
74 .iter()
75 .all(|a| a.status == OxiosAgentGroupStatus::Completed)
76 }
77
78 pub fn any_failed(&self) -> bool {
80 self.agents
81 .iter()
82 .any(|a| a.status == OxiosAgentGroupStatus::Failed)
83 }
84
85 pub fn completion_pct(&self) -> f64 {
87 if self.agents.is_empty() {
88 return 0.0;
89 }
90 let completed = self
91 .agents
92 .iter()
93 .filter(|a| a.status == OxiosAgentGroupStatus::Completed)
94 .count();
95 completed as f64 / self.agents.len() as f64
96 }
97
98 pub fn combined_results(&self) -> String {
100 self.completed_agents()
101 .iter()
102 .filter_map(|a| a.result.as_ref())
103 .map(|r| r.as_str())
104 .collect::<Vec<_>>()
105 .join("\n\n")
106 }
107}
108
109#[cfg(test)]
110mod tests {
111 use super::*;
112
113 #[test]
114 fn test_completion_pct_empty_group() {
115 let group = OxiosAgentGroup {
116 id: Uuid::new_v4(),
117 agents: vec![],
118 };
119 assert!((group.completion_pct() - 0.0).abs() < f64::EPSILON);
120 }
121}