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, session store, and hook orchestration.

Agents are stored as plain immutable values. Sessions own conversation history behind per-session Arc<Mutex<Session>>. The sessions map uses RwLock for concurrent access without requiring &mut self.

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, tool_tx: Option<ToolSender>) -> Self

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

Calls hook.on_register_tools() to populate the schema registry. Pass tool_tx to enable tool dispatch from agents; None means agents have no tool dispatch (e.g. CLI without a daemon).

Source

pub fn register_tool(&mut self, tool: Tool)

Register a tool schema.

Source

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

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

Source

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

Register an agent from its configuration.

Calls hook.on_build_agent(config) to enrich the config, then builds the agent with a filtered schema snapshot and the runtime’s tool_tx.

Source

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

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

Source

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

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

Source

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

Get a reference to an agent by name.

Source

pub async fn create_session(&self, agent: &str, created_by: &str) -> Result<u64>

Create a new session for the given agent. Returns the session ID.

Source

pub async fn close_session(&self, id: u64) -> bool

Close (remove) a session by ID. Returns true if it existed.

Source

pub async fn session(&self, id: u64) -> Option<Arc<Mutex<Session>>>

Get a session mutex by ID.

Source

pub async fn sessions(&self) -> Vec<Arc<Mutex<Session>>>

Get all session mutexes (for iteration/listing).

Source

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

Send a message to a session and run to completion.

Locks the session, looks up the agent, pushes the user message, delegates to agent.run(), and forwards events to hook.on_event().

Source

pub fn stream_to( &self, session_id: u64, content: &str, sender: &str, ) -> impl Stream<Item = AgentEvent> + '_

Send a message to a session and stream response events.

Locks the session, looks up the agent, pushes the user message, and streams events forwarded to hook.on_event().

Auto Trait Implementations§

§

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

§

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,

§

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