pub struct Tool {
pub id: CallId,
pub call: FunctionCall,
pub status: ToolStatus,
}Expand description
A tool invocation paired with its lifecycle state.
Replaces the previous split of PartEnum::FunctionCall and
PartEnum::FunctionResponse. Call and result live on the same part; the
status field tracks where the tool is in its lifecycle (waiting for
human approval, running, completed, rejected, or failed).
Fields§
§id: CallId§call: FunctionCall§status: ToolStatusImplementations§
Source§impl Tool
impl Tool
Sourcepub fn new(call: FunctionCall) -> Tool
pub fn new(call: FunctionCall) -> Tool
Create a new Tool in Pending state from a model-emitted call.
Uses the call’s existing id, or mints a fresh one.
Sourcepub fn is_resolved(&self) -> bool
pub fn is_resolved(&self) -> bool
True if the Tool has reached a final state (Completed, Rejected, Failed). Resolved tools are safe to send on the wire.
pub fn is_pending(&self) -> bool
Sourcepub fn is_executing(&self) -> bool
pub fn is_executing(&self) -> bool
True if the tool has been approved (or auto-approved) and is either queued or running.
Sourcepub fn effective_call(&self) -> &FunctionCall
pub fn effective_call(&self) -> &FunctionCall
The call as it should actually be executed. Honors edits made during approval; otherwise returns the original model-emitted call.
Sourcepub fn response(&self) -> Option<&FunctionResponse>
pub fn response(&self) -> Option<&FunctionResponse>
The successful response, if any. Returns None for any non-Completed
state — including Failed and Rejected. Use Tool::to_tuple for the
wire-ready projection.
pub fn approve(&mut self, edited_call: Option<FunctionCall>)
pub fn reject(&mut self, reason: Option<String>)
pub fn mark_running(&mut self)
pub fn complete(&mut self, response: FunctionResponse)
pub fn fail(&mut self, error: impl Into<String>)
Sourcepub fn to_tuple(&self) -> (FunctionCall, Option<FunctionResponse>)
pub fn to_tuple(&self) -> (FunctionCall, Option<FunctionResponse>)
Project the Tool into the (call, optional response) pair that
providers put on the wire.
Completed→ real responseFailed→ synthesized error response carrying the error stringRejected→ synthesized error response noting the refusalPending/Approved/Running→(call, None)— not ready
This is the only place in the codebase where lossy ToolStatus → wire conversion happens. Providers must not re-implement it.
Sourcepub fn try_to_tuple(
&self,
) -> Result<(FunctionCall, FunctionResponse), NonResolvedToolError>
pub fn try_to_tuple( &self, ) -> Result<(FunctionCall, FunctionResponse), NonResolvedToolError>
Strict variant: errors if the Tool is not resolved. Use in provider request builders where sending a non-resolved Tool would be a bug.