Skip to main content

starweaver_core/
lifecycle.rs

1//! Shared run lifecycle vocabulary.
2
3use serde::{Deserialize, Serialize};
4
5/// Named execution boundary in the agent loop and durable stream protocol.
6#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
7#[serde(rename_all = "snake_case")]
8pub enum AgentExecutionNode {
9    /// Run initialization completed.
10    RunStart,
11    /// The next model request is about to be prepared.
12    PrepareModelRequest,
13    /// The model request is about to be sent or skipped by policy.
14    BeforeModelRequest,
15    /// A model response has been applied to state.
16    ModelResponse,
17    /// A function tool call is about to execute.
18    ToolCall,
19    /// A function tool result has been applied to state.
20    ToolReturn,
21    /// Final output validation is about to run.
22    ValidateOutput,
23    /// The run completed.
24    RunComplete,
25    /// The run failed.
26    RunFailed,
27}
28
29/// Lifecycle of an admitted runtime execution.
30#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
31#[serde(rename_all = "snake_case")]
32pub enum RunLifecycle {
33    /// Runtime initialization is in progress.
34    Starting,
35    /// Runtime is actively executing.
36    Running,
37    /// Runtime is waiting for external work or a decision.
38    Waiting,
39    /// Runtime completed successfully.
40    Completed,
41    /// Runtime failed.
42    Failed,
43    /// Runtime was cancelled or interrupted.
44    Cancelled,
45}
46
47impl RunLifecycle {
48    /// Return the stable wire name.
49    #[must_use]
50    pub const fn as_str(self) -> &'static str {
51        match self {
52            Self::Starting => "starting",
53            Self::Running => "running",
54            Self::Waiting => "waiting",
55            Self::Completed => "completed",
56            Self::Failed => "failed",
57            Self::Cancelled => "cancelled",
58        }
59    }
60
61    /// Return whether this lifecycle is terminal.
62    #[must_use]
63    pub const fn is_terminal(self) -> bool {
64        matches!(self, Self::Completed | Self::Failed | Self::Cancelled)
65    }
66}