pub struct ToolDispatcher { /* private fields */ }Expand description
Routes function calls to the right tool implementation.
Implementations§
Source§impl ToolDispatcher
impl ToolDispatcher
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty tool dispatcher with the default 30-second timeout.
§Examples
use gemini_adk_rs::tool::{ToolDispatcher, SimpleTool};
use serde_json::json;
let mut dispatcher = ToolDispatcher::new();
dispatcher.register(SimpleTool::new(
"echo", "Echo input", None,
|args| async move { Ok(args) },
));Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set the default timeout for tool calls.
Sourcepub fn default_timeout(&self) -> Duration
pub fn default_timeout(&self) -> Duration
Returns the configured default timeout.
Sourcepub fn register(&mut self, tool: impl ToolFunction)
pub fn register(&mut self, tool: impl ToolFunction)
Register a tool that implements ToolFunction.
Sourcepub fn register_function(&mut self, tool: Arc<dyn ToolFunction>)
pub fn register_function(&mut self, tool: Arc<dyn ToolFunction>)
Register a regular function tool (pre-wrapped in Arc).
Sourcepub fn register_streaming(&mut self, tool: Arc<dyn StreamingTool>)
pub fn register_streaming(&mut self, tool: Arc<dyn StreamingTool>)
Register a streaming tool.
Sourcepub fn register_input_streaming(&mut self, tool: Arc<dyn InputStreamingTool>)
pub fn register_input_streaming(&mut self, tool: Arc<dyn InputStreamingTool>)
Register an input-streaming tool.
Sourcepub fn get_tool(&self, name: &str) -> Option<&ToolKind>
pub fn get_tool(&self, name: &str) -> Option<&ToolKind>
Get a tool by name (for introspection/streaming tool spawning).
Sourcepub async fn call_function(
&self,
name: &str,
args: Value,
) -> Result<Value, ToolError>
pub async fn call_function( &self, name: &str, args: Value, ) -> Result<Value, ToolError>
Call a regular function tool by name, using the default timeout.
Sourcepub async fn call_function_with_timeout(
&self,
name: &str,
args: Value,
timeout: Duration,
) -> Result<Value, ToolError>
pub async fn call_function_with_timeout( &self, name: &str, args: Value, timeout: Duration, ) -> Result<Value, ToolError>
Call a regular function tool by name with an explicit timeout.
If the tool does not complete within the given duration, its future is
dropped (cancelling it) and ToolError::Timeout is returned.
Sourcepub async fn call_function_with_cancel(
&self,
name: &str,
args: Value,
cancel: CancellationToken,
) -> Result<Value, ToolError>
pub async fn call_function_with_cancel( &self, name: &str, args: Value, cancel: CancellationToken, ) -> Result<Value, ToolError>
Call a regular function tool by name, racing against a cancellation token.
If the token is cancelled before the tool completes, its future is
dropped and ToolError::Cancelled is returned.
Sourcepub fn build_response(
call: &FunctionCall,
result: Result<Value, ToolError>,
) -> FunctionResponse
pub fn build_response( call: &FunctionCall, result: Result<Value, ToolError>, ) -> FunctionResponse
Build a FunctionResponse from a FunctionCall result.
Sourcepub async fn cancel_streaming(&self, name: &str)
pub async fn cancel_streaming(&self, name: &str)
Cancel a streaming tool by name.
Sourcepub async fn cancel_by_ids(&self, ids: &[String])
pub async fn cancel_by_ids(&self, ids: &[String])
Cancel streaming tools by IDs.
Sourcepub fn to_tool_declarations(&self) -> Vec<Tool>
pub fn to_tool_declarations(&self) -> Vec<Tool>
Generate Tool declarations for the setup message.
Results are cached after first computation. The cache is invalidated
when tools are registered via register*() methods.