pub struct ToolContext { /* private fields */ }Expand description
What a tool receives when it runs (ToolContext).
Cheap to clone and 'static, so tools can move it into spawned work.
Implementations§
Source§impl ToolContext
impl ToolContext
Sourcepub fn invocation_state(&self) -> &InvocationState
pub fn invocation_state(&self) -> &InvocationState
The caller’s per-invocation state, shared with hooks and other tools.
Sourcepub fn cancel_signal(&self) -> &CancelSignal
pub fn cancel_signal(&self) -> &CancelSignal
The cancellation signal for this tool call. Cancellation is cooperative: check it between
steps or await CancelSignal::cancelled.
Sourcepub fn invocation_context(&self) -> Option<&InvocationContext>
pub fn invocation_context(&self) -> Option<&InvocationContext>
The request this call belongs to; pass it to a nested agent call to share its limits and usage.
Sourcepub fn interrupt(
&self,
params: impl Into<InterruptParams>,
) -> Result<JsonValue, InterruptError>
pub fn interrupt( &self, params: impl Into<InterruptParams>, ) -> Result<JsonValue, InterruptError>
Raises an interrupt for human input (interrupt).
Returns the response when the agent resumed with one (or params carries a preemptive
response). Otherwise returns the InterruptError; propagate it with ? into a
ToolError or a BoxError, which ends the tool as
ToolOutcome::Interrupt. The tool runs again from the start on resume, and this call
then returns the response. The interrupt id is tool:<toolUseId>:<name>.
§Errors
The unanswered interrupt.
Trait Implementations§
Source§impl Clone for ToolContext
impl Clone for ToolContext
Auto Trait Implementations§
impl !RefUnwindSafe for ToolContext
impl !UnwindSafe for ToolContext
impl Freeze for ToolContext
impl Send for ToolContext
impl Sync for ToolContext
impl Unpin for ToolContext
impl UnsafeUnpin for ToolContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more