pub struct DynamicTool { /* private fields */ }Expand description
A tool defined at runtime: a name, a schema and a callback. The callback
is the handler (ToolFn); this struct is its definition plus the
erased handler a registry stages until a bus takes it. The optional
liveness probe supports registry retirement; inline execution does not
consult it.
Implementations§
Source§impl DynamicTool
impl DynamicTool
Sourcepub fn new<F>(
name: impl Into<String>,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> DynamicToolwhere
F: Fn(Value) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolExecutionError>> + Send>> + WasmCompatSend + WasmCompatSync + 'static,
pub fn new<F>(
name: impl Into<String>,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> DynamicToolwhere
F: Fn(Value) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolExecutionError>> + Send>> + WasmCompatSend + WasmCompatSync + 'static,
Define a tool from a context-free callback over owned arguments.
Sourcepub fn new_with_context<F>(
name: impl Into<String>,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> DynamicToolwhere
F: ToolCallback + 'static,
pub fn new_with_context<F>(
name: impl Into<String>,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> DynamicToolwhere
F: ToolCallback + 'static,
Define a tool from a callback over the dispatch-scoped context.
Sourcepub fn with_liveness<F>(self, is_live: F) -> DynamicTool
pub fn with_liveness<F>(self, is_live: F) -> DynamicTool
Attach a liveness probe.
Sourcepub fn definition(&self) -> ToolDefinition
pub fn definition(&self) -> ToolDefinition
The tool’s definition.
Sourcepub fn handler(&self) -> &ErasedHandler
pub fn handler(&self) -> &ErasedHandler
The erased handler behind this definition.
Sourcepub fn into_parts(
self,
) -> (ToolDefinition, ErasedHandler, Option<Arc<dyn Fn() -> bool + Send + Sync>>)
pub fn into_parts( self, ) -> (ToolDefinition, ErasedHandler, Option<Arc<dyn Fn() -> bool + Send + Sync>>)
Consumes the tool into its definition, handler, and optional liveness probe.
Sourcepub async fn execute(
&self,
arguments: Value,
) -> Result<ToolOutput, ToolExecutionError>
pub async fn execute( &self, arguments: Value, ) -> Result<ToolOutput, ToolExecutionError>
Run the tool inline with an empty context.
Sourcepub async fn execute_with(
&self,
context: &mut ToolContext,
arguments: Value,
) -> Result<ToolOutput, ToolExecutionError>
pub async fn execute_with( &self, context: &mut ToolContext, arguments: Value, ) -> Result<ToolOutput, ToolExecutionError>
Run the tool inline with isolated inbound values. A completed call
replaces only context’s result metadata, including when the tool
returns an error. Dropping the execution future leaves the caller’s
context unchanged; it does not publish partial mutations.
Trait Implementations§
Source§impl Clone for DynamicTool
impl Clone for DynamicTool
Source§fn clone(&self) -> DynamicTool
fn clone(&self) -> DynamicTool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more