Skip to main content

oxios_kernel/
agent_group.rs

1//! Agent group types for oxios orchestration.
2//!
3//! Defines the data structures for multi-agent groups persisted to the state
4//! store. The group creation logic (`delegate_subtasks`) was removed during
5//! the RFC-027 migration; these types remain for reading historical data
6//! from the state store via the `/api/agent-groups` API.
7
8use serde::{Deserialize, Serialize};
9use uuid::Uuid;
10
11/// Status of an agent within a group.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13pub enum OxiosAgentGroupStatus {
14    /// Agent is pending execution.
15    Pending,
16    /// Agent is currently running.
17    Running,
18    /// Agent completed successfully.
19    Completed,
20    /// Agent failed.
21    Failed,
22}
23
24/// A single agent's entry in a group.
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct OxiosGroupAgent {
27    /// Unique ID for this group agent.
28    pub id: Uuid,
29    /// The goal this agent was assigned.
30    pub goal: String,
31    /// Current status.
32    pub status: OxiosAgentGroupStatus,
33    /// Result output (when completed).
34    pub result: Option<String>,
35}
36
37/// A group of agents executing in parallel.
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct OxiosAgentGroup {
40    /// Unique group ID.
41    pub id: Uuid,
42    /// The parent ID that spawned this group.
43    pub parent_seed_id: Uuid,
44    /// Agents in this group.
45    pub agents: Vec<OxiosGroupAgent>,
46}
47
48impl OxiosAgentGroup {
49    /// Get all pending agents.
50    pub fn pending_agents(&self) -> Vec<&OxiosGroupAgent> {
51        self.agents
52            .iter()
53            .filter(|a| a.status == OxiosAgentGroupStatus::Pending)
54            .collect()
55    }
56
57    /// Get all completed agents.
58    pub fn completed_agents(&self) -> Vec<&OxiosGroupAgent> {
59        self.agents
60            .iter()
61            .filter(|a| a.status == OxiosAgentGroupStatus::Completed)
62            .collect()
63    }
64
65    /// Get all failed agents.
66    pub fn failed_agents(&self) -> Vec<&OxiosGroupAgent> {
67        self.agents
68            .iter()
69            .filter(|a| a.status == OxiosAgentGroupStatus::Failed)
70            .collect()
71    }
72
73    /// Check if all agents in the group have completed.
74    pub fn all_completed(&self) -> bool {
75        self.agents
76            .iter()
77            .all(|a| a.status == OxiosAgentGroupStatus::Completed)
78    }
79
80    /// Check if any agent has failed.
81    pub fn any_failed(&self) -> bool {
82        self.agents
83            .iter()
84            .any(|a| a.status == OxiosAgentGroupStatus::Failed)
85    }
86
87    /// Get completion percentage.
88    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    /// Combine results from all completed agents.
101    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}