pub struct LashRuntime { /* private fields */ }Expand description
Generic runtime for CLI or programmatic embedding.
Implementations§
Source§impl LashRuntime
impl LashRuntime
pub fn builder() -> EmbeddedRuntimeBuilder
Source§impl LashRuntime
impl LashRuntime
Sourcepub fn set_model_variant(&mut self, model_variant: Option<String>)
pub fn set_model_variant(&mut self, model_variant: Option<String>)
Update model variant on the runtime config.
Sourcepub fn set_max_context_tokens(&mut self, max_context_tokens: usize)
pub fn set_max_context_tokens(&mut self, max_context_tokens: usize)
Update explicit model context metadata on the runtime config.
Sourcepub fn set_provider(&mut self, provider: ProviderHandle)
pub fn set_provider(&mut self, provider: ProviderHandle)
Update provider on the runtime config.
Sourcepub fn set_session_id(&mut self, session_id: Option<String>)
pub fn set_session_id(&mut self, session_id: Option<String>)
Update session ID metadata on the runtime config.
pub async fn update_session_config( &mut self, provider: Option<ProviderHandle>, model: Option<String>, model_variant: Option<Option<String>>, max_context_tokens: Option<usize>, prompt: Option<PromptLayer>, )
pub async fn set_prompt_template(&mut self, template: PromptTemplate)
pub async fn clear_prompt_template(&mut self)
pub async fn add_prompt_contribution( &mut self, contribution: PromptContribution, )
pub async fn replace_prompt_slot( &mut self, slot: PromptSlot, contributions: impl IntoIterator<Item = PromptContribution>, )
pub async fn clear_prompt_slot(&mut self, slot: PromptSlot)
Sourcepub async fn refresh_session_tool_surface(&mut self) -> Result<(), SessionError>
pub async fn refresh_session_tool_surface(&mut self) -> Result<(), SessionError>
Re-register the current tool surface in the live RLM session.
pub async fn apply_tool_state( &mut self, snapshot: ToolState, ) -> Result<u64, SessionError>
Source§impl LashRuntime
impl LashRuntime
Sourcepub async fn from_embedded_state(
policy: SessionPolicy,
host: EmbeddedRuntimeHost,
services: RuntimeServices,
state: PersistedSessionState,
) -> Result<Self, SessionError>
pub async fn from_embedded_state( policy: SessionPolicy, host: EmbeddedRuntimeHost, services: RuntimeServices, state: PersistedSessionState, ) -> Result<Self, SessionError>
Build a runtime for an embedded host with no background worker support.
Sourcepub async fn from_background_state(
policy: SessionPolicy,
host: BackgroundRuntimeHost,
services: RuntimeServices,
state: PersistedSessionState,
) -> Result<Self, SessionError>
pub async fn from_background_state( policy: SessionPolicy, host: BackgroundRuntimeHost, services: RuntimeServices, state: PersistedSessionState, ) -> Result<Self, SessionError>
Build a runtime for a host that supports background plugin work.
Sourcepub async fn from_persistent_embedded_state(
policy: SessionPolicy,
host: EmbeddedRuntimeHost,
services: PersistentRuntimeServices,
state: PersistedSessionState,
) -> Result<Self, SessionError>
pub async fn from_persistent_embedded_state( policy: SessionPolicy, host: EmbeddedRuntimeHost, services: PersistentRuntimeServices, state: PersistedSessionState, ) -> Result<Self, SessionError>
Build a runtime for an embedded host with persistent store support.
Sourcepub async fn from_persistent_background_state(
policy: SessionPolicy,
host: BackgroundRuntimeHost,
services: PersistentRuntimeServices,
state: PersistedSessionState,
) -> Result<Self, SessionError>
pub async fn from_persistent_background_state( policy: SessionPolicy, host: BackgroundRuntimeHost, services: PersistentRuntimeServices, state: PersistedSessionState, ) -> Result<Self, SessionError>
Build a runtime for a background-capable host with persistent store support.
Sourcepub async fn from_environment(
env: &RuntimeEnvironment,
policy: SessionPolicy,
state: PersistedSessionState,
store: Option<Arc<dyn RuntimePersistence>>,
) -> Result<Self, SessionError>
pub async fn from_environment( env: &RuntimeEnvironment, policy: SessionPolicy, state: PersistedSessionState, store: Option<Arc<dyn RuntimePersistence>>, ) -> Result<Self, SessionError>
Embedder-preferred constructor: build a LashRuntime from a
shared RuntimeEnvironment.
Everything expensive (plugin factories, HTTP client pool, prompt template, path resolver) lives on the environment and is reused across every runtime the embedder builds. This call is O(plugin-session-registration + state-hydration), not O(full-infrastructure-init).
env— the shared environment.env.plugin_hostmust be set.policy— per-session policy (model, provider, execution mode).state— persisted session state (empty for a fresh session).store— per-session store.Nonebuilds an embedded runtime with no persistence;Somebuilds a persistent background-capable runtime.
Sourcepub async fn park(self) -> Result<ParkedSession, SessionError>
pub async fn park(self) -> Result<ParkedSession, SessionError>
Persist any dirty state and drop the runtime, returning a lightweight
handle the embedder can cache and resume later via
LashRuntime::resume. This is the webserver-embedder handoff
primitive: the handle holds only the session id, policy, and store
reference — no graph nodes, no plugin session, no HTTP client.
Sourcepub async fn resume(
parked: ParkedSession,
env: &RuntimeEnvironment,
) -> Result<Self, SessionError>
pub async fn resume( parked: ParkedSession, env: &RuntimeEnvironment, ) -> Result<Self, SessionError>
Resume a previously parked session against a shared environment.
Loads only the active-path graph when
env.residency == ActivePathOnly; under KeepAll
loads the full graph (current behavior).
Sourcepub async fn get_historic_node(
&self,
node_id: &str,
) -> Result<Option<SessionNodeRecord>, SessionError>
pub async fn get_historic_node( &self, node_id: &str, ) -> Result<Option<SessionNodeRecord>, SessionError>
Opt-in async read for historic (non-active-path) nodes under
Residency::ActivePathOnly. Plugins that walk the full graph
call this instead of session_graph().find_node() so missing
nodes surface as Ok(None) rather than silently missing.
Sourcepub async fn orphaned_node_ids(&self) -> Result<Vec<String>, SessionError>
pub async fn orphaned_node_ids(&self) -> Result<Vec<String>, SessionError>
Store-resident node IDs that are NOT reachable from the current leaf — i.e. orphans eligible for tombstoning. lash owns RAM; the host owns disk lifecycle, so this is a primitive the host calls on its own schedule (e.g. every N turns, or off-peak).
Typical autonomous-agent loop:
let orphans = runtime.orphaned_node_ids().await?;
if !orphans.is_empty() {
store.tombstone_nodes(&orphans).await;
}
// And less often:
store.vacuum().await;Source§impl LashRuntime
impl LashRuntime
pub fn session_id(&self) -> &str
pub fn tool_state(&self) -> Result<ToolState, SessionError>
Sourcepub fn set_mode_turn_options(&mut self, options: ModeTurnOptions)
pub fn set_mode_turn_options(&mut self, options: ModeTurnOptions)
Override mode-owned turn options for this session.
Sourcepub fn export_state(&self) -> SessionStateEnvelope
pub fn export_state(&self) -> SessionStateEnvelope
Export current session state for inspection/UI purposes.
This keeps persistence-heavy snapshots untouched; callers that need a
fully persisted view should use export_persisted_state.
pub fn read_view(&self) -> SessionReadView
Sourcepub fn export_persistence_state(&self) -> PersistedSessionState
pub fn export_persistence_state(&self) -> PersistedSessionState
Export the narrow persistence snapshot used by stores and resume logic.
pub fn apply_persistence_state(&mut self, state: PersistedSessionState)
Sourcepub fn export_persisted_state(&self) -> PersistedSessionState
pub fn export_persisted_state(&self) -> PersistedSessionState
Export a persistence-ready state envelope with dynamic/plugin snapshots refreshed from the live session.
pub fn usage_report(&self) -> SessionUsageReport
pub async fn await_background_work(&mut self) -> Result<(), SessionError>
pub fn session_manager( &self, ) -> Result<Arc<dyn RuntimeSessionHost>, PluginActionInvokeError>
Sourcepub fn plugin_session(&self) -> Option<Arc<PluginSession>>
pub fn plugin_session(&self) -> Option<Arc<PluginSession>>
The plugin session bound to the currently active runtime session, if any.
pub fn turn_input_injection_bridge( &self, ) -> Result<TurnInputInjectionBridge, SessionError>
Sourcepub async fn rewrite_history(
&mut self,
trigger: RewriteTrigger,
) -> Result<bool, PluginActionInvokeError>
pub async fn rewrite_history( &mut self, trigger: RewriteTrigger, ) -> Result<bool, PluginActionInvokeError>
Run the registered history rewrite pipeline against the current state, applying the resulting messages back onto the runtime. Returns true when at least one rewriter produced a summary or otherwise mutated the message list.
Source§impl LashRuntime
impl LashRuntime
Sourcepub fn set_persisted_state(&mut self, state: PersistedSessionState)
pub fn set_persisted_state(&mut self, state: PersistedSessionState)
Replace the host-owned state envelope.
pub async fn append_session_nodes( &mut self, request: AppendSessionNodesRequest, ) -> Result<AppendSessionNodesResult, SessionError>
pub async fn apply_mode_session_extension( &mut self, extension: ModeSessionExtensionHandle, ) -> Result<(), SessionError>
pub async fn validate_mode_turn_extension( &mut self, extension: &ModeTurnExtensionHandle, ) -> Result<(), SessionError>
pub async fn branch_to_node( &mut self, node_id: Option<String>, ) -> Result<SessionStateEnvelope, SessionError>
Sourcepub async fn activate_managed_session(
&mut self,
session_id: &str,
) -> Result<(), SessionError>
pub async fn activate_managed_session( &mut self, session_id: &str, ) -> Result<(), SessionError>
Promote a managed child session into the foreground runtime.
Child sessions created through RuntimeSessionHost::create_session are real
runtimes, not serialized placeholders. Foreground handoff must therefore
claim that runtime instead of reconstructing a new empty state in the UI.
Sourcepub async fn reset_session(&mut self) -> Result<(), SessionError>
pub async fn reset_session(&mut self) -> Result<(), SessionError>
Reset the RLM session on the underlying session runtime.
Sourcepub async fn snapshot_execution_state(
&mut self,
) -> Result<Option<Vec<u8>>, SessionError>
pub async fn snapshot_execution_state( &mut self, ) -> Result<Option<Vec<u8>>, SessionError>
Explicitly snapshot execution-mode-local state, if any.
Sourcepub async fn restore_execution_state(
&mut self,
snapshot: &[u8],
) -> Result<(), SessionError>
pub async fn restore_execution_state( &mut self, snapshot: &[u8], ) -> Result<(), SessionError>
Explicitly restore execution-mode-local state from an opaque snapshot blob.
pub async fn invoke_plugin_action( &self, name: &str, args: Value, session_id: Option<String>, ) -> Result<ToolResult, PluginActionInvokeError>
Source§impl LashRuntime
impl LashRuntime
Sourcepub async fn stream_turn(
&mut self,
input: TurnInput,
events: &dyn EventSink,
cancel: CancellationToken,
) -> Result<AssembledTurn, RuntimeError>
pub async fn stream_turn( &mut self, input: TurnInput, events: &dyn EventSink, cancel: CancellationToken, ) -> Result<AssembledTurn, RuntimeError>
Run a single turn and stream events to the host sink.
Sourcepub async fn stream_turn_following_handoffs(
&mut self,
input: TurnInput,
events: &dyn EventSink,
cancel: CancellationToken,
) -> Result<FollowedTurn, RuntimeError>
pub async fn stream_turn_following_handoffs( &mut self, input: TurnInput, events: &dyn EventSink, cancel: CancellationToken, ) -> Result<FollowedTurn, RuntimeError>
Stream one logical host turn, following foreground handoffs until a non-handoff outcome is reached.
RLM continue_as creates a successor session with queued first-turn
input. Hosts that only care about the benchmark/app answer should not
need to special-case that intermediate outcome; this helper activates
each successor and drives its queued first turn with the normal runtime
turn guards.
pub async fn stream_turn_events_following_handoffs( &mut self, input: TurnInput, turn_events: &dyn TurnActivitySink, cancel: CancellationToken, ) -> Result<FollowedTurn, RuntimeError>
pub async fn stream_turn_with_events_following_handoffs( &mut self, input: TurnInput, events: &dyn EventSink, turn_events: &dyn TurnActivitySink, cancel: CancellationToken, ) -> Result<FollowedTurn, RuntimeError>
Sourcepub async fn run_turn_assembled(
&mut self,
input: TurnInput,
cancel: CancellationToken,
) -> Result<AssembledTurn, RuntimeError>
pub async fn run_turn_assembled( &mut self, input: TurnInput, cancel: CancellationToken, ) -> Result<AssembledTurn, RuntimeError>
Run a single turn and return only the assembled terminal result.
Sourcepub async fn stream_prepared_turn(
&mut self,
messages: MessageSequence,
_previous_prompt_usage: Option<PromptUsage>,
mode_turn_options: Option<ModeTurnOptions>,
mode_extension: Option<ModeTurnExtensionHandle>,
turn_context: TurnContext,
trace_turn_id: String,
turn_index: usize,
events: &dyn EventSink,
turn_events: &dyn TurnActivitySink,
cancel: CancellationToken,
) -> Result<AssembledTurn, RuntimeError>
pub async fn stream_prepared_turn( &mut self, messages: MessageSequence, _previous_prompt_usage: Option<PromptUsage>, mode_turn_options: Option<ModeTurnOptions>, mode_extension: Option<ModeTurnExtensionHandle>, turn_context: TurnContext, trace_turn_id: String, turn_index: usize, events: &dyn EventSink, turn_events: &dyn TurnActivitySink, cancel: CancellationToken, ) -> Result<AssembledTurn, RuntimeError>
Run a turn using host-prepared message history.