pub struct Runtime { /* private fields */ }Expand description
Entry point for configuring providers, tools, and agent lifecycles.
A runtime composes four main subsystems:
- execution: providers, policies, hooks, and command execution
- persistence: agent state, runs, tasks, leases, and memory
- tooling: registered tools, skills, and app context
- collaboration: persistent teams and background task coordination
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn empty_builder() -> RuntimeBuilder
pub fn empty_builder() -> RuntimeBuilder
Returns a builder with no builtin tools registered.
Sourcepub fn register_tool<T>(&self, tool: T)where
T: ExecutableTool + 'static,
pub fn register_tool<T>(&self, tool: T)where
T: ExecutableTool + 'static,
Registers a custom tool on the runtime after construction.
Sourcepub fn register_context(&self, context: Arc<dyn Any + Send + Sync>)
pub fn register_context(&self, context: Arc<dyn Any + Send + Sync>)
Registers typed application state that tools can retrieve from their context.
Sourcepub fn app_context<T>(&self) -> Result<Arc<T>, String>
pub fn app_context<T>(&self) -> Result<Arc<T>, String>
Returns typed application state previously registered on this runtime.
Sourcepub fn register_skills_dir(
&self,
path: impl AsRef<Path>,
) -> Result<(), SkillLoadError>
pub fn register_skills_dir( &self, path: impl AsRef<Path>, ) -> Result<(), SkillLoadError>
Registers a skills directory and enables the builtin load_skill tool.
Sourcepub fn spawn(
&self,
name: impl Into<String>,
model: ModelInfo,
) -> Result<Agent, RuntimeError>
pub fn spawn( &self, name: impl Into<String>, model: ModelInfo, ) -> Result<Agent, RuntimeError>
Spawns a new agent with the default AgentConfig.
Sourcepub fn spawn_with_config(
&self,
name: impl Into<String>,
model: ModelInfo,
config: AgentConfig,
) -> Result<Agent, RuntimeError>
pub fn spawn_with_config( &self, name: impl Into<String>, model: ModelInfo, config: AgentConfig, ) -> Result<Agent, RuntimeError>
Spawns a new agent with an explicit configuration.
Sourcepub fn resume_agent(&self, agent_id: &str) -> Result<Agent, RuntimeError>
pub fn resume_agent(&self, agent_id: &str) -> Result<Agent, RuntimeError>
Restores a previously persisted agent by identifier.
Sourcepub fn resume(
&self,
runtime_identifier: &str,
) -> Result<Vec<Agent>, RuntimeError>
pub fn resume( &self, runtime_identifier: &str, ) -> Result<Vec<Agent>, RuntimeError>
Restores every persisted agent that belongs to the provided runtime identifier.
Sourcepub fn list_persisted_agents(
&self,
runtime_identifier: &str,
) -> Result<Vec<PersistedAgentSummary>, RuntimeError>
pub fn list_persisted_agents( &self, runtime_identifier: &str, ) -> Result<Vec<PersistedAgentSummary>, RuntimeError>
Lists persisted agents for a runtime identifier without reviving them.
Sourcepub fn resume_all(&self) -> Result<Vec<Agent>, RuntimeError>
pub fn resume_all(&self) -> Result<Vec<Agent>, RuntimeError>
Restores every persisted agent known to the runtime store.
Source§impl Runtime
impl Runtime
Sourcepub fn providers(&self) -> Vec<ProviderDescriptor>
pub fn providers(&self) -> Vec<ProviderDescriptor>
Returns descriptors for registered providers.
Sourcepub fn register_provider(
&mut self,
id: BuiltinProvider,
api_key: impl Into<String>,
) -> Result<(), String>
pub fn register_provider( &mut self, id: BuiltinProvider, api_key: impl Into<String>, ) -> Result<(), String>
Registers a builtin provider from an API key.
Sourcepub fn register_provider_instance<P>(&mut self, provider: P)where
P: Provider + 'static,
pub fn register_provider_instance<P>(&mut self, provider: P)where
P: Provider + 'static,
Registers a custom provider implementation.
This is the supported seam for injecting a scripted provider in tests or embedding Mentra on top of a custom transport.
use async_trait::async_trait;
use mentra::{BuiltinProvider, ModelInfo, ProviderDescriptor, Runtime};
use mentra::error::{ProviderError, RuntimeError};
use mentra::provider::{Provider, ProviderEventStream, Request};
use tokio::sync::mpsc;
struct TestProvider;
#[async_trait]
impl Provider for TestProvider {
fn descriptor(&self) -> ProviderDescriptor {
ProviderDescriptor::new(BuiltinProvider::Anthropic)
}
async fn list_models(&self) -> Result<Vec<ModelInfo>, ProviderError> {
Ok(vec![ModelInfo::new("test-model", BuiltinProvider::Anthropic)])
}
async fn stream(
&self,
_request: Request<'_>,
) -> Result<ProviderEventStream, ProviderError> {
let (_tx, rx) = mpsc::unbounded_channel();
Ok(rx)
}
}
let mut runtime = Runtime::empty_builder()
.with_provider(BuiltinProvider::Anthropic, "placeholder")
.build()?;
runtime.register_provider_instance(TestProvider);Sourcepub async fn list_models(
&self,
provider: Option<&ProviderId>,
) -> Result<Vec<ModelInfo>, RuntimeError>
pub async fn list_models( &self, provider: Option<&ProviderId>, ) -> Result<Vec<ModelInfo>, RuntimeError>
Lists models for a specific provider, or the default provider when omitted.
Sourcepub async fn resolve_model(
&self,
provider: impl Into<ProviderId>,
selector: ModelSelector,
) -> Result<ModelInfo, RuntimeError>
pub async fn resolve_model( &self, provider: impl Into<ProviderId>, selector: ModelSelector, ) -> Result<ModelInfo, RuntimeError>
Resolves a model for a registered provider using a deterministic selection strategy.