Skip to main content

LashRuntime

Struct LashRuntime 

Source
pub struct LashRuntime { /* private fields */ }
Expand description

Generic runtime for CLI or programmatic embedding.

Implementations§

Source§

impl LashRuntime

Source§

impl LashRuntime

Source

pub fn set_model(&mut self, model: ModelSpec)

Update model spec on the runtime config.

Source

pub fn set_provider(&mut self, provider: ProviderHandle)

Update provider on the runtime config.

Source

pub fn set_session_id(&mut self, session_id: Option<String>)

Update session ID metadata on the runtime config.

Source

pub async fn update_session_config( &mut self, provider: Option<ProviderHandle>, model: Option<ModelSpec>, prompt: Option<PromptLayer>, )

Source

pub async fn set_prompt_template(&mut self, template: PromptTemplate)

Source

pub async fn clear_prompt_template(&mut self)

Source

pub async fn add_prompt_contribution( &mut self, contribution: PromptContribution, )

Source

pub async fn replace_prompt_slot( &mut self, slot: PromptSlot, contributions: impl IntoIterator<Item = PromptContribution>, )

Source

pub async fn clear_prompt_slot(&mut self, slot: PromptSlot)

Source

pub async fn refresh_session_tool_surface(&mut self) -> Result<(), SessionError>

Re-register the current tool surface in the live RLM session.

Source

pub async fn apply_tool_state( &mut self, snapshot: ToolState, ) -> Result<u64, SessionError>

Source

pub async fn restore_tool_state( &mut self, snapshot: ToolState, ) -> Result<u64, SessionError>

Restore a persisted tool-state snapshot, adopting its generation.

Unlike apply_tool_state — a generation-checked delta that requires the snapshot to match the current generation and bumps it — this restores the exact persisted surface idempotently, so a cold resume of a session whose surface reached generation ≥ 2 succeeds (a delta-apply onto a fresh base-1 registry would be rejected).

Source§

impl LashRuntime

Source

pub fn unregister_plugin_session(&self) -> Result<(), PluginError>

Source

pub async fn from_embedded_state( policy: SessionPolicy, host: EmbeddedRuntimeHost, services: RuntimeServices, state: RuntimeSessionState, ) -> Result<Self, SessionError>

Build a runtime for an embedded host with no background worker support.

Source

pub async fn from_background_state( policy: SessionPolicy, host: ProcessRuntimeHost, services: RuntimeServices, state: RuntimeSessionState, ) -> Result<Self, SessionError>

Build a runtime for a host that supports background plugin work.

Source

pub async fn from_persistent_embedded_state( policy: SessionPolicy, host: EmbeddedRuntimeHost, services: PersistentRuntimeServices, state: RuntimeSessionState, ) -> Result<Self, SessionError>

Build a runtime for an embedded host with persistent store support.

Source

pub async fn from_persistent_background_state( policy: SessionPolicy, host: ProcessRuntimeHost, services: PersistentRuntimeServices, state: RuntimeSessionState, ) -> Result<Self, SessionError>

Build a runtime for a background-capable host with persistent store support.

Source

pub async fn from_environment( env: &RuntimeEnvironment, policy: SessionPolicy, state: RuntimeSessionState, 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_host must be set.
  • policy — per-session policy (model, provider, autonomy, turn limits).
  • state — persisted session state (empty for a fresh session).
  • store — per-session store. None builds an embedded runtime with no persistence; Some builds a persistent background-capable runtime.
Source

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 parking primitive: the handle holds only the session id, policy, and store reference — no graph nodes, no plugin session, no HTTP client.

Source

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).

Source

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.

Source

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

Source

pub fn session_id(&self) -> &str

Source

pub fn tool_state(&self) -> Result<ToolState, SessionError>

Source

pub fn set_protocol_turn_options(&mut self, options: ProtocolTurnOptions)

Override protocol-owned turn options for this session.

Source

pub fn export_state(&self) -> SessionSnapshot

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.

Source

pub fn read_view(&self) -> SessionReadView

Source

pub fn export_persistence_state(&self) -> RuntimeSessionState

Export the narrow persistence snapshot used by stores and resume logic.

Source

pub fn apply_persistence_state( &mut self, state: RuntimeSessionState, ) -> Result<(), SessionError>

Source

pub fn export_persisted_state(&self) -> RuntimeSessionState

Export a persistence-ready state envelope with dynamic/plugin snapshots refreshed from the live session.

Source

pub fn usage_report(&self) -> SessionUsageReport

Source

pub async fn await_background_work(&mut self) -> Result<(), SessionError>

Source

pub fn session_state_service( &self, ) -> Result<Arc<dyn SessionStateService>, PluginActionInvokeError>

Source

pub fn session_lifecycle_service( &self, ) -> Result<Arc<dyn SessionLifecycleService>, PluginActionInvokeError>

Source

pub fn session_graph_service( &self, ) -> Result<Arc<dyn SessionGraphService>, PluginActionInvokeError>

Source

pub fn process_service( &self, ) -> Result<Arc<dyn ProcessService>, PluginActionInvokeError>

Source

pub fn process_cancel_ability(&self) -> Arc<dyn ProcessCancelAbility>

Source

pub fn effect_host(&self) -> Arc<dyn EffectHost>

Source

pub async fn enqueue_turn_input( &self, input: TurnInput, delivery_policy: DeliveryPolicy, slot_policy: SlotPolicy, source_key: Option<String>, ) -> Result<QueuedWorkBatch, RuntimeError>

Source

pub async fn cancel_queued_work_batch( &self, session_id: &str, batch_id: &str, ) -> Result<Option<QueuedWorkBatch>, RuntimeError>

Source

pub fn plugin_session(&self) -> Option<Arc<PluginSession>>

The plugin session bound to the currently active runtime session, if any.

Source

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

Source§

impl LashRuntime

Source

pub fn set_persisted_state( &mut self, state: RuntimeSessionState, ) -> Result<(), SessionError>

Replace the host-owned state envelope.

Source

pub async fn append_session_nodes( &mut self, request: AppendSessionNodesRequest, ) -> Result<AppendSessionNodesResult, SessionError>

Source

pub async fn apply_protocol_session_extension( &mut self, extension: ProtocolSessionExtensionHandle, ) -> Result<(), SessionError>

Source

pub async fn validate_protocol_turn_extension( &mut self, extension: &ProtocolTurnExtensionHandle, ) -> Result<(), SessionError>

Source

pub async fn branch_to_node( &mut self, node_id: Option<String>, ) -> Result<SessionSnapshot, SessionError>

Source

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 SessionLifecycleService::create_session are real runtimes, not serialized placeholders. Foreground activation must therefore claim that runtime instead of reconstructing a new empty state in the UI.

Source

pub async fn snapshot_execution_state( &mut self, ) -> Result<Option<Vec<u8>>, SessionError>

Explicitly snapshot protocol-local execution state, if any.

Source

pub async fn restore_execution_state( &mut self, snapshot: &[u8], ) -> Result<(), SessionError>

Explicitly restore protocol-local execution state from an opaque snapshot blob.

Source

pub async fn list_lashlang_trigger_registrations( &self, ) -> Result<Vec<TriggerRegistration>, SessionError>

Source

pub async fn lashlang_trigger_registrations_by_source_type( &self, source_type: impl Into<TriggerSourceType>, ) -> Result<Vec<TriggerRegistration>, SessionError>

Source

pub async fn invoke_plugin_action( &self, name: &str, args: Value, session_id: Option<String>, ) -> Result<ToolResult, PluginActionInvokeError>

Source§

impl LashRuntime

Source

pub async fn stream_turn( &mut self, input: TurnInput, opts: TurnOptions<'_>, ) -> Result<AssembledTurn, RuntimeError>

Run a single turn and stream events to the host sink.

Source

pub async fn stream_next_queued_work( &mut self, opts: TurnOptions<'_>, ) -> Result<Option<AssembledTurn>, RuntimeError>

Source

pub async fn stream_selected_queued_work( &mut self, opts: TurnOptions<'_>, batch_ids: &[String], ) -> Result<Option<AssembledTurn>, RuntimeError>

Source

pub async fn stream_turn_with_agent_frames( &mut self, input: TurnInput, opts: TurnOptions<'_>, ) -> Result<AgentFrameRun, RuntimeError>

Stream one logical host turn, following foreground AgentFrame switches until a terminal outcome is reached.

RLM continue_as creates a new frame in the same session. Hosts that only care about the benchmark/app answer should not need to special-case that intermediate outcome; this helper keeps driving the same session through each frame’s task with the normal runtime turn guards.

Source

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.

Source

pub async fn stream_prepared_turn( &mut self, messages: MessageSequence, _previous_prompt_usage: Option<PromptUsage>, protocol_turn_options: Option<ProtocolTurnOptions>, protocol_extension: Option<ProtocolTurnExtensionHandle>, turn_context: TurnContext, initial_turn_causes: Vec<TurnCause>, trace_turn_id: String, turn_index: usize, events: &dyn EventSink, turn_events: &dyn TurnActivitySink, scoped_effect_controller: ScopedEffectController<'_>, cancel: CancellationToken, initial_queue_claim: Option<QueuedWorkClaim>, ) -> Result<AssembledTurn, RuntimeError>

Run a turn using host-prepared message history.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more