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 if a run was cancelled, false if no active run existed. Waits up to 5 seconds for the run to actually unregister.

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§

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>) -> Self

Source

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

Source

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

Source

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

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

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>

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