pub struct AgentRuntime { /* private fields */ }Expand description
The core agent runtime that manages sessions, turns, approvals, and events.
Implementations§
Source§impl AgentRuntime
impl AgentRuntime
Sourcepub fn new(options: AgentRuntimeOptions) -> Self
pub fn new(options: AgentRuntimeOptions) -> Self
Creates a new runtime from the given options.
Sourcepub fn rewind_store_handle(&self) -> Arc<Mutex<RewindStore>> ⓘ
pub fn rewind_store_handle(&self) -> Arc<Mutex<RewindStore>> ⓘ
Shared rewind store (write tools note dirty paths through this handle).
Sourcepub fn rebind_rewind_store(&self)
pub fn rebind_rewind_store(&self)
Rebind rewind store to the live session id (after start_session).
Sourcepub fn get_goal(&self) -> Option<SessionGoal>
pub fn get_goal(&self) -> Option<SessionGoal>
Returns all agent events recorded so far. Returns the current session goal, if any.
Sourcepub fn set_goal(
&self,
objective: String,
token_budget: Option<i64>,
) -> SessionGoal
pub fn set_goal( &self, objective: String, token_budget: Option<i64>, ) -> SessionGoal
Sets or updates the session goal and notifies live clients.
Sourcepub fn set_goal_with_short_description(
&self,
objective: String,
short_description: Option<String>,
token_budget: Option<i64>,
) -> SessionGoal
pub fn set_goal_with_short_description( &self, objective: String, short_description: Option<String>, token_budget: Option<i64>, ) -> SessionGoal
Sets or updates the session goal with a compact UI label.
Sourcepub fn clear_goal(&self)
pub fn clear_goal(&self)
Clears the current session goal.
Live UIs typically clear their chip optimistically when the user requests clear; no terminal GoalUpdated is published (that would look like a successful complete).
Sourcepub fn update_goal(&self, goal: SessionGoal)
pub fn update_goal(&self, goal: SessionGoal)
Updates the stored goal (used after status transitions) and notifies clients.
Sourcepub fn update_goal_checklist(&self, tasks: Vec<GoalTask>) -> Option<SessionGoal>
pub fn update_goal_checklist(&self, tasks: Vec<GoalTask>) -> Option<SessionGoal>
Updates the goal checklist (replaces all tasks).
Sourcepub fn update_goal_task_status(
&self,
task_id: usize,
status: TaskStatus,
) -> Option<SessionGoal>
pub fn update_goal_task_status( &self, task_id: usize, status: TaskStatus, ) -> Option<SessionGoal>
Updates a single task’s status in the goal checklist.
Sourcepub fn goal_idle_prompt(&self) -> Option<String>
pub fn goal_idle_prompt(&self) -> Option<String>
Returns a continuation steering prompt if the goal is active and should auto-continue.
Sourcepub fn goals_config(&self) -> GoalsConfig
pub fn goals_config(&self) -> GoalsConfig
Returns the goals configuration.
Sourcepub fn goal_runtime(&self) -> &Arc<GoalRuntimeHandle> ⓘ
pub fn goal_runtime(&self) -> &Arc<GoalRuntimeHandle> ⓘ
Returns a reference to the goal runtime handle.
Sourcepub fn agent_mode(&self) -> AgentMode
pub fn agent_mode(&self) -> AgentMode
Returns the current agent mode.
Sourcepub fn enter_plan_mode(&self)
pub fn enter_plan_mode(&self)
Enters Plan mode. Exploration tools + the session plan markdown file are available; project writes and commands are blocked.
Sourcepub fn exit_plan_mode(&self)
pub fn exit_plan_mode(&self)
Exits Plan mode and returns to normal execution.
Sourcepub fn feed_plan_text(&self, text: &str) -> Vec<ProposedPlan>
pub fn feed_plan_text(&self, text: &str) -> Vec<ProposedPlan>
Feeds a text delta into the plan parser. Returns any completed plans.
Sourcepub fn drain_plans(&self) -> Vec<ProposedPlan>
pub fn drain_plans(&self) -> Vec<ProposedPlan>
Drains any pending plans from the parser (call at end of turn).
Sourcepub fn is_parsing_plan(&self) -> bool
pub fn is_parsing_plan(&self) -> bool
Returns true if the parser is currently inside a <proposed_plan> block.
Sourcepub fn has_pending_user_input(&self) -> bool
pub fn has_pending_user_input(&self) -> bool
Returns true if a user message is pending (set when send_turn is
called while the runtime is busy with auto-continuation).
Sourcepub fn set_pending_user_input(&self, pending: bool)
pub fn set_pending_user_input(&self, pending: bool)
Marks that a user message is pending.
Sourcepub fn events(&self) -> &[AgentEvent]
pub fn events(&self) -> &[AgentEvent]
Returns all agent events recorded so far.
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Returns the current session id.
Sourcepub fn session_title(&self) -> Option<&str>
pub fn session_title(&self) -> Option<&str>
Returns the session title, if one has been derived.
Sourcepub fn add_context_packet(&mut self, packet: ContextPacket)
pub fn add_context_packet(&mut self, packet: ContextPacket)
Adds a context packet to the session and emits a ContextUpdated event.
Sourcepub fn clear_context_packets(&mut self)
pub fn clear_context_packets(&mut self)
Clears all context packets and emits a ContextUpdated event.
Sourcepub fn context_packets(&self) -> &[ContextPacket]
pub fn context_packets(&self) -> &[ContextPacket]
Returns the current context packets.
Sourcepub fn set_active_skills(&mut self, skills: Vec<String>)
pub fn set_active_skills(&mut self, skills: Vec<String>)
Sets the session catalog filter for skills.
Empty skills means all discovered skills are catalog-active (default).
Non-empty restricts the Available Skills catalog to those ids/names.
Never injects skill instruction bodies into the prompt.
When a skill has a harness pack under {data_dir}/harnesses/<id>/, applies
soft graph allowlists, loop max_turns / token_budget, and harness card text.
Sourcepub fn effective_max_auto_continue_turns(&self) -> u32
pub fn effective_max_auto_continue_turns(&self) -> u32
Effective max auto-continue turns (harness pack overrides goals config when set).
Sourcepub fn harness_card(&self) -> Option<&str>
pub fn harness_card(&self) -> Option<&str>
Developer harness card for the active pack(s), if any.
Sourcepub fn list_models(&self) -> Vec<ModelOption>
pub fn list_models(&self) -> Vec<ModelOption>
Lists available model options from the loaded configuration.
Sourcepub fn model_selection(&self) -> (&str, &str)
pub fn model_selection(&self) -> (&str, &str)
Current (provider_id, model_name) selection for this runtime.
Sourcepub fn set_model(
&mut self,
provider: impl Into<String>,
model: impl Into<String>,
)
pub fn set_model( &mut self, provider: impl Into<String>, model: impl Into<String>, )
Changes the selected model and emits a ContextUpdated event.
Sourcepub fn set_model_provider(
&mut self,
loaded_config: LoadedConfig,
model_provider: Arc<dyn ModelProvider>,
)
pub fn set_model_provider( &mut self, loaded_config: LoadedConfig, model_provider: Arc<dyn ModelProvider>, )
Replaces the runtime configuration and provider used by subsequent turns.
Sourcepub fn register_host_tool(&mut self, tool: Arc<dyn Tool>) -> Result<()>
pub fn register_host_tool(&mut self, tool: Arc<dyn Tool>) -> Result<()>
Registers a host-provided tool with the runtime’s tool executor. Creates a default executor if none exists yet.
Sourcepub fn stream_events(&self) -> Receiver<RuntimeEvent>
pub fn stream_events(&self) -> Receiver<RuntimeEvent>
Returns a broadcast receiver for RuntimeEvents.
Sourcepub fn cancel_turn(&self)
pub fn cancel_turn(&self)
Cancels the currently running turn.
Sourcepub fn resolve_approval(&self, decision: ApprovalDecision) -> bool
pub fn resolve_approval(&self, decision: ApprovalDecision) -> bool
Resolves a pending approval by id. Returns true if found.
Sourcepub fn resolve_question(&self, response: QuestionResponse) -> bool
pub fn resolve_question(&self, response: QuestionResponse) -> bool
Resolves a pending interactive question by id. Returns true if found.
Sourcepub fn resolve_plan_review(&self, response: PlanReviewResponse) -> bool
pub fn resolve_plan_review(&self, response: PlanReviewResponse) -> bool
Resolves a pending plan review by invocation id. Returns true if found.
Sourcepub fn approval_resolver(&self) -> ApprovalResolver
pub fn approval_resolver(&self) -> ApprovalResolver
Returns an ApprovalResolver handle for external approval resolution.
Sourcepub fn question_resolver(&self) -> QuestionResolver
pub fn question_resolver(&self) -> QuestionResolver
Returns a QuestionResolver handle for external question resolution.
Sourcepub fn plan_review_resolver(&self) -> PlanReviewResolver
pub fn plan_review_resolver(&self) -> PlanReviewResolver
Returns a PlanReviewResolver handle for external plan-review resolution.
Sourcepub fn sudo_password_resolver(&self) -> SudoPasswordResolver
pub fn sudo_password_resolver(&self) -> SudoPasswordResolver
Returns a SudoPasswordResolver for interactive sudo prompts.
pub fn resolve_sudo_password(&self, response: SudoPasswordResponse) -> bool
Sourcepub fn turn_canceller(&self) -> TurnCanceller
pub fn turn_canceller(&self) -> TurnCanceller
Returns a TurnCanceller handle for external cancellation.
Sourcepub fn start_session(&mut self) -> Result<SessionId>
pub fn start_session(&mut self) -> Result<SessionId>
Starts a new session (or restarts if one is already active). Returns the session id.
Sourcepub async fn send_turn_with_parts(
&mut self,
task: String,
content_parts: Vec<ContentPart>,
thinking_override: Option<ThinkingConfig>,
) -> Result<ModelResponse>
pub async fn send_turn_with_parts( &mut self, task: String, content_parts: Vec<ContentPart>, thinking_override: Option<ThinkingConfig>, ) -> Result<ModelResponse>
Sends a user task to the agent and waits for the full response. Starts a session automatically if one is not active. Sends a user turn with optional multimodal content parts.
When content_parts is non-empty, the message is created as a
multimodal user message containing both text and images.
After a successful turn, if a thread goal is still active, runs automatic continuation turns (idle lifecycle) until the goal stops, the auto-continue limit is hit, plan mode is on, or the user has pending input.
pub async fn submit_task(&mut self, task: String) -> Result<ModelResponse>
Sourcepub async fn send_turn(&mut self, task: String) -> Result<ModelResponse>
pub async fn send_turn(&mut self, task: String) -> Result<ModelResponse>
Sends a plain text user turn (no images).
Sourcepub async fn compact_now(&mut self) -> Result<CompactOutcome>
pub async fn compact_now(&mut self) -> Result<CompactOutcome>
Force-compact live conversation history using the session’s own model.
Summarizes older turns, replaces the live message list, and emits
AutoCompactStarted / AutoCompactCompleted (or Failed) events.
Sourcepub async fn rewind_to_user_turns(
&mut self,
keep_user_turns: usize,
) -> Result<usize>
pub async fn rewind_to_user_turns( &mut self, keep_user_turns: usize, ) -> Result<usize>
Rewind live conversation history for an edited past user message.
Keeps the first keep_user_turns user turns (and their assistant/tool
follow-ups), drops everything after, and truncates recorded session
events the same way. Also restores project files to the pre-turn state
of the first dropped user prompt (session rewind).
Caller should then send_turn with the new text (or leave the prompt in
the input for the user to edit).
keep_user_turns = 0 keeps only system/developer preamble.
Sourcepub fn list_rewind_points(&self) -> Vec<RewindPointMeta>
pub fn list_rewind_points(&self) -> Vec<RewindPointMeta>
List rewind checkpoints (user-turn snapshots) for the live session.
Sourcepub fn rewind_store_points_path(&self) -> PathBuf
pub fn rewind_store_points_path(&self) -> PathBuf
Filesystem restore summary from the last restore_to is not retained;
use Self::rewind_to_user_turns which restores as a side effect.
Sourcepub fn snapshot_session(&mut self) -> Result<SessionSnapshot>
pub fn snapshot_session(&mut self) -> Result<SessionSnapshot>
Creates a SessionSnapshot of the current session state for persistence.
Sourcepub async fn snapshot_session_async(&mut self) -> Result<SessionSnapshot>
pub async fn snapshot_session_async(&mut self) -> Result<SessionSnapshot>
Creates and persists a session snapshot without blocking the async runtime.
Sourcepub fn tool_executor(&self) -> Option<Arc<ToolExecutor>>
pub fn tool_executor(&self) -> Option<Arc<ToolExecutor>>
Returns the configured tool executor, if any.
Sourcepub fn retain_tools<F>(&mut self, pred: F)
pub fn retain_tools<F>(&mut self, pred: F)
Keep only tools whose names satisfy pred on the live session executor.
Used by host tool profiles after start (goal/skill tools may re-register). No-ops when the executor Arc is shared.
Sourcepub fn session_title_handle(&self) -> SessionTitleHandle
pub fn session_title_handle(&self) -> SessionTitleHandle
Returns the session-local handle used by the title tool. SDK tooling reloads use this to keep the built-in title capability installed.
Sourcepub fn set_tool_executor(&mut self, executor: Arc<ToolExecutor>)
pub fn set_tool_executor(&mut self, executor: Arc<ToolExecutor>)
Replaces the session tool executor (e.g. after installing WASM plugins).
Sourcepub fn set_security_config(&mut self, security: SecurityConfig) -> Result<()>
pub fn set_security_config(&mut self, security: SecurityConfig) -> Result<()>
Updates the security configuration used by the tool executor and the runtime’s loaded config. No-op when no executor has been created yet.
Auto Trait Implementations§
impl !Freeze for AgentRuntime
impl !RefUnwindSafe for AgentRuntime
impl !UnwindSafe for AgentRuntime
impl Send for AgentRuntime
impl Sync for AgentRuntime
impl Unpin for AgentRuntime
impl UnsafeUnpin for AgentRuntime
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