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
impl AgentRuntime
Sourcepub async fn cancel_and_wait_by_thread(&self, thread_id: &str) -> bool
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.
Sourcepub fn cancel_by_thread(&self, thread_id: &str) -> bool
pub fn cancel_by_thread(&self, thread_id: &str) -> bool
Cancel an active run by thread ID.
Sourcepub fn cancel_by_run_id(&self, run_id: &str) -> bool
pub fn cancel_by_run_id(&self, run_id: &str) -> bool
Cancel an active run by run ID.
Sourcepub fn cancel(&self, id: &str) -> bool
pub fn cancel(&self, id: &str) -> bool
Cancel an active run by dual-index ID (run_id or thread_id). Ambiguous IDs are rejected.
Sourcepub fn send_decisions(
&self,
thread_id: &str,
decisions: Vec<(String, ToolCallResume)>,
) -> bool
pub fn send_decisions( &self, thread_id: &str, decisions: Vec<(String, ToolCallResume)>, ) -> bool
Send decisions to an active run by thread ID.
Sourcepub fn send_decision(
&self,
id: &str,
tool_call_id: String,
resume: ToolCallResume,
) -> bool
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
impl AgentRuntime
Sourcepub async fn run_to_completion(
&self,
request: RunRequest,
) -> Result<AgentRunResult, AgentLoopError>
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.
Sourcepub async fn run(
&self,
request: RunRequest,
sink: Arc<dyn EventSink>,
) -> Result<AgentRunResult, AgentLoopError>
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:
- Resolves the agent from the registry
- Loads thread messages from storage (if configured)
- Applies resume decisions (if present in request)
- Creates a PhaseRuntime and StateStore
- Registers the active run
- Calls
run_agent_loopinternally - 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
impl AgentRuntime
pub fn new(resolver: Arc<dyn AgentResolver>) -> Self
pub fn new_with_execution_resolver(resolver: Arc<dyn ExecutionResolver>) -> Self
pub fn with_registry_handle(self, handle: RegistryHandle) -> Self
pub fn with_thread_run_store(self, store: Arc<dyn ThreadRunStore>) -> Self
pub fn resolver(&self) -> &dyn AgentResolver
Sourcepub fn resolver_arc(&self) -> Arc<dyn AgentResolver>
pub fn resolver_arc(&self) -> Arc<dyn AgentResolver>
Return a cloned Arc of the agent resolver.
pub fn execution_resolver(&self) -> &dyn ExecutionResolver
pub fn execution_resolver_arc(&self) -> Arc<dyn ExecutionResolver>
pub fn registry_handle(&self) -> Option<RegistryHandle>
pub fn registry_snapshot(&self) -> Option<RegistrySnapshot>
pub fn registry_version(&self) -> Option<u64>
pub fn registry_set(&self) -> Option<RegistrySet>
pub fn replace_registry_set(&self, registries: RegistrySet) -> Option<u64>
pub fn with_composite_registry( self, registry: Arc<CompositeAgentSpecRegistry>, ) -> Self
Sourcepub fn composite_registry(&self) -> Option<&Arc<CompositeAgentSpecRegistry>>
pub fn composite_registry(&self) -> Option<&Arc<CompositeAgentSpecRegistry>>
Return the composite registry, if one was configured.
Sourcepub async fn initialize(&self) -> Result<(), RuntimeError>
pub async fn initialize(&self) -> Result<(), RuntimeError>
Initialize the runtime — discover remote agents.
Call this after build() to complete async initialization.