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: ToolName,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> Selfwhere
F: Fn(Value) -> WasmBoxedFuture<'static, Result<ToolOutput, ToolExecutionError>> + WasmCompatSend + WasmCompatSync + 'static,
pub fn new<F>(
name: ToolName,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> Selfwhere
F: Fn(Value) -> WasmBoxedFuture<'static, Result<ToolOutput, ToolExecutionError>> + WasmCompatSend + WasmCompatSync + 'static,
Define a tool from a context-free callback over owned arguments.
Sourcepub fn new_with_context<F>(
name: ToolName,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> Selfwhere
F: ToolCallback + 'static,
pub fn new_with_context<F>(
name: ToolName,
description: impl Into<String>,
parameters: Value,
callback: F,
) -> Selfwhere
F: ToolCallback + 'static,
Define a tool from a callback over the dispatch-scoped context.
Sourcepub fn with_liveness<F>(self, is_live: F) -> Self
pub fn with_liveness<F>(self, is_live: F) -> Self
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<LivenessFn>)
pub fn into_parts(self) -> (ToolDefinition, ErasedHandler, Option<LivenessFn>)
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
Auto Trait Implementations§
impl !RefUnwindSafe for DynamicTool
impl !UnwindSafe for DynamicTool
impl Freeze for DynamicTool
impl Send for DynamicTool
impl Sync for DynamicTool
impl Unpin for DynamicTool
impl UnsafeUnpin for DynamicTool
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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