Skip to main content

jamjet_agents/
lifecycle.rs

1use serde::{Deserialize, Serialize};
2
3/// Lifecycle state of a registered agent.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum AgentStatus {
7    /// Registered but not yet accepting tasks.
8    Registered,
9    /// Accepting and executing tasks.
10    Active,
11    /// Not accepting new tasks; existing tasks continue.
12    Paused,
13    /// Draining in-flight tasks; will become archived once drained.
14    Deactivated,
15    /// No longer active. Kept for historical reference.
16    Archived,
17}
18
19impl AgentStatus {
20    pub fn can_accept_tasks(&self) -> bool {
21        matches!(self, Self::Active)
22    }
23
24    pub fn validate_transition(&self, next: &AgentStatus) -> Result<(), String> {
25        let valid = matches!(
26            (self, next),
27            (Self::Registered, Self::Active)
28                | (Self::Active, Self::Paused)
29                | (Self::Active, Self::Deactivated)
30                | (Self::Paused, Self::Active)
31                | (Self::Paused, Self::Deactivated)
32                | (Self::Deactivated, Self::Archived)
33        );
34        if valid {
35            Ok(())
36        } else {
37            Err(format!(
38                "invalid agent status transition: {self:?} → {next:?}"
39            ))
40        }
41    }
42}