pub struct DynamicToolset<Deps = ()>{ /* private fields */ }Expand description
Toolset that can have tools added/removed at runtime.
This is useful for scenarios where the available tools change during the agent’s lifetime.
§Thread Safety
All operations are thread-safe and can be called concurrently.
§Example
ⓘ
use serdes_ai_toolsets::DynamicToolset;
let toolset = DynamicToolset::new();
// Add tools at runtime
toolset.add_tool(my_tool);
// Remove tools
toolset.remove_tool("my_tool");Implementations§
Source§impl<Deps> DynamicToolset<Deps>
impl<Deps> DynamicToolset<Deps>
Sourcepub fn new() -> DynamicToolset<Deps>
pub fn new() -> DynamicToolset<Deps>
Create a new empty dynamic toolset.
Sourcepub fn with_id(id: impl Into<String>) -> DynamicToolset<Deps>
pub fn with_id(id: impl Into<String>) -> DynamicToolset<Deps>
Create with an ID.
Sourcepub fn with_max_retries(self, retries: u32) -> DynamicToolset<Deps>
pub fn with_max_retries(self, retries: u32) -> DynamicToolset<Deps>
Set max retries.
Sourcepub fn add_tool<T>(&self, tool: T)where
T: Tool<Deps> + 'static,
pub fn add_tool<T>(&self, tool: T)where
T: Tool<Deps> + 'static,
Add a tool.
If a tool with the same name exists, it will be replaced.
Sourcepub fn remove_tool(&self, name: &str) -> bool
pub fn remove_tool(&self, name: &str) -> bool
Remove a tool by name.
Returns true if the tool was removed, false if it didn’t exist.
Sourcepub fn tool_names(&self) -> Vec<String>
pub fn tool_names(&self) -> Vec<String>
Get tool names.
Trait Implementations§
Source§impl<Deps> AbstractToolset<Deps> for DynamicToolset<Deps>
impl<Deps> AbstractToolset<Deps> for DynamicToolset<Deps>
Source§fn get_tools<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 RunContext<Deps>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, ToolsetTool>, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DynamicToolset<Deps>: 'async_trait,
fn get_tools<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 RunContext<Deps>,
) -> Pin<Box<dyn Future<Output = Result<HashMap<String, ToolsetTool>, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DynamicToolset<Deps>: 'async_trait,
Get all available tools. Read more
Source§fn call_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
name: &'life1 str,
args: Value,
ctx: &'life2 RunContext<Deps>,
_tool: &'life3 ToolsetTool,
) -> Pin<Box<dyn Future<Output = Result<ToolReturn, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
DynamicToolset<Deps>: 'async_trait,
fn call_tool<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
name: &'life1 str,
args: Value,
ctx: &'life2 RunContext<Deps>,
_tool: &'life3 ToolsetTool,
) -> Pin<Box<dyn Future<Output = Result<ToolReturn, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
DynamicToolset<Deps>: 'async_trait,
Call a tool by name.
Source§fn tool_name_conflict_hint(&self) -> String
fn tool_name_conflict_hint(&self) -> String
Hint for resolving name conflicts.
Source§impl<Deps> Debug for DynamicToolset<Deps>
impl<Deps> Debug for DynamicToolset<Deps>
Auto Trait Implementations§
impl<Deps = ()> !Freeze for DynamicToolset<Deps>
impl<Deps = ()> !RefUnwindSafe for DynamicToolset<Deps>
impl<Deps> Send for DynamicToolset<Deps>
impl<Deps> Sync for DynamicToolset<Deps>
impl<Deps> Unpin for DynamicToolset<Deps>
impl<Deps = ()> !UnwindSafe for DynamicToolset<Deps>
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