pub struct ClosureTool { /* private fields */ }Expand description
A tool defined by a closure function.
Created via ClosureTool::new_sync or ClosureTool::new_async.
For ergonomic creation, use the macros or AgentBuilder’s custom_tool method.
Implementations§
Source§impl ClosureTool
impl ClosureTool
Sourcepub fn new_sync(
name: impl Into<String>,
description: impl Into<String>,
schema: Value,
handler: impl Fn(Value, &ToolContext) -> Result<AgentToolResult, ToolError> + Send + Sync + 'static,
) -> Self
pub fn new_sync( name: impl Into<String>, description: impl Into<String>, schema: Value, handler: impl Fn(Value, &ToolContext) -> Result<AgentToolResult, ToolError> + Send + Sync + 'static, ) -> Self
Create a new sync tool from a closure.
The closure receives (params: Value, ctx: &ToolContext).
Sourcepub fn new_async(
name: impl Into<String>,
description: impl Into<String>,
schema: Value,
handler: impl Fn(Value, &ToolContext) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, ToolError>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn new_async( name: impl Into<String>, description: impl Into<String>, schema: Value, handler: impl Fn(Value, &ToolContext) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, ToolError>> + Send>> + Send + Sync + 'static, ) -> Self
Create a new async tool from a closure.
The closure receives (params: Value, ctx: &ToolContext) and returns a Future.
Trait Implementations§
Source§impl AgentTool for ClosureTool
impl AgentTool for ClosureTool
Source§fn description(&self) -> &str
fn description(&self) -> &str
Description for the model
Source§fn parameters_schema(&self) -> Value
fn parameters_schema(&self) -> Value
JSON Schema for parameters
Source§fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_tool_call_id: &'life1 str,
params: Value,
_signal: Option<Receiver<()>>,
ctx: &'life2 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_tool_call_id: &'life1 str,
params: Value,
_signal: Option<Receiver<()>>,
ctx: &'life2 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<AgentToolResult, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Execute the tool with the given tool call ID and parameters. Read more
Source§fn essential(&self) -> bool
fn essential(&self) -> bool
Whether this tool is essential (cannot be disabled).
Essential tools: read, write, edit, bash, grep, find, ls
Optional tools: web_search, github, subagent, etc.
Source§fn on_progress(&self, _callback: Arc<dyn Fn(String) + Send + Sync>)
fn on_progress(&self, _callback: Arc<dyn Fn(String) + Send + Sync>)
Called with progress updates during execution.
Tools can override this to emit streaming updates.
Source§fn on_browse_progress(
&self,
_callback: Arc<dyn Fn(BrowseProgress) + Send + Sync>,
)
fn on_browse_progress( &self, _callback: Arc<dyn Fn(BrowseProgress) + Send + Sync>, )
Structured browse progress callback for browser tool context enrichment.
Default implementation is no-op. Only browse tools override this to
register a callback that enriches
ToolCallContext with structured
data from BrowseProgress events.Source§fn render_call(&self, _params: &Value) -> Option<RenderOutput>
fn render_call(&self, _params: &Value) -> Option<RenderOutput>
Custom rendering for tool call (TUI visualization).
Return None to use the default tool_renderer.rs formatter.
Source§fn render_result(&self, _result: &AgentToolResult) -> Option<RenderOutput>
fn render_result(&self, _result: &AgentToolResult) -> Option<RenderOutput>
Custom rendering for tool result (TUI visualization).
Return None to use the default tool_renderer.rs formatter.
Source§fn intent(&self) -> Option<&str>
fn intent(&self) -> Option<&str>
Intent trace — a concise description of what this tool does.
Returned value is included in
ToolExecutionStart / ToolExecutionEnd
events so the agent loop can surface intent to users or telemetry.
Default None (no intent tracing).Source§fn execution_mode(&self) -> ToolExecutionMode
fn execution_mode(&self) -> ToolExecutionMode
Execution mode for parallel safety.
Defaults to ParallelSafe. Override for file-mutating or sequential tools.
Source§fn current_tab_id(&self) -> Option<Uuid>
fn current_tab_id(&self) -> Option<Uuid>
Return the current active tab ID, if this tool manages browser tabs.
Defaults to
None. Browser tools override this to return the tab ID
of the currently-open tab during execution, so the agent loop can
populate ToolExecutionUpdate.tab_id.Source§fn set_tab_id_slot(&self, _slot: Arc<Mutex<RawMutex, Option<Uuid>>>)
fn set_tab_id_slot(&self, _slot: Arc<Mutex<RawMutex, Option<Uuid>>>)
Receive a shared slot where the tool can write the current tab ID.
The agent loop creates the slot and passes it before
on_progress;
the tool writes Some(tab_id) when it opens a tab and None when
it closes it. Defaults to a no-op — only tab-aware tools override.Source§fn to_definition(&self) -> ToolDefinition
fn to_definition(&self) -> ToolDefinition
Convert to ToolDefinition
Auto Trait Implementations§
impl !RefUnwindSafe for ClosureTool
impl !UnwindSafe for ClosureTool
impl Freeze for ClosureTool
impl Send for ClosureTool
impl Sync for ClosureTool
impl Unpin for ClosureTool
impl UnsafeUnpin for ClosureTool
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
Mutably borrows from an owned value. Read more