Skip to main content

AgentRuntime

Struct AgentRuntime 

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

Streaming-first agent runtime kernel.

Ties together provider registry, context pipeline, tool runtime, compaction service, persistent stores, snapshot recovery, session gating, and input admission into a complete agent execution loop.

Implementations§

Source§

impl AgentRuntime

Source

pub fn new(extensions: Arc<Extensions>, policy: RuntimePolicy) -> Self

Creates a new agent runtime from an Extensions facade and a RuntimePolicy.

Internally constructs a ProviderRegistry, RuntimeStore, ContextPipeline, and ToolRuntime from the extensions or their defaults. Use with_tool_registry to populate the tool runtime, and the with_* setters for optional components (event publisher, snapshot store).

Source

pub fn with_tool_registry(self, registry: ToolRegistry) -> Self

Replaces the tool runtime with one backed by the given registry.

Source

pub fn with_snapshot_store(self, snapshot_store: Arc<dyn SnapshotStore>) -> Self

Sets an optional snapshot store for FSM run recovery.

When configured, intermediate run state is persisted after each turn, allowing crashed runs to be resumed via resume.

Source

pub fn extensions(&self) -> &Arc<Extensions>

Returns the composable Extensions facade.

Use this to register, replace, or look up providers, tools, context adapters, stores, and other pluggable elements by name. The facade is shared with the runtime’s internal references, so registering here is equivalent to using the with_* setters.

Source

pub fn session_gate(&self) -> &SessionGate

Returns the session gate used to serialize concurrent runs per session.

Source

pub fn subscribe(&self) -> Receiver<AgentEvent>

Subscribes to runtime events via a tokio broadcast receiver.

The receiver starts with the oldest event still in the buffer (capacity 256). Slow consumers that fall behind will miss events.

Source

pub fn policy(&self) -> &RuntimePolicy

Returns the runtime policy.

Source

pub fn tools(&self) -> &ToolRuntime

Returns the tool runtime.

Source

pub fn providers(&self) -> &ProviderRegistry

Returns the provider registry.

Source

pub fn context(&self) -> &ContextPipeline

Returns the context pipeline.

Source

pub fn store(&self) -> &Arc<RuntimeStore>

Returns the runtime store.

Source

pub fn compaction(&self) -> &CompactionService

Returns the compaction service.

Source

pub fn snapshot_store(&self) -> Option<&Arc<dyn SnapshotStore>>

Returns the snapshot store, if configured.

Source

pub fn sessions(&self) -> &dyn SessionStore

Returns the session store.

Source

pub fn executions(&self) -> &dyn ExecutionStore

Returns the execution store.

Source

pub fn runs(&self) -> &dyn RunStore

Returns the run store.

Source

pub fn embeddings(&self) -> Option<&dyn EmbeddingStore>

Returns the embedding store, if configured.

Source

pub fn artifacts(&self) -> Option<&dyn ArtifactStore>

Returns the artifact store, if configured.

Source

pub async fn run(&self, request: RunRequest) -> RuntimeResult<RunOutput>

Executes an agent run to completion.

The run loop:

  1. Creates or loads a session
  2. Persists the user message
  3. Iterates: build context → call model → persist response → execute tools → repeat
  4. Returns the final run ID and finish reason
§Errors

Returns RuntimeError on provider, store, context, or policy violations.

Source

pub async fn resume(&self, run_id: RunId) -> RuntimeResult<RunOutput>

Resumes a crashed or halted agent run from its last saved snapshot.

Loads the snapshot by run_id, re-acquires the session lock, pushes a Run-level tool scope, and restarts the turn loop from the saved state.

§Errors

Returns RuntimeError if the snapshot is not found, the session is busy, or resuming fails.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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