Skip to main content

swarm_engine_core/agent/
escalation.rs

1//! Escalation - Worker から Manager への介入要求
2
3/// Escalation 理由
4///
5/// Worker が Manager に介入を求める理由。
6/// システム検知(連続失敗)と Agent 申告の両方をサポート。
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum EscalationReason {
9    /// 連続失敗(システムが自動検知)
10    ConsecutiveFailures(u32),
11    /// リソース不足
12    ResourceExhausted,
13    /// タイムアウト
14    Timeout,
15    /// Agent 自身の判断による申告
16    AgentRequested(String),
17    /// 不明なエラー
18    Unknown(String),
19}
20
21/// Escalation 情報(WorkerState に保存)
22#[derive(Debug, Clone)]
23pub struct Escalation {
24    /// 理由
25    pub reason: EscalationReason,
26    /// 発生 tick
27    pub raised_at_tick: u64,
28    /// 追加コンテキスト
29    pub context: Option<String>,
30}
31
32impl Escalation {
33    /// 連続失敗による Escalation を作成
34    pub fn consecutive_failures(count: u32, tick: u64) -> Self {
35        Self {
36            reason: EscalationReason::ConsecutiveFailures(count),
37            raised_at_tick: tick,
38            context: None,
39        }
40    }
41
42    /// Agent 申告による Escalation を作成
43    pub fn agent_requested(reason: impl Into<String>, tick: u64) -> Self {
44        Self {
45            reason: EscalationReason::AgentRequested(reason.into()),
46            raised_at_tick: tick,
47            context: None,
48        }
49    }
50
51    /// コンテキストを追加
52    pub fn with_context(mut self, ctx: impl Into<String>) -> Self {
53        self.context = Some(ctx.into());
54        self
55    }
56}