Skip to main content

systemprompt_agent/services/agent_orchestration/
mod.rs

1pub mod database;
2pub mod event_bus;
3pub mod events;
4pub mod lifecycle;
5pub mod monitor;
6pub mod orchestrator;
7pub mod port_manager;
8pub mod process;
9pub mod reconciler;
10
11use systemprompt_identifiers::AgentId;
12
13pub use event_bus::AgentEventBus;
14pub use events::AgentEvent;
15pub use orchestrator::{AgentInfo, AgentOrchestrator};
16pub use port_manager::PortManager;
17
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum AgentStatus {
20    Running {
21        pid: u32,
22        port: u16,
23    },
24    Failed {
25        reason: String,
26        last_attempt: Option<String>,
27        retry_count: u32,
28    },
29}
30
31#[derive(Debug, Clone)]
32pub struct AgentRuntimeConfig {
33    pub id: AgentId,
34    pub name: String,
35    pub port: u16,
36}
37
38#[derive(Debug, Clone)]
39pub struct ValidationReport {
40    pub valid: bool,
41    pub issues: Vec<String>,
42}
43
44impl Default for ValidationReport {
45    fn default() -> Self {
46        Self::new()
47    }
48}
49
50impl ValidationReport {
51    pub const fn new() -> Self {
52        Self {
53            valid: true,
54            issues: Vec::new(),
55        }
56    }
57
58    pub fn with_issue(issue: String) -> Self {
59        Self {
60            valid: false,
61            issues: vec![issue],
62        }
63    }
64
65    pub fn add_issue(&mut self, issue: String) {
66        self.valid = false;
67        self.issues.push(issue);
68    }
69}
70
71use anyhow::Result;
72use thiserror::Error;
73
74#[derive(Error, Debug)]
75pub enum OrchestrationError {
76    #[error("Agent {0} not found")]
77    AgentNotFound(String),
78
79    #[error("Agent {0} already running")]
80    AgentAlreadyRunning(String),
81
82    #[error("Process spawn failed: {0}")]
83    ProcessSpawnFailed(String),
84
85    #[error("Database error: {0}")]
86    DatabaseError(#[from] sqlx::Error),
87
88    #[error("Database error: {0}")]
89    Database(String),
90
91    #[error("IO error: {0}")]
92    IoError(#[from] std::io::Error),
93
94    #[error("Health check timeout for agent {0}")]
95    HealthCheckTimeout(String),
96
97    #[error("Generic error: {0}")]
98    Generic(#[from] anyhow::Error),
99}
100
101pub type OrchestrationResult<T> = Result<T, OrchestrationError>;