pub trait ListenExecuteTool<Ctx>: Send + Sync {
type Name: ToolName;
// Required methods
fn name(&self) -> Self::Name;
fn display_name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn input_schema(&self) -> Value;
fn listen(
&self,
ctx: &ToolContext<Ctx>,
input: Value,
) -> impl Stream<Item = ListenToolUpdate> + Send;
fn execute(
&self,
ctx: &ToolContext<Ctx>,
operation_id: &str,
expected_revision: u64,
) -> impl Future<Output = Result<ToolResult>> + Send;
// Provided methods
fn tier(&self) -> ToolTier { ... }
fn cancel(
&self,
_ctx: &ToolContext<Ctx>,
_operation_id: &str,
_reason: ListenStopReason,
) -> impl Future<Output = Result<()>> + Send { ... }
}Expand description
A tool whose runtime has two phases:
listen()- starts preparation and streams updatesexecute()- performs final execution after confirmation
This abstraction is useful when runtime state can expire or evolve before execution (quotes, challenge windows, leases, approvals).
Ordering note: the agent loop consumes listen() updates before
AgentHooks::pre_tool_use() runs. Hooks can therefore block execute(), but
any side effects done during listen() have already happened.
Required Associated Types§
Required Methods§
Sourcefn display_name(&self) -> &'static str
fn display_name(&self) -> &'static str
Human-readable display name for UI.
Sourcefn description(&self) -> &'static str
fn description(&self) -> &'static str
Human-readable description of what the tool does.
Sourcefn input_schema(&self) -> Value
fn input_schema(&self) -> Value
JSON schema for the tool’s input parameters.
Sourcefn listen(
&self,
ctx: &ToolContext<Ctx>,
input: Value,
) -> impl Stream<Item = ListenToolUpdate> + Send
fn listen( &self, ctx: &ToolContext<Ctx>, input: Value, ) -> impl Stream<Item = ListenToolUpdate> + Send
Start and stream runtime preparation updates.
Sourcefn execute(
&self,
ctx: &ToolContext<Ctx>,
operation_id: &str,
expected_revision: u64,
) -> impl Future<Output = Result<ToolResult>> + Send
fn execute( &self, ctx: &ToolContext<Ctx>, operation_id: &str, expected_revision: u64, ) -> impl Future<Output = Result<ToolResult>> + Send
Execute using operation ID and optimistic concurrency revision.
§Errors
Returns an error if execution fails or revision is stale.
Provided Methods§
Sourcefn cancel(
&self,
_ctx: &ToolContext<Ctx>,
_operation_id: &str,
_reason: ListenStopReason,
) -> impl Future<Output = Result<()>> + Send
fn cancel( &self, _ctx: &ToolContext<Ctx>, _operation_id: &str, _reason: ListenStopReason, ) -> impl Future<Output = Result<()>> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.