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    /// Agents in this group.
43    pub agents: Vec<OxiosGroupAgent>,
44}
45
46impl OxiosAgentGroup {
47    /// Get all pending agents.
48    pub fn pending_agents(&self) -> Vec<&OxiosGroupAgent> {
49        self.agents
50            .iter()
51            .filter(|a| a.status == OxiosAgentGroupStatus::Pending)
52            .collect()
53    }
54
55    /// Get all completed agents.
56    pub fn completed_agents(&self) -> Vec<&OxiosGroupAgent> {
57        self.agents
58            .iter()
59            .filter(|a| a.status == OxiosAgentGroupStatus::Completed)
60            .collect()
61    }
62
63    /// Get all failed agents.
64    pub fn failed_agents(&self) -> Vec<&OxiosGroupAgent> {
65        self.agents
66            .iter()
67            .filter(|a| a.status == OxiosAgentGroupStatus::Failed)
68            .collect()
69    }
70
71    /// Check if all agents in the group have completed.
72    pub fn all_completed(&self) -> bool {
73        self.agents
74            .iter()
75            .all(|a| a.status == OxiosAgentGroupStatus::Completed)
76    }
77
78    /// Check if any agent has failed.
79    pub fn any_failed(&self) -> bool {
80        self.agents
81            .iter()
82            .any(|a| a.status == OxiosAgentGroupStatus::Failed)
83    }
84
85    /// Get completion percentage.
86    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    /// Combine results from all completed agents.
99    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}