pub struct FunctionTool { /* private fields */ }Expand description
A custom agent tool backed by an async function or closure.
Construct one with FunctionTool::new and hand it to
AgentBuilder::tool. The handler is invoked
with the model’s call arguments deserialized into a serde_json::Value
and returns any IntoToolResult. A returned Err becomes a redacted
internal error — the turn is never panicked by a handler. Return
ToolResponse::error from the Ok path for errors that are safe to show
to the model.
The Err channel is redacted because a handler’s error text is written
against the host — a path, a query, a connection string — and the model is
an untrusted reader of anything it is shown. The full error is still logged
with the tool name and call id, so nothing is lost for the developer.
#[everruns::tool] is unaffected: it maps a function’s own Err to a
model-visible tool error before it reaches this channel, and reserves this
channel for failures the model did not cause.
A FunctionTool is cheap to clone (the handler is reference-counted) and is
Send + Sync, so the same tool can execute calls concurrently.
Implementations§
Source§impl FunctionTool
impl FunctionTool
Sourcepub fn new<F, Fut, T, E>(
name: impl Into<String>,
description: impl Into<String>,
json_schema: Value,
handler: F,
) -> Self
pub fn new<F, Fut, T, E>( name: impl Into<String>, description: impl Into<String>, json_schema: Value, handler: F, ) -> Self
Wrap an async handler as a callable tool.
nameis the identifier the model calls (validated atAgent::build).descriptiontells the model when to use the tool.json_schemais the JSON Schema for the tool’s arguments (validated at build time).handleris an asyncFn(serde_json::Value) -> Result<T, E>whereT: IntoToolResult(aValue, aString, or aToolResponse) andE: Display. OnErr, the error’sDisplaytext is retained for internal diagnostics but redacted from the model-facing tool result.
Trait Implementations§
Source§impl Clone for FunctionTool
impl Clone for FunctionTool
Source§fn clone(&self) -> FunctionTool
fn clone(&self) -> FunctionTool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FunctionTool
impl Debug for FunctionTool
Source§impl Tool for FunctionTool
impl Tool for FunctionTool
Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§fn parameters_schema(&self) -> Value
fn parameters_schema(&self) -> Value
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
arguments: Value,
) -> Pin<Box<dyn Future<Output = ToolExecutionResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
arguments: Value,
) -> Pin<Box<dyn Future<Output = ToolExecutionResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn display_name(&self) -> Option<&str>
fn display_name(&self) -> Option<&str>
Source§fn execute_with_context<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
_context: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolExecutionResult> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn execute_with_context<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
_context: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolExecutionResult> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Source§fn requires_context(&self) -> bool
fn requires_context(&self) -> bool
Source§fn required_context_services(&self) -> &'static [ToolContextService]
fn required_context_services(&self) -> &'static [ToolContextService]
Source§fn policy(&self) -> ToolPolicy
fn policy(&self) -> ToolPolicy
Source§fn hints(&self) -> ToolHints
fn hints(&self) -> ToolHints
Source§fn narrate(
&self,
_tool_call: &ToolCall,
_phase: ToolNarrationPhase,
_locale: Option<&str>,
_ctx: ToolNarrationContext<'_>,
) -> Option<String>
fn narrate( &self, _tool_call: &ToolCall, _phase: ToolNarrationPhase, _locale: Option<&str>, _ctx: ToolNarrationContext<'_>, ) -> Option<String>
Source§fn as_background_executable(&self) -> Option<&dyn BackgroundExecutableTool>
fn as_background_executable(&self) -> Option<&dyn BackgroundExecutableTool>
hints().supports_background.Source§fn deferrable_policy(&self) -> DeferrablePolicy
fn deferrable_policy(&self) -> DeferrablePolicy
DeferrablePolicy::Never
to always keep their full schema directly callable. Defaults to
DeferrablePolicy::Automatic.