pub struct ToolMiddleware { /* private fields */ }Expand description
Implementations§
Source§impl ToolMiddleware
impl ToolMiddleware
Sourcepub fn new<F>(inner: Arc<dyn AgentTool>, f: F) -> Selfwhere
F: Fn(Arc<dyn AgentTool>, String, Value, CancellationToken, Option<Box<dyn Fn(AgentToolResult) + Send + Sync>>, Arc<RwLock<SessionState>>, Option<ResolvedCredential>) -> ToolFuture<'static> + Send + Sync + 'static,
pub fn new<F>(inner: Arc<dyn AgentTool>, f: F) -> Selfwhere
F: Fn(Arc<dyn AgentTool>, String, Value, CancellationToken, Option<Box<dyn Fn(AgentToolResult) + Send + Sync>>, Arc<RwLock<SessionState>>, Option<ResolvedCredential>) -> ToolFuture<'static> + Send + Sync + 'static,
Create a new middleware wrapping inner.
The closure receives (inner_tool, tool_call_id, params, cancel, on_update, state, credential)
and can call through to the inner tool’s execute() at any point.
Sourcepub fn with_timeout(inner: Arc<dyn AgentTool>, timeout: Duration) -> Self
pub fn with_timeout(inner: Arc<dyn AgentTool>, timeout: Duration) -> Self
Create a middleware that enforces a timeout on tool execution.
If the inner tool does not complete within timeout, an error result
is returned.
Sourcepub fn with_logging<F>(inner: Arc<dyn AgentTool>, callback: F) -> Self
pub fn with_logging<F>(inner: Arc<dyn AgentTool>, callback: F) -> Self
Create a middleware that calls a logging callback before and after tool execution.
The callback receives (tool_name, tool_call_id, is_start) where
is_start is true before execution and false after.
Trait Implementations§
Source§impl AgentTool for ToolMiddleware
impl AgentTool for ToolMiddleware
Source§fn description(&self) -> &str
fn description(&self) -> &str
Natural-language description included in the LLM prompt.
Source§fn parameters_schema(&self) -> &Value
fn parameters_schema(&self) -> &Value
JSON Schema describing the tool’s input shape, used for validation.
Source§fn metadata(&self) -> Option<ToolMetadata>
fn metadata(&self) -> Option<ToolMetadata>
Optional organizational metadata (namespace, version). Read more
Source§fn requires_approval(&self) -> bool
fn requires_approval(&self) -> bool
Whether this tool requires user approval before execution.
Default is
false — tools execute immediately.Source§fn approval_context(&self, params: &Value) -> Option<Value>
fn approval_context(&self, params: &Value) -> Option<Value>
Optional rich context for the approval UI. Read more
Source§fn auth_config(&self) -> Option<AuthConfig>
fn auth_config(&self) -> Option<AuthConfig>
Optional authentication configuration for this tool. Read more
Source§fn execute(
&self,
tool_call_id: &str,
params: Value,
cancellation_token: CancellationToken,
on_update: Option<Box<dyn Fn(AgentToolResult) + Send + Sync>>,
state: Arc<RwLock<SessionState>>,
credential: Option<ResolvedCredential>,
) -> ToolFuture<'_>
fn execute( &self, tool_call_id: &str, params: Value, cancellation_token: CancellationToken, on_update: Option<Box<dyn Fn(AgentToolResult) + Send + Sync>>, state: Arc<RwLock<SessionState>>, credential: Option<ResolvedCredential>, ) -> ToolFuture<'_>
Execute the tool with validated parameters. Read more
Auto Trait Implementations§
impl Freeze for ToolMiddleware
impl !RefUnwindSafe for ToolMiddleware
impl Send for ToolMiddleware
impl Sync for ToolMiddleware
impl Unpin for ToolMiddleware
impl UnsafeUnpin for ToolMiddleware
impl !UnwindSafe for ToolMiddleware
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