pub struct StructuredTool { /* private fields */ }Expand description
A structured tool with a typed schema and a closure for execution.
Use StructuredToolBuilder to construct instances.
§Example
use synwire_core::tools::{StructuredTool, Tool, ToolOutput, ToolSchema};
use synwire_core::error::SynwireError;
let tool = StructuredTool::builder()
.name("echo")
.description("Echoes input")
.schema(ToolSchema {
name: "echo".into(),
description: "Echoes input".into(),
parameters: serde_json::json!({"type": "object"}),
})
.func(|input| Box::pin(async move {
Ok(ToolOutput {
content: input.to_string(),
..Default::default()
})
}))
.build()
.expect("valid tool");
assert_eq!(tool.name(), "echo");Implementations§
Source§impl StructuredTool
impl StructuredTool
Sourcepub fn builder() -> StructuredToolBuilder
pub fn builder() -> StructuredToolBuilder
Returns a new builder for constructing a StructuredTool.
Trait Implementations§
Source§impl Debug for StructuredTool
impl Debug for StructuredTool
Source§impl Tool for StructuredTool
impl Tool for StructuredTool
Source§fn description(&self) -> &str
fn description(&self) -> &str
The tool’s description.
Source§fn schema(&self) -> &ToolSchema
fn schema(&self) -> &ToolSchema
The tool’s schema for argument validation.
Source§fn invoke(
&self,
input: Value,
) -> BoxFuture<'_, Result<ToolOutput, SynwireError>>
fn invoke( &self, input: Value, ) -> BoxFuture<'_, Result<ToolOutput, SynwireError>>
Invoke the tool with JSON arguments.
Auto Trait Implementations§
impl Freeze for StructuredTool
impl !RefUnwindSafe for StructuredTool
impl Send for StructuredTool
impl Sync for StructuredTool
impl Unpin for StructuredTool
impl UnsafeUnpin for StructuredTool
impl !UnwindSafe for StructuredTool
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