Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime<M: Model, H: Hook> {
    pub model: M,
    pub hook: H,
    /* private fields */
}
Expand description

The walrus runtime — agent registry, tool registry, and hook orchestration.

Each agent is wrapped in a per-agent Mutex for concurrent execution. Tools are stored in a shared ToolRegistry behind Arc<RwLock>. Runtime::new() is async — it calls hook.on_register_tools() during construction so hooks self-register their tools.

Fields§

§model: M§hook: H

Implementations§

Source§

impl<M: Model + Send + Sync + Clone + 'static, H: Hook + 'static> Runtime<M, H>

Source

pub async fn new(model: M, hook: H) -> Self

Create a new runtime with the given model and hook backend.

Calls hook.on_register_tools() to populate the tool registry before returning. All hook crates self-register their tools here.

Source

pub async fn register_tool(&self, tool: Tool, handler: Handler)

Register a tool with its handler.

Works both before and after wrapping in Arc (the registry is behind RwLock). Used for hot-reload (MCP add/remove/reload).

Source

pub async fn unregister_tool(&self, name: &str) -> bool

Remove a tool by name. Returns true if it existed.

Source

pub async fn replace_tools( &self, old_names: &[CompactString], new_tools: Vec<(Tool, Handler)>, )

Atomically replace a set of tools.

Removes old_names and inserts new_tools under a single write lock — no window where agents see partial state.

Source

pub fn add_agent(&mut self, config: AgentConfig)

Register an agent from its configuration.

Must be called before wrapping the runtime in Arc. Calls hook.on_build_agent(config) to enrich the config before building.

Source

pub async fn agent(&self, name: &str) -> Option<AgentConfig>

Get a registered agent’s config by name (cloned).

Source

pub async fn agents(&self) -> Vec<AgentConfig>

Get all registered agent configs (cloned, alphabetical order).

Source

pub fn agent_mutex(&self, name: &str) -> Option<Arc<Mutex<Agent<M>>>>

Get the per-agent mutex by name.

Source

pub async fn clear_session(&self, agent: &str)

Clear the conversation history for a named agent.

Source

pub async fn send_to(&self, agent: &str, content: &str) -> Result<AgentResponse>

Send a message to an agent and run to completion.

Builds a dispatcher snapshot from the tool registry, locks the per-agent mutex, pushes the user message, delegates to agent.run(), and forwards all events to hook.on_event().

Source

pub fn stream_to<'a>( &'a self, agent: &'a str, content: &'a str, ) -> impl Stream<Item = AgentEvent> + 'a

Send a message to an agent and stream response events.

Builds a dispatcher snapshot from the tool registry, locks the per-agent mutex, delegates to agent.run_stream(), and forwards each event to hook.on_event().

Auto Trait Implementations§

§

impl<M, H> Freeze for Runtime<M, H>
where M: Freeze, H: Freeze,

§

impl<M, H> !RefUnwindSafe for Runtime<M, H>

§

impl<M, H> Send for Runtime<M, H>
where M: Send,

§

impl<M, H> Sync for Runtime<M, H>
where M: Sync + Send,

§

impl<M, H> Unpin for Runtime<M, H>
where M: Unpin, H: Unpin,

§

impl<M, H> UnsafeUnpin for Runtime<M, H>
where M: UnsafeUnpin, H: UnsafeUnpin,

§

impl<M, H> !UnwindSafe for Runtime<M, H>

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, 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, 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.