pub trait Hooks: Send + Sync {
// Provided methods
fn transform_tool_input<'life0, 'life1, 'async_trait>(
&'life0 self,
_call: &'life1 mut ToolCall,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn before_tool_call<'life0, 'life1, 'async_trait>(
&'life0 self,
_call: &'life1 ToolCall,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn after_tool_call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_call: &'life1 ToolCall,
_out: &'life2 mut ToolOutput,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn before_inbound<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_from: Option<&'life1 SessionId>,
_request: &'life2 mut Request,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn transform_context<'life0, 'life1, 'async_trait>(
&'life0 self,
_msgs: &'life1 mut Vec<AgentMessage>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn should_stop_after_turn<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 [AgentMessage],
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn after_run<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 [AgentMessage],
_stop: StopReason,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Provided Methods§
Sourcefn transform_tool_input<'life0, 'life1, 'async_trait>(
&'life0 self,
_call: &'life1 mut ToolCall,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn transform_tool_input<'life0, 'life1, 'async_trait>(
&'life0 self,
_call: &'life1 mut ToolCall,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
May mutate the tool call’s arguments before it is executed (e.g. to
rewrite a bash command through rtk). Mutations are what actually
executes, so before_tool_call/after_tool_call observe the rewrite.
Sourcefn before_tool_call<'life0, 'life1, 'async_trait>(
&'life0 self,
_call: &'life1 ToolCall,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn before_tool_call<'life0, 'life1, 'async_trait>(
&'life0 self,
_call: &'life1 ToolCall,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Some(reason) = blocked: tool is not executed; the reason is fed back
to the LLM as an error ToolResult (blocked: {reason}).
Sourcefn after_tool_call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_call: &'life1 ToolCall,
_out: &'life2 mut ToolOutput,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn after_tool_call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_call: &'life1 ToolCall,
_out: &'life2 mut ToolOutput,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Runs after every tool execution; may mutate the output before it is recorded and sent to the LLM.
Sourcefn before_inbound<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_from: Option<&'life1 SessionId>,
_request: &'life2 mut Request,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn before_inbound<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_from: Option<&'life1 SessionId>,
_request: &'life2 mut Request,
) -> Pin<Box<dyn Future<Output = Option<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Policy for an inbound peer message (an A2A Notify/Interrupt/Wake):
the mirror of Hooks::before_tool_call. May rewrite the request in
place (the rewrite is what is delivered); Some(reason) drops it — the
reason is returned to the sender when it is an ask. A message dropped
here never reaches the context or starts a turn.
Sourcefn transform_context<'life0, 'life1, 'async_trait>(
&'life0 self,
_msgs: &'life1 mut Vec<AgentMessage>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn transform_context<'life0, 'life1, 'async_trait>(
&'life0 self,
_msgs: &'life1 mut Vec<AgentMessage>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Runs at every turn start, after steering is drained, before streaming.
Sourcefn should_stop_after_turn<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 [AgentMessage],
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn should_stop_after_turn<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 [AgentMessage],
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Checked after tool execution completes; true ends the run with StopReason::Stop.
Sourcefn after_run<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 [AgentMessage],
_stop: StopReason,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn after_run<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 [AgentMessage],
_stop: StopReason,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Runs once when a run finishes, with the final context and why it
stopped. The A2A auto-report rides this (a worker forwards its result to
its orchestrator); a no-op by default.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".