pub struct ToolDispatcher { /* private fields */ }Expand description
Routes function calls to the right tool implementation.
Implementations§
Source§impl ToolDispatcher
impl ToolDispatcher
Sourcepub fn new() -> ToolDispatcher
pub fn new() -> ToolDispatcher
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) -> ToolDispatcher
pub fn with_timeout(self, timeout: Duration) -> ToolDispatcher
Set the default timeout for tool calls.
Sourcepub fn with_confirmation_provider(
self,
provider: Arc<dyn ConfirmationProvider>,
) -> ToolDispatcher
pub fn with_confirmation_provider( self, provider: Arc<dyn ConfirmationProvider>, ) -> ToolDispatcher
Attach a confirmation provider (builder form).
Once set, any tool reporting
requires_confirmation
— e.g. one built with T::confirm(..) — is checked against the provider
before it executes; a denied decision returns a ToolError instead of
running the tool. With no provider configured, confirmation-gated tools
run normally (enforcement is opt-in).
Sourcepub fn set_confirmation_provider(
&mut self,
provider: Arc<dyn ConfirmationProvider>,
)
pub fn set_confirmation_provider( &mut self, provider: Arc<dyn ConfirmationProvider>, )
Attach a confirmation provider in place. See
with_confirmation_provider.
Sourcepub fn has_confirmation_provider(&self) -> bool
pub fn has_confirmation_provider(&self) -> bool
Whether a confirmation provider is configured.
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.
Trait Implementations§
Source§impl Default for ToolDispatcher
impl Default for ToolDispatcher
Source§fn default() -> ToolDispatcher
fn default() -> ToolDispatcher
Source§impl ToolProvider for ToolDispatcher
impl ToolProvider for ToolDispatcher
Source§fn declarations(&self) -> Vec<Tool>
fn declarations(&self) -> Vec<Tool>
Auto Trait Implementations§
impl !Freeze for ToolDispatcher
impl !RefUnwindSafe for ToolDispatcher
impl Send for ToolDispatcher
impl Sync for ToolDispatcher
impl Unpin for ToolDispatcher
impl !UnwindSafe for ToolDispatcher
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
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].