Skip to main content

Runtime

Struct Runtime 

Source
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

Source

pub fn builder() -> RuntimeBuilder

Returns a builder with Mentra’s builtin tools enabled.

Source

pub fn empty_builder() -> RuntimeBuilder

Returns a builder with no builtin tools registered.

Source

pub fn register_tool<T>(&self, tool: T)
where T: ExecutableTool + 'static,

Registers a custom tool on the runtime after construction.

Source

pub fn register_context(&self, context: Arc<dyn Any + Send + Sync>)

Registers typed application state that tools can retrieve from their context.

Source

pub fn app_context<T>(&self) -> Result<Arc<T>, String>
where T: Any + Send + Sync + 'static,

Returns typed application state previously registered on this runtime.

Source

pub fn register_skills_dir( &self, path: impl AsRef<Path>, ) -> Result<(), SkillLoadError>

Registers a skills directory and enables the builtin load_skill tool.

Source

pub fn spawn( &self, name: impl Into<String>, model: ModelInfo, ) -> Result<Agent, RuntimeError>

Spawns a new agent with the default AgentConfig.

Source

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.

Source

pub fn resume_agent(&self, agent_id: &str) -> Result<Agent, RuntimeError>

Restores a previously persisted agent by identifier.

Source

pub fn resume( &self, runtime_identifier: &str, ) -> Result<Vec<Agent>, RuntimeError>

Restores every persisted agent that belongs to the provided runtime identifier.

Source

pub fn list_persisted_agents( &self, runtime_identifier: &str, ) -> Result<Vec<PersistedAgentSummary>, RuntimeError>

Lists persisted agents for a runtime identifier without reviving them.

Source

pub fn resume_all(&self) -> Result<Vec<Agent>, RuntimeError>

Restores every persisted agent known to the runtime store.

Source§

impl Runtime

Source

pub fn providers(&self) -> Vec<ProviderDescriptor>

Returns descriptors for registered providers.

Source

pub fn register_provider( &mut self, id: BuiltinProvider, api_key: impl Into<String>, ) -> Result<(), String>

Registers a builtin provider from an API key.

Source

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);
Source

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.

Source

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.

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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, 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