pub struct FunctionTool { /* private fields */ }Expand description
A tool wrapping a typed async Rust function.
The input (and output) JSON schemas are inferred from the handler’s argument and result types unless
FunctionToolConfig overrides them. Type-erased: the generic handler lives in run.
Implementations§
Source§impl FunctionTool
impl FunctionTool
Sourcepub fn new<Args, Out, F, Fut>(
cfg: FunctionToolConfig,
f: F,
) -> Result<Arc<dyn Tool>, ToolError>where
Args: DeserializeOwned + JsonSchema + Send + 'static,
Out: Serialize + JsonSchema + Send + 'static,
F: Fn(Context, Args) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Out, ToolError>> + Send + 'static,
pub fn new<Args, Out, F, Fut>(
cfg: FunctionToolConfig,
f: F,
) -> Result<Arc<dyn Tool>, ToolError>where
Args: DeserializeOwned + JsonSchema + Send + 'static,
Out: Serialize + JsonSchema + Send + 'static,
F: Fn(Context, Args) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Out, ToolError>> + Send + 'static,
A tool calling f with arguments decoded (and validated) as Args.
Fails with ToolError::InvalidArgument when Args is not an object type or a schema cannot be
compiled.
Sourcepub fn with_confirmation_provider<Args, Out, F, Fut, P>(
cfg: FunctionToolConfig,
f: F,
provider: P,
) -> Result<Arc<dyn Tool>, ToolError>
pub fn with_confirmation_provider<Args, Out, F, Fut, P>( cfg: FunctionToolConfig, f: F, provider: P, ) -> Result<Arc<dyn Tool>, ToolError>
Like FunctionTool::new, with a confirmation provider: when the call carries no
confirmation, provider(&args) decides whether one is required, overriding
cfg.require_confirmation.
Trait Implementations§
Source§impl RunnableTool for FunctionTool
impl RunnableTool for FunctionTool
Source§fn run<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Map<String, Value>, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Map<String, Value>, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Runs the handler. A panic becomes ToolError::Panic with the text
panic in tool "<name>": <message> (no stack: Rust cannot capture the panicking stack
after unwinding).
Source§impl Tool for FunctionTool
impl Tool for FunctionTool
Source§fn origin_kind(&self) -> ToolOriginKind
fn origin_kind(&self) -> ToolOriginKind
FunctionToolConfig::origin (default ToolOriginKind::Local).
Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§fn is_long_running(&self) -> bool
fn is_long_running(&self) -> bool
Source§fn declaration(&self) -> Option<FunctionDeclaration>
fn declaration(&self) -> Option<FunctionDeclaration>
Source§fn as_runnable(&self) -> Option<&dyn RunnableTool>
fn as_runnable(&self) -> Option<&dyn RunnableTool>
Source§fn process_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 Context,
_req: &'life2 mut LlmRequest,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn process_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 Context,
_req: &'life2 mut LlmRequest,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
declaration with pack_tool before this runs; a tool without one
is never packed. Async because implementations may do I/O (artifact listing, memory search).Source§fn as_streaming(&self) -> Option<&dyn StreamingTool>
fn as_streaming(&self) -> Option<&dyn StreamingTool>
Source§fn defers_response(&self) -> bool
fn defers_response(&self) -> bool
Source§fn display_result_on_skip_summarization(&self) -> bool
fn display_result_on_skip_summarization(&self) -> bool
skip_summarization.Source§fn wrapper_key(&self) -> Option<&str>
fn wrapper_key(&self) -> Option<&str>
finish_task wrapper key.Source§fn unwrap(&self) -> Option<Arc<dyn Tool>>
fn unwrap(&self) -> Option<Arc<dyn Tool>>
None for a tool that wraps nothing.Source§fn origin_agent(&self) -> Option<Arc<dyn Agent>>
fn origin_agent(&self) -> Option<Arc<dyn Agent>>
ToolOriginKind::SubAgent tool runs (this tells a sub-agent from a remote
A2A agent).Source§fn origin_agents(&self) -> Vec<Arc<dyn Agent>>
fn origin_agents(&self) -> Vec<Arc<dyn Agent>>
origin_agent as a list of at most one.