tirea_contract/runtime/phase/
types.rs1pub use crate::runtime::run::flow::RunAction;
2pub use crate::runtime::tool_call::gate::{SuspendTicket, ToolCallAction};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum Phase {
7 RunStart,
9 StepStart,
11 BeforeInference,
13 AfterInference,
15 BeforeToolExecute,
17 AfterToolExecute,
19 StepEnd,
21 RunEnd,
23}
24
25impl std::fmt::Display for Phase {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 Self::RunStart => write!(f, "RunStart"),
29 Self::StepStart => write!(f, "StepStart"),
30 Self::BeforeInference => write!(f, "BeforeInference"),
31 Self::AfterInference => write!(f, "AfterInference"),
32 Self::BeforeToolExecute => write!(f, "BeforeToolExecute"),
33 Self::AfterToolExecute => write!(f, "AfterToolExecute"),
34 Self::StepEnd => write!(f, "StepEnd"),
35 Self::RunEnd => write!(f, "RunEnd"),
36 }
37 }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub struct PhasePolicy {
43 pub allow_tool_filter_mutation: bool,
45 pub allow_run_action_mutation: bool,
47 pub allow_tool_gate_mutation: bool,
49}
50
51impl PhasePolicy {
52 pub const fn read_only() -> Self {
53 Self {
54 allow_tool_filter_mutation: false,
55 allow_run_action_mutation: false,
56 allow_tool_gate_mutation: false,
57 }
58 }
59}
60
61impl Phase {
62 pub const fn policy(self) -> PhasePolicy {
64 match self {
65 Self::BeforeInference => PhasePolicy {
66 allow_tool_filter_mutation: true,
67 allow_run_action_mutation: true,
68 allow_tool_gate_mutation: false,
69 },
70 Self::AfterInference => PhasePolicy {
71 allow_tool_filter_mutation: false,
72 allow_run_action_mutation: true,
73 allow_tool_gate_mutation: false,
74 },
75 Self::BeforeToolExecute => PhasePolicy {
76 allow_tool_filter_mutation: false,
77 allow_run_action_mutation: false,
78 allow_tool_gate_mutation: true,
79 },
80 Self::RunStart
81 | Self::StepStart
82 | Self::AfterToolExecute
83 | Self::StepEnd
84 | Self::RunEnd => PhasePolicy::read_only(),
85 }
86 }
87}
88
89#[derive(Debug, Clone, PartialEq)]
91pub enum StepOutcome {
92 Continue,
94 Complete,
96 Pending(Box<SuspendTicket>),
98}