llm_optimizer_processor/decision/traits.rs
1//! Decision Engine core traits
2
3use async_trait::async_trait;
4
5use super::error::{DecisionError, DecisionResult, DecisionState};
6use super::types::{Decision, DecisionCriteria, DecisionInput, DecisionOutcome, DecisionStats};
7
8/// Core trait for the Decision Engine
9#[async_trait]
10pub trait DecisionEngine: Send + Sync {
11 /// Get the name of this decision engine
12 fn name(&self) -> &str;
13
14 /// Get the current state
15 fn state(&self) -> DecisionState;
16
17 /// Start the decision engine
18 async fn start(&mut self) -> DecisionResult<()>;
19
20 /// Stop the decision engine
21 async fn stop(&mut self) -> DecisionResult<()>;
22
23 /// Make decisions based on analyzer input
24 ///
25 /// # Arguments
26 /// * `input` - Input from the analyzer engine
27 /// * `criteria` - Decision criteria to use
28 ///
29 /// # Returns
30 /// Vector of decisions to execute
31 async fn make_decisions(
32 &mut self,
33 input: DecisionInput,
34 criteria: &DecisionCriteria,
35 ) -> DecisionResult<Vec<Decision>>;
36
37 /// Record the outcome of a decision
38 async fn record_outcome(&mut self, outcome: DecisionOutcome) -> DecisionResult<()>;
39
40 /// Get decision statistics
41 fn get_stats(&self) -> DecisionStats;
42
43 /// Health check
44 async fn health_check(&self) -> DecisionResult<()>;
45
46 /// Reset the decision engine state
47 async fn reset(&mut self) -> DecisionResult<()>;
48}
49
50/// Trait for optimization strategies
51#[async_trait]
52pub trait OptimizationStrategy: Send + Sync {
53 /// Get the name of this strategy
54 fn name(&self) -> &str;
55
56 /// Get the priority of this strategy (higher = more important)
57 fn priority(&self) -> u32;
58
59 /// Check if this strategy is applicable to the given input
60 fn is_applicable(&self, input: &DecisionInput) -> bool;
61
62 /// Evaluate and generate decisions
63 ///
64 /// # Arguments
65 /// * `input` - Input from the analyzer engine
66 /// * `criteria` - Decision criteria to use
67 ///
68 /// # Returns
69 /// Vector of decisions this strategy recommends
70 async fn evaluate(
71 &self,
72 input: &DecisionInput,
73 criteria: &DecisionCriteria,
74 ) -> DecisionResult<Vec<Decision>>;
75
76 /// Validate a decision before execution
77 ///
78 /// # Arguments
79 /// * `decision` - The decision to validate
80 /// * `criteria` - Decision criteria to validate against
81 ///
82 /// # Returns
83 /// Ok if valid, Err with reason if invalid
84 async fn validate(
85 &self,
86 decision: &Decision,
87 criteria: &DecisionCriteria,
88 ) -> DecisionResult<()>;
89
90 /// Learn from a decision outcome
91 ///
92 /// # Arguments
93 /// * `decision` - The original decision
94 /// * `outcome` - The outcome that was observed
95 async fn learn(&mut self, decision: &Decision, outcome: &DecisionOutcome)
96 -> DecisionResult<()>;
97
98 /// Get strategy-specific statistics
99 fn get_stats(&self) -> serde_json::Value;
100}
101
102/// Trait for decision validators
103#[async_trait]
104pub trait DecisionValidator: Send + Sync {
105 /// Validate a decision
106 async fn validate(
107 &self,
108 decision: &Decision,
109 criteria: &DecisionCriteria,
110 ) -> DecisionResult<()>;
111}
112
113/// Trait for decision executors (actuators)
114#[async_trait]
115pub trait DecisionExecutor: Send + Sync {
116 /// Execute a decision
117 async fn execute(&self, decision: &Decision) -> DecisionResult<DecisionOutcome>;
118
119 /// Rollback a decision
120 async fn rollback(&self, decision: &Decision) -> DecisionResult<()>;
121}