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) -> Self
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).
Sourcepub fn with_tool_registry(self, registry: ToolRegistry) -> Self
pub fn with_tool_registry(self, registry: ToolRegistry) -> Self
Replaces the tool runtime with one backed by the given registry.
Sourcepub fn with_snapshot_store(self, snapshot_store: Arc<dyn SnapshotStore>) -> Self
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.
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) -> RuntimeResult<RunOutput>
pub async fn run(&self, request: RunRequest) -> RuntimeResult<RunOutput>
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) -> RuntimeResult<RunOutput>
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.