Skip to main content

tau_agent_plugin/
executor.rs

1//! Tool execution abstraction.
2//!
3//! The `ToolExecutor` trait is the contract between "something that runs tools"
4//! and "something that consumes tool results". Plugin authors don't implement it
5//! directly (they speak the wire protocol), but consumers of plugin handles do
6//! (`PluginExecutor` in server, `InProcessWorker` in worker).
7
8use async_trait::async_trait;
9use tau_agent_base::types::{ToolCall, ToolResultMessage};
10
11/// Trait for tool execution (allows plugin-based or in-process).
12#[async_trait]
13pub trait ToolExecutor: Send {
14    /// Execute a tool call.
15    ///
16    /// `cancel` is a shared cancellation flag. Long-running tools (bash) poll
17    /// it and abort mid-execution when it becomes true; short tools (read,
18    /// write, edit) may ignore it or check it once at the top.
19    ///
20    /// Implementations that cannot poll the flag directly (e.g. a plugin
21    /// subprocess over an RPC channel) should spawn a background watcher
22    /// that translates the flag into a [`PluginRequest::CancelToolCall`]
23    /// sent to the plugin.
24    async fn execute(
25        &mut self,
26        tool_call: &ToolCall,
27        output_tx: &smol::channel::Sender<String>,
28        cancel: &tau_agent_base::types::CancelToken,
29    ) -> tau_agent_base::Result<ToolResultMessage>;
30}