pub struct ConversationStateMachine { /* private fields */ }Expand description
Finite-state machine that advances a conversation through its lifecycle.
§Example
use tokio_prompt_orchestrator::conversation_state::{
ConversationStateMachine, TransitionTrigger,
};
let mut sm = ConversationStateMachine::new();
let new_phase = sm.trigger(TransitionTrigger::TaskMentioned, 1_000);
assert!(new_phase.is_some());Implementations§
Source§impl ConversationStateMachine
impl ConversationStateMachine
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new state machine starting in ConversationPhase::Opening.
Sourcepub fn current_phase(&self) -> &ConversationPhase
pub fn current_phase(&self) -> &ConversationPhase
Return the current phase.
Sourcepub fn trigger(
&mut self,
trigger: TransitionTrigger,
now: u64,
) -> Option<ConversationPhase>
pub fn trigger( &mut self, trigger: TransitionTrigger, now: u64, ) -> Option<ConversationPhase>
Apply a trigger. Returns the new phase if a transition occurred, or
None if the machine is in a terminal state or no rule matched.
Sourcepub fn can_transition(
from: &ConversationPhase,
trigger: &TransitionTrigger,
) -> bool
pub fn can_transition( from: &ConversationPhase, trigger: &TransitionTrigger, ) -> bool
Return true if the given trigger can fire from from.
Sourcepub fn history(&self) -> &[PhaseTransition]
pub fn history(&self) -> &[PhaseTransition]
Return the full transition history.
Sourcepub fn time_in_current_phase(&self, now: u64) -> u64
pub fn time_in_current_phase(&self, now: u64) -> u64
Milliseconds spent in the current phase as of now.
Sourcepub fn detect_trigger(user_text: &str) -> Option<TransitionTrigger>
pub fn detect_trigger(user_text: &str) -> Option<TransitionTrigger>
Heuristic trigger detection from raw user text.
Rules (checked in order):
- “bye” / “goodbye” / “close” →
TransitionTrigger::ExplicitClose - “thank” / “thanks” →
TransitionTrigger::UserSatisfied - “hello” / “hi” / “hey” →
TransitionTrigger::UserGreeting - text contains “?” →
TransitionTrigger::QuestionAsked - any other non-empty text →
TransitionTrigger::TaskMentioned
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConversationStateMachine
impl RefUnwindSafe for ConversationStateMachine
impl Send for ConversationStateMachine
impl Sync for ConversationStateMachine
impl Unpin for ConversationStateMachine
impl UnsafeUnpin for ConversationStateMachine
impl UnwindSafe for ConversationStateMachine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request