Skip to main content

ListenExecuteTool

Trait ListenExecuteTool 

Source
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:

  1. listen() - starts preparation and streams updates
  2. execute() - 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§

Source

type Name: ToolName

The type of name for this tool.

Required Methods§

Source

fn name(&self) -> Self::Name

Returns the tool’s strongly-typed name.

Source

fn display_name(&self) -> &'static str

Human-readable display name for UI.

Source

fn description(&self) -> &'static str

Human-readable description of what the tool does.

Source

fn input_schema(&self) -> Value

JSON schema for the tool’s input parameters.

Source

fn listen( &self, ctx: &ToolContext<Ctx>, input: Value, ) -> impl Stream<Item = ListenToolUpdate> + Send

Start and stream runtime preparation updates.

Source

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§

Source

fn tier(&self) -> ToolTier

Permission tier for this tool.

Source

fn cancel( &self, _ctx: &ToolContext<Ctx>, _operation_id: &str, _reason: ListenStopReason, ) -> impl Future<Output = Result<()>> + Send

Stop a listen operation (best effort).

§Errors

Returns an error if cancellation fails.

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.

Implementors§