Skip to main content

AgentRuntime

Struct AgentRuntime 

Source
pub struct AgentRuntime { /* private fields */ }
Expand description

Top-level agent runtime. Manages runs across threads.

Provides methods for cancelling and sending decisions to active agent runs. Enforces one active run per thread.

Implementations§

Source§

impl AgentRuntime

Source

pub async fn cancel_and_wait_by_thread(&self, thread_id: &str) -> bool

Cancel an active run by thread ID and wait for it to finish.

Returns true only when the run slot is released before the wait timeout. Returns false when no active run exists or cancellation does not finish in time.

Source

pub fn cancel_by_thread(&self, thread_id: &str) -> bool

Cancel an active run by thread ID.

Source

pub fn cancel_by_run_id(&self, run_id: &str) -> bool

Cancel an active run by run ID.

Source

pub fn cancel(&self, id: &str) -> bool

Cancel an active run by dual-index ID (run_id or thread_id). Ambiguous IDs are rejected.

Source

pub fn send_decisions( &self, thread_id: &str, decisions: Vec<(String, ToolCallResume)>, ) -> bool

Send decisions to an active run by thread ID.

Source

pub fn send_decision( &self, id: &str, tool_call_id: String, resume: ToolCallResume, ) -> bool

Send a decision by dual-index ID (run_id or thread_id). Ambiguous IDs are rejected.

Source

pub fn send_messages(&self, id: &str, messages: Vec<Message>) -> bool

Send direct input messages to an active run by run ID or thread ID. Ambiguous IDs are rejected.

Source§

impl AgentRuntime

Source

pub async fn run_to_completion( &self, request: RunRequest, ) -> Result<AgentRunResult, AgentLoopError>

Run an agent loop until it returns an AgentRunResult.

This is a convenience wrapper for one-shot CLI programs and examples that only need the final AgentRunResult. Use Self::run with an EventSink when streaming events to SSE, WebSocket, protocol adapters, or tests.

Source

pub async fn run( &self, request: RunRequest, sink: Arc<dyn EventSink>, ) -> Result<AgentRunResult, AgentLoopError>

Run an agent loop.

This is the single production entry point. It:

  1. Resolves the agent from the registry
  2. Loads thread messages from storage (if configured)
  3. Applies resume decisions (if present in request)
  4. Creates a PhaseRuntime and StateStore
  5. Registers the active run
  6. Calls run_agent_loop internally
  7. Unregisters the run when complete

Run an agent loop. Returns the result when the run completes.

Use cancel() / send_decisions() on AgentRuntime for external control of in-flight runs.

Source§

impl AgentRuntime

Source

pub fn new(resolver: Arc<dyn AgentResolver>) -> AgentRuntime

Source

pub fn new_with_execution_resolver( resolver: Arc<dyn ExecutionResolver>, ) -> AgentRuntime

Source

pub fn with_registry_handle(self, handle: RegistryHandle) -> AgentRuntime

Source

pub fn with_thread_run_store( self, store: Arc<dyn ThreadRunStore>, ) -> AgentRuntime

Source

pub fn with_mailbox_store(self, store: Arc<dyn MailboxStore>) -> AgentRuntime

Wire the mailbox store used to subscribe to live-steering commands for each active run. If unset, runs never receive remote LiveRunCommands — this is the single-process / test default.

Source

pub fn resolver(&self) -> &dyn AgentResolver

Source

pub fn resolver_arc(&self) -> Arc<dyn AgentResolver>

Return a cloned Arc of the agent resolver.

Source

pub fn execution_resolver(&self) -> &dyn ExecutionResolver

Source

pub fn execution_resolver_arc(&self) -> Arc<dyn ExecutionResolver>

Source

pub fn registry_handle(&self) -> Option<RegistryHandle>

Source

pub fn registry_snapshot(&self) -> Option<RegistrySnapshot>

Source

pub fn registry_version(&self) -> Option<u64>

Source

pub fn registry_set(&self) -> Option<RegistrySet>

Source

pub fn replace_registry_set(&self, registries: RegistrySet) -> Option<u64>

Source

pub fn with_composite_registry( self, registry: Arc<CompositeAgentSpecRegistry>, ) -> AgentRuntime

Source

pub fn composite_registry(&self) -> Option<&Arc<CompositeAgentSpecRegistry>>

Return the composite registry, if one was configured.

Source

pub async fn initialize(&self) -> Result<(), RuntimeError>

Initialize the runtime — discover remote agents. Call this after build() to complete async initialization.

Source

pub fn thread_run_store(&self) -> Option<&dyn ThreadRunStore>

Trait Implementations§

Source§

impl RunDispatchExecutor for AgentRuntime

Source§

fn run<'life0, 'async_trait>( &'life0 self, request: RunRequest, sink: Arc<dyn EventSink>, ) -> Pin<Box<dyn Future<Output = Result<AgentRunResult, AgentLoopError>> + Send + 'async_trait>>
where 'life0: 'async_trait, AgentRuntime: 'async_trait,

Execute a run request and stream events into the provided sink.
Source§

fn run_with_thread_context<'life0, 'async_trait>( &'life0 self, request: RunRequest, sink: Arc<dyn EventSink>, thread_ctx: Option<ThreadContextSnapshot>, ) -> Pin<Box<dyn Future<Output = Result<AgentRunResult, AgentLoopError>> + Send + 'async_trait>>
where 'life0: 'async_trait, AgentRuntime: 'async_trait,

Execute a run with an optional mailbox-provided thread cache.
Source§

fn cancel(&self, id: &str) -> bool

Cancel an active run by run id or thread id.
Source§

fn cancel_and_wait_by_thread<'life0, 'life1, 'async_trait>( &'life0 self, thread_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, AgentRuntime: 'async_trait,

Cancel an active run by thread id and wait for it to unregister.
Source§

fn send_decision( &self, id: &str, tool_call_id: String, resume: ToolCallResume, ) -> bool

Forward one human/tool decision to an active run.
Source§

fn send_messages(&self, id: &str, messages: Vec<Message>) -> bool

Forward direct input messages to an active run.

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> IntoMaybeUndefined<T> for T

Source§

impl<T> IntoOption<T> for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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