swarm-engine-core 0.1.6

Core types and orchestration for SwarmEngine
Documentation
//! StrategyAdviceRecord - LLM 戦略アドバイスの記録
//!
//! `LearningEvent::StrategyAdvice` から `From` で変換される。

use serde::{Deserialize, Serialize};

use crate::events::LearningEvent;

/// LLM 戦略アドバイス記録
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StrategyAdviceRecord {
    /// タイムスタンプ(Unix epoch ms)
    pub timestamp_ms: u64,
    /// Tick 番号
    pub tick: u64,
    /// アドバイザー名
    pub advisor: String,
    /// 現在の戦略
    pub current_strategy: String,
    /// 推奨戦略
    pub recommended: String,
    /// 変更すべきか
    pub should_change: bool,
    /// 信頼度 (0.0-1.0)
    pub confidence: f64,
    /// 理由
    pub reason: String,
    /// フロンティア数
    pub frontier_count: usize,
    /// 総訪問数
    pub total_visits: u32,
    /// 失敗率 (0.0-1.0)
    pub failure_rate: f64,
    /// レイテンシ(ms)
    pub latency_ms: u64,
    /// 成功したか
    pub success: bool,
    /// エラー(失敗時のみ)
    pub error: Option<String>,
}

impl From<&LearningEvent> for StrategyAdviceRecord {
    fn from(event: &LearningEvent) -> Self {
        match event {
            LearningEvent::StrategyAdvice {
                timestamp_ms,
                tick,
                advisor,
                current_strategy,
                recommended,
                should_change,
                confidence,
                reason,
                frontier_count,
                total_visits,
                failure_rate,
                latency_ms,
                success,
                error,
            } => Self {
                timestamp_ms: *timestamp_ms,
                tick: *tick,
                advisor: advisor.clone(),
                current_strategy: current_strategy.clone(),
                recommended: recommended.clone(),
                should_change: *should_change,
                confidence: *confidence,
                reason: reason.clone(),
                frontier_count: *frontier_count,
                total_visits: *total_visits,
                failure_rate: *failure_rate,
                latency_ms: *latency_ms,
                success: *success,
                error: error.clone(),
            },
            _ => panic!("StrategyAdviceRecord::from() requires StrategyAdvice event"),
        }
    }
}

impl StrategyAdviceRecord {
    /// 成功かどうか
    pub fn is_success(&self) -> bool {
        self.success
    }

    /// 戦略変更が推奨されたか
    pub fn recommends_change(&self) -> bool {
        self.should_change
    }
}