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: HImplementations§
Source§impl<M: Model + Send + Sync + Clone + 'static, H: Hook + 'static> Runtime<M, H>
impl<M: Model + Send + Sync + Clone + 'static, H: Hook + 'static> Runtime<M, H>
Sourcepub async fn new(model: M, hook: H) -> Self
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.
Sourcepub async fn register_tool(&self, tool: Tool, handler: Handler)
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).
Sourcepub async fn unregister_tool(&self, name: &str) -> bool
pub async fn unregister_tool(&self, name: &str) -> bool
Remove a tool by name. Returns true if it existed.
Sourcepub async fn replace_tools(
&self,
old_names: &[CompactString],
new_tools: Vec<(Tool, Handler)>,
)
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.
Sourcepub fn add_agent(&mut self, config: AgentConfig)
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.
Sourcepub async fn agent(&self, name: &str) -> Option<AgentConfig>
pub async fn agent(&self, name: &str) -> Option<AgentConfig>
Get a registered agent’s config by name (cloned).
Sourcepub async fn agents(&self) -> Vec<AgentConfig>
pub async fn agents(&self) -> Vec<AgentConfig>
Get all registered agent configs (cloned, alphabetical order).
Sourcepub fn agent_mutex(&self, name: &str) -> Option<Arc<Mutex<Agent<M>>>>
pub fn agent_mutex(&self, name: &str) -> Option<Arc<Mutex<Agent<M>>>>
Get the per-agent mutex by name.
Sourcepub async fn clear_session(&self, agent: &str)
pub async fn clear_session(&self, agent: &str)
Clear the conversation history for a named agent.
Sourcepub async fn send_to(&self, agent: &str, content: &str) -> Result<AgentResponse>
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().
Sourcepub fn stream_to<'a>(
&'a self,
agent: &'a str,
content: &'a str,
) -> impl Stream<Item = AgentEvent> + 'a
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().