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
impl AgentRuntime
Sourcepub fn new(extensions: Arc<Extensions>, policy: RuntimePolicy) -> AgentRuntime
pub fn new(extensions: Arc<Extensions>, policy: RuntimePolicy) -> AgentRuntime
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).
Sourcepub fn with_tool_registry(self, registry: ToolRegistry) -> AgentRuntime
pub fn with_tool_registry(self, registry: ToolRegistry) -> AgentRuntime
Replaces the tool runtime with one backed by the given registry.
Sourcepub fn with_event_publisher(
self,
publisher: Arc<dyn EventPublisher>,
) -> AgentRuntime
pub fn with_event_publisher( self, publisher: Arc<dyn EventPublisher>, ) -> AgentRuntime
Sets an external event publisher for the agent runtime.
When set, every AgentEvent emitted during a run will also be
published to the configured EventPublisher via fire-and-forget.
Requires the queue feature.
Sourcepub fn with_snapshot_store(
self,
snapshot_store: Arc<dyn SnapshotStore>,
) -> AgentRuntime
pub fn with_snapshot_store( self, snapshot_store: Arc<dyn SnapshotStore>, ) -> AgentRuntime
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.
Sourcepub fn extensions(&self) -> &Arc<Extensions> ⓘ
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.
Sourcepub fn session_gate(&self) -> &SessionGate
pub fn session_gate(&self) -> &SessionGate
Returns the session gate used to serialize concurrent runs per session.
Sourcepub fn subscribe(&self) -> Receiver<AgentEvent>
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.
Sourcepub fn policy(&self) -> &RuntimePolicy
pub fn policy(&self) -> &RuntimePolicy
Returns the runtime policy.
Sourcepub fn tools(&self) -> &ToolRuntime
pub fn tools(&self) -> &ToolRuntime
Returns the tool runtime.
Sourcepub fn providers(&self) -> &ProviderRegistry
pub fn providers(&self) -> &ProviderRegistry
Returns the provider registry.
Sourcepub fn context(&self) -> &ContextPipeline
pub fn context(&self) -> &ContextPipeline
Returns the context pipeline.
Sourcepub fn store(&self) -> &Arc<RuntimeStore> ⓘ
pub fn store(&self) -> &Arc<RuntimeStore> ⓘ
Returns the runtime store.
Sourcepub fn compaction(&self) -> &CompactionService
pub fn compaction(&self) -> &CompactionService
Returns the compaction service.
Sourcepub fn snapshot_store(&self) -> Option<&Arc<dyn SnapshotStore>>
pub fn snapshot_store(&self) -> Option<&Arc<dyn SnapshotStore>>
Returns the snapshot store, if configured.
Sourcepub fn sessions(&self) -> &dyn SessionStore
pub fn sessions(&self) -> &dyn SessionStore
Returns the session store.
Sourcepub fn executions(&self) -> &dyn ExecutionStore
pub fn executions(&self) -> &dyn ExecutionStore
Returns the execution store.
Sourcepub fn embeddings(&self) -> Option<&dyn EmbeddingStore>
pub fn embeddings(&self) -> Option<&dyn EmbeddingStore>
Returns the embedding store, if configured.
Sourcepub fn artifacts(&self) -> Option<&dyn ArtifactStore>
pub fn artifacts(&self) -> Option<&dyn ArtifactStore>
Returns the artifact store, if configured.
Sourcepub async fn run(&self, request: RunRequest) -> Result<RunOutput, RuntimeError>
pub async fn run(&self, request: RunRequest) -> Result<RunOutput, RuntimeError>
Executes an agent run to completion.
The run loop:
- Creates or loads a session
- Persists the user message
- Iterates: build context → call model → persist response → execute tools → repeat
- Returns the final run ID and finish reason
§Errors
Returns RuntimeError on provider, store, context, or policy violations.
Sourcepub async fn resume(&self, run_id: RunId) -> Result<RunOutput, RuntimeError>
pub async fn resume(&self, run_id: RunId) -> Result<RunOutput, RuntimeError>
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§
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.