pub struct ToolBatch { /* private fields */ }Expand description
One tool batch with a completed prefix and pending suffix.
Each result joins the end of the completed prefix as it is resolved, so
the prefix is in resolution order: with concurrent dispatch, the order the
calls completed in, not the order the model declared them in. That order
is what ToolBatch::into_results returns and what a runner commits. To
keep declaration order instead, sort ToolBatch::results_mut by
ProcessorContext::declaration_order in a processor that runs after
dispatch.
Implementations§
Source§impl ToolBatch
impl ToolBatch
Sourcepub fn new(calls: Vec<ToolCallContext>) -> Result<Self, BatchError>
pub fn new(calls: Vec<ToolCallContext>) -> Result<Self, BatchError>
Creates a batch from declarations in their original order.
Sourcepub fn calls(&self) -> &[ToolCallEntry]
pub fn calls(&self) -> &[ToolCallEntry]
Returns the pending suffix.
Sourcepub fn calls_mut(&mut self) -> &mut [ToolCallEntry]
pub fn calls_mut(&mut self) -> &mut [ToolCallEntry]
Mutably returns the pending suffix.
Sourcepub fn results(&self) -> &[ToolCallEntry]
pub fn results(&self) -> &[ToolCallEntry]
Returns the completed prefix.
Sourcepub fn results_mut(&mut self) -> &mut [ToolCallEntry]
pub fn results_mut(&mut self) -> &mut [ToolCallEntry]
Mutably returns the completed prefix for output editing and ordering.
Sourcepub fn completed_len(&self) -> usize
pub fn completed_len(&self) -> usize
Returns the number of completed entries.
Sourcepub fn declaration_ids(&self) -> Vec<BlockId>
pub fn declaration_ids(&self) -> Vec<BlockId>
Returns declaration identities in the batch’s current entry order.
Sourcepub fn validate(&self) -> Result<(), BatchError>
pub fn validate(&self) -> Result<(), BatchError>
Validates the completed-prefix/pending-suffix and identity invariants.
Sourcepub fn resolve_at(
&mut self,
index: usize,
result_block_id: BlockId,
result: ToolResultPayload,
) -> Result<(), RejectedToolResult>
pub fn resolve_at( &mut self, index: usize, result_block_id: BlockId, result: ToolResultPayload, ) -> Result<(), RejectedToolResult>
Installs a result at an absolute entry index and advances the prefix,
prepending any pending result_notes and clearing the entry’s
CallAttachments. A refused result leaves the batch unchanged
(including its attachments) and is handed back with the reason, so a
caller can retry or report it without a copy.
Sourcepub fn validate_complete(&self) -> Result<(), BatchError>
pub fn validate_complete(&self) -> Result<(), BatchError>
Validates the invariants and that every entry has a result.
Sourcepub fn into_results(
self,
) -> Result<Vec<(BlockId, ToolResultPayload)>, (BatchError, Self)>
pub fn into_results( self, ) -> Result<Vec<(BlockId, ToolResultPayload)>, (BatchError, Self)>
Consumes a fully completed batch into result blocks in current order.