pub struct AgentRun { /* private fields */ }Expand description
Runtime-owned single-consumer protocol for one agent run.
Self::next_message is the only output path. It yields durable runtime
events and explicit host-owned tool batches from the same ordered channel,
so a consumer cannot accidentally skip a tool handoff by using an
event-only stream. Runtime state owns the active batch and its lifecycle.
Implementations§
Source§impl AgentRun
impl AgentRun
Sourcepub async fn submit_bridge_tool_outcomes(
&mut self,
batch_id: &ToolCallBatchId,
outcomes: Vec<(ToolCallId, ToolExecutionOutcome)>,
) -> Result<(), RuntimeError>
pub async fn submit_bridge_tool_outcomes( &mut self, batch_id: &ToolCallBatchId, outcomes: Vec<(ToolCallId, ToolExecutionOutcome)>, ) -> Result<(), RuntimeError>
Submits a complete batch of host-executed tool outcomes.
The host may prepare results concurrently, then submit the complete set in any order. The batch itself does not grant parallel-execution safety; the runtime validates the complete set and records it in pending-call order before starting the next model turn. Correctable validation errors keep the batch pending; a non-correctable recording error is converted into a failed tool result so the model loop can still recover.
Sourcepub async fn result(&mut self) -> Result<AgentLoopResult, AgentLoopError>
pub async fn result(&mut self) -> Result<AgentLoopResult, AgentLoopError>
Returns the collected loop result once the run has completed.
Unconsumed events are drained. An unresolved host-tool batch is reported as an error and cancellation is requested so the producer cannot remain blocked waiting for a result that the caller has abandoned.
Sourcepub async fn cancel_and_wait(&mut self)
pub async fn cancel_and_wait(&mut self)
Cancels the loop producer and waits until its task has stopped.
This is the output-boundary cancellation path: once a consumer cannot accept another event, callers must stop provider/tool work before settling and persisting the runtime state.
Sourcepub async fn next_message(
&mut self,
) -> Result<Option<AgentRunMessage>, RuntimeError>
pub async fn next_message( &mut self, ) -> Result<Option<AgentRunMessage>, RuntimeError>
Returns the next runtime-owned run message.
SDK host adapters use this to execute bridge tool calls without
exposing bridge handoff as a public RuntimeEvent.
Sourcepub async fn next(&mut self) -> Result<Option<AgentRunMessage>, RuntimeError>
pub async fn next(&mut self) -> Result<Option<AgentRunMessage>, RuntimeError>
Returns the next runtime-owned run message.
This Rust convenience alias has the same message-first semantics as
Self::next_message; it never filters host-tool handoffs.
Sourcepub fn request_cancel(&mut self)
pub fn request_cancel(&mut self)
Requests cancellation without waiting for the producer task to stop.
This is intended for synchronous cleanup guards that cannot await, such
as a facade tool-invocation lease being dropped before it is resolved.
Callers that own an async lifecycle should prefer Self::cancel_and_wait
so producer completion and the terminal result are observed explicitly.