pub struct PhaseMachine { /* private fields */ }Expand description
Evaluates transitions and manages phase entry/exit lifecycle.
Implementations§
Source§impl PhaseMachine
impl PhaseMachine
Sourcepub fn add_phase(&mut self, phase: Phase)
pub fn add_phase(&mut self, phase: Phase)
Register a phase. Overwrites any existing phase with the same name.
Sourcepub fn current_phase(&self) -> Option<&Phase>
pub fn current_phase(&self) -> Option<&Phase>
A reference to the current Phase, if it exists in the registry.
Sourcepub fn history(&self) -> &VecDeque<PhaseTransition>
pub fn history(&self) -> &VecDeque<PhaseTransition>
The transition history (oldest first, capped at 100 entries).
Generate a structured navigation context block giving the model awareness of where it is in the conversation flow.
The output includes the current phase and its goal, recent phase history, any state keys still needed, and possible transitions.
Sourcepub fn evaluate(&self, state: &State) -> Option<(&str, usize)>
pub fn evaluate(&self, state: &State) -> Option<(&str, usize)>
Evaluate transitions from the current phase.
Returns the target phase name and transition index of the first
transition whose guard returns true, or None if no transition
fires (or the current phase is terminal / missing).
This method is pure — it does not modify state or execute callbacks.
Sourcepub fn evaluate_for_transition(
&self,
state: &State,
) -> Option<TransitionEvaluation>
pub fn evaluate_for_transition( &self, state: &State, ) -> Option<TransitionEvaluation>
Evaluate transitions from the current phase, preserving blocked targets that declare preparations.
Sourcepub async fn prepare_target(
&self,
target: &str,
state: &State,
writer: &Arc<dyn SessionWriter>,
) -> bool
pub async fn prepare_target( &self, target: &str, state: &State, writer: &Arc<dyn SessionWriter>, ) -> bool
Run preparation effects declared by a target phase, then report whether all target requirements are now satisfied.
Sourcepub async fn transition(
&mut self,
target: &str,
state: &State,
writer: &Arc<dyn SessionWriter>,
turn: u32,
trigger: TransitionTrigger,
transcript_window: &TranscriptWindow,
) -> Option<TransitionResult>
pub async fn transition( &mut self, target: &str, state: &State, writer: &Arc<dyn SessionWriter>, turn: u32, trigger: TransitionTrigger, transcript_window: &TranscriptWindow, ) -> Option<TransitionResult>
Execute a transition: run on_exit for the current phase, update
current, run on_enter for the new phase, record history, and
return the TransitionResult for the new phase.
Returns None if the target phase does not exist.
Sourcepub fn current_phase_duration(&self) -> Duration
pub fn current_phase_duration(&self) -> Duration
Returns how long the machine has been in the current phase.
Sourcepub fn active_tools(&self) -> Option<&[String]>
pub fn active_tools(&self) -> Option<&[String]>
Active tools filter for the current phase.
Returns None when all tools are allowed, or Some(slice) with
the explicitly enabled tool names.