pub struct GoalRuntimeHandle { /* private fields */ }Expand description
Per-session goal lifecycle manager.
Drives auto-continuation, status transitions, and steering prompt injection.
All mutations go through with_goal_state which serializes access via a
dedicated state lock, preventing external set/clear calls from
interfering with continue_if_idle.
Implementations§
Source§impl GoalRuntimeHandle
impl GoalRuntimeHandle
Sourcepub fn new(initial_goal: Option<SessionGoal>) -> Self
pub fn new(initial_goal: Option<SessionGoal>) -> Self
Creates a new runtime handle with an optional initial goal.
Sourcepub fn get_goal(&self) -> Option<SessionGoal>
pub fn get_goal(&self) -> Option<SessionGoal>
Returns the current goal, if any.
Sourcepub fn set_session_id(&self, session_id: impl Into<String>)
pub fn set_session_id(&self, session_id: impl Into<String>)
Binds this runtime to a session id and rewrites any loaded goal to match.
Sourcepub fn set_objective(
&self,
objective: String,
token_budget: Option<i64>,
) -> SessionGoal
pub fn set_objective( &self, objective: String, token_budget: Option<i64>, ) -> SessionGoal
Sets or replaces the goal.
Sourcepub fn set_objective_with_short_description(
&self,
objective: String,
short_description: Option<String>,
token_budget: Option<i64>,
) -> SessionGoal
pub fn set_objective_with_short_description( &self, objective: String, short_description: Option<String>, token_budget: Option<i64>, ) -> SessionGoal
Sets or replaces the goal with an optional compact UI label.
When a goal already exists, mutates it in place (same goal_id) and
re-activates it — used by host/SDK set_goal. Model create_goal must
call [create_new_goal] so terminal goals get a fresh id.
Sourcepub fn create_new_goal(
&self,
objective: String,
short_description: Option<String>,
token_budget: Option<i64>,
) -> SessionGoal
pub fn create_new_goal( &self, objective: String, short_description: Option<String>, token_budget: Option<i64>, ) -> SessionGoal
Creates a brand-new active goal (new goal_id), replacing any prior goal.
Caller must ensure there is no unfinished goal when this is used from the
model-facing create_goal tool.
Sourcepub fn update_goal(&self, goal: SessionGoal)
pub fn update_goal(&self, goal: SessionGoal)
Updates the stored goal (used after status transitions).
Sourcepub fn clear_goal(&self)
pub fn clear_goal(&self)
Clears the current goal.
Sourcepub fn update_checklist(&self, tasks: Vec<GoalTask>) -> Option<SessionGoal>
pub fn update_checklist(&self, tasks: Vec<GoalTask>) -> Option<SessionGoal>
Updates the checklist on the current goal. Returns the updated goal if successful.
Sourcepub fn update_task_status(
&self,
task_id: usize,
status: TaskStatus,
) -> Option<SessionGoal>
pub fn update_task_status( &self, task_id: usize, status: TaskStatus, ) -> Option<SessionGoal>
Updates a single task’s status in the goal checklist.
Sourcepub fn start_turn(&self)
pub fn start_turn(&self)
Starts turn accounting for the active goal.
Sourcepub fn record_tokens(&self, delta: i64) -> bool
pub fn record_tokens(&self, delta: i64) -> bool
Records token usage during a turn.
Sourcepub fn finish_turn(&self)
pub fn finish_turn(&self)
Finishes turn accounting and updates the stored goal.
Sourcepub fn record_blocked_turn(&self, reason: &str) -> bool
pub fn record_blocked_turn(&self, reason: &str) -> bool
Transitions the goal to Blocked after consecutive blocked turns.
Sourcepub fn mark_usage_limited(&self)
pub fn mark_usage_limited(&self)
Transitions the goal to UsageLimited.
Sourcepub fn continue_if_idle(&self) -> Option<String>
pub fn continue_if_idle(&self) -> Option<String>
If the goal is active and should auto-continue, returns a steering continuation prompt to inject into the conversation. Acquires the state lock to prevent race conditions with concurrent set/clear operations.
Sourcepub fn budget_limit_prompt(&self) -> Option<String>
pub fn budget_limit_prompt(&self) -> Option<String>
Returns a budget-limit steering prompt if the budget is exceeded.
Sourcepub fn objective_updated_prompt(&self) -> Option<String>
pub fn objective_updated_prompt(&self) -> Option<String>
Returns an objective-updated steering prompt.
Sourcepub fn set_auto_continue(&self, enabled: bool)
pub fn set_auto_continue(&self, enabled: bool)
Enables or disables auto-continuation.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Returns true if the goal is in a terminal state.
Auto Trait Implementations§
impl !Freeze for GoalRuntimeHandle
impl RefUnwindSafe for GoalRuntimeHandle
impl Send for GoalRuntimeHandle
impl Sync for GoalRuntimeHandle
impl Unpin for GoalRuntimeHandle
impl UnsafeUnpin for GoalRuntimeHandle
impl UnwindSafe for GoalRuntimeHandle
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more