#[non_exhaustive]pub struct BeforeToolCallEvent { /* private fields */ }Expand description
A tool is about to run, after its lookup (BeforeToolCallEvent).
Hooks can cancel the call, run a different tool with
set_selected_tool, or rewrite the tool use; a changed name
re-resolves the tool unless one is selected. The tool use id stays the model’s.
Implementations§
Source§impl BeforeToolCallEvent
impl BeforeToolCallEvent
Sourcepub fn invocation_state(&self) -> &InvocationState
pub fn invocation_state(&self) -> &InvocationState
The caller’s per-invocation state.
Sourcepub fn invocation_context(&self) -> Option<&InvocationContext>
pub fn invocation_context(&self) -> Option<&InvocationContext>
The request this event belongs to.
Source§impl BeforeToolCallEvent
impl BeforeToolCallEvent
Sourcepub fn tool_use_mut(&mut self) -> &mut ToolUse
pub fn tool_use_mut(&mut self) -> &mut ToolUse
The tool use, to edit its name or input in place.
Sourcepub fn set_tool_use(&mut self, tool_use: ToolUse)
pub fn set_tool_use(&mut self, tool_use: ToolUse)
Replaces the tool use.
Sourcepub fn set_cancel(&mut self, cancel: impl Into<Cancel>)
pub fn set_cancel(&mut self, cancel: impl Into<Cancel>)
Cancels the tool call: true uses the default message, a string becomes the error text of
the tool result.
Sourcepub fn selected_tool(&self) -> Option<&Arc<dyn Tool>>
pub fn selected_tool(&self) -> Option<&Arc<dyn Tool>>
The replacement tool a hook selected.
Sourcepub fn set_selected_tool(&mut self, tool: Arc<dyn Tool>)
pub fn set_selected_tool(&mut self, tool: Arc<dyn Tool>)
Runs tool instead of the registry’s match. The last callback to set it wins.
Sourcepub fn interrupt(
&mut self,
params: impl Into<InterruptParams>,
) -> Result<JsonValue, InterruptError>
pub fn interrupt( &mut self, params: impl Into<InterruptParams>, ) -> Result<JsonValue, InterruptError>
Raises an interrupt for human input (interrupt), with the id
hook:beforeToolCall:<toolUseId>:<name>.
Returns the response when the agent resumed with one (or params carries a preemptive
response). Otherwise the interrupt is recorded on the event and the agent stops with it
once every callback has run; return the InterruptError with ? (it does not fail the
invocation) or simply return from the callback.
§Errors
The unanswered interrupt.
Trait Implementations§
Source§impl Debug for BeforeToolCallEvent
impl Debug for BeforeToolCallEvent
Source§impl From<&BeforeToolCallEvent> for BeforeToolCallEventData
impl From<&BeforeToolCallEvent> for BeforeToolCallEventData
Source§fn from(event: &BeforeToolCallEvent) -> Self
fn from(event: &BeforeToolCallEvent) -> Self
Source§impl From<&BeforeToolCallEvent> for AgentStreamEvent
impl From<&BeforeToolCallEvent> for AgentStreamEvent
Source§fn from(event: &BeforeToolCallEvent) -> Self
fn from(event: &BeforeToolCallEvent) -> Self
Source§impl HookEvent for BeforeToolCallEvent
impl HookEvent for BeforeToolCallEvent
Source§type Event<'a> = BeforeToolCallEvent
type Event<'a> = BeforeToolCallEvent
'a.impl<H> IntoHookImpl<BeforeToolCallEvent> for Hwhere
H: Hook<BeforeToolCallEvent>,
impl<F, R> IntoSyncHook<BeforeToolCallEvent> for F
Auto Trait Implementations§
impl !RefUnwindSafe for BeforeToolCallEvent
impl !UnwindSafe for BeforeToolCallEvent
impl Freeze for BeforeToolCallEvent
impl Send for BeforeToolCallEvent
impl Sync for BeforeToolCallEvent
impl Unpin for BeforeToolCallEvent
impl UnsafeUnpin for BeforeToolCallEvent
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
§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