pub enum ToolResult {
Done(Box<ToolCallOutput>),
Pending(PendingCompletion),
}Expand description
The outcome a ToolProvider::execute returns
for a single call.
The variant a tool returns chooses its completion mode:
ToolResult::Done— active await. The result is available inline and the runtime finalizes the call immediately. Construct it withToolResult::ok,ToolResult::err,ToolResult::failure, and friends.ToolResult::Pending— deferred / callback completion. The tool has launched out-of-band work (a webhook, a human approval, another service) and the real outcome is delivered later against a completion key.
§The completion-key contract
Before returning ToolResult::Pending, a tool must first obtain a completion
key by calling ToolContext::completion_key
(reachable through call.context). That key names the durable wait the runtime parks
the call on, and is what an external resolver uses to deliver the outcome. Returning
Pending without having taken a completion key fails the call with the internal
error pending_tool_missing_completion_key.
async fn execute(&self, call: ToolCall<'_>) -> ToolResult {
// Take the key first, then hand it to whatever completes the work out-of-band.
let key = match call.context.completion_key().await {
Ok(key) => key,
Err(err) => return ToolResult::err_fmt(err),
};
enqueue_external_work(key);
ToolResult::pending(PendingCompletion::new())
}Variants§
Done(Box<ToolCallOutput>)
Active await: the tool finished inline; this is its final output.
Pending(PendingCompletion)
Deferred completion: the tool parked on a durable wait keyed by the
ToolContext::completion_key it took
before returning. The outcome arrives later through the resolve seam and is
shaped by the carried PendingCompletion.
Implementations§
Source§impl ToolResult
impl ToolResult
pub fn from_output(output: ToolCallOutput) -> Self
pub fn pending(pending: PendingCompletion) -> Self
pub fn ok(result: Value) -> Self
pub fn err(result: Value) -> Self
pub fn err_fmt(msg: impl Display) -> Self
pub fn failure(failure: ToolFailure) -> Self
pub fn retryable_failure( class: ToolFailureClass, code: impl Into<String>, message: impl Into<String>, after_ms: Option<u64>, ) -> Self
pub fn cancelled(message: impl Into<String>) -> Self
pub fn cancelled_with_raw(message: impl Into<String>, raw: Value) -> Self
pub fn with_control(self, control: ToolControl) -> Self
pub fn is_success(&self) -> bool
pub fn is_pending(&self) -> bool
pub fn value_for_projection(&self) -> Value
pub fn as_done_output(&self) -> Option<&ToolCallOutput>
pub fn as_output(&self) -> &ToolCallOutput
pub fn into_done_output(self) -> Result<ToolCallOutput, PendingCompletion>
Trait Implementations§
Source§impl Clone for ToolResult
impl Clone for ToolResult
Source§fn clone(&self) -> ToolResult
fn clone(&self) -> ToolResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ToolResult
impl Debug for ToolResult
Source§impl<T, E> From<Result<T, E>> for ToolResult
impl<T, E> From<Result<T, E>> for ToolResult
Source§impl PartialEq for ToolResult
impl PartialEq for ToolResult
Source§fn eq(&self, other: &ToolResult) -> bool
fn eq(&self, other: &ToolResult) -> bool
self and other values to be equal, and is used by ==.