pub struct PreparedToolset<T, F, Deps = ()> { /* private fields */ }Expand description
Prepares/modifies tool definitions at runtime.
This allows dynamically modifying tool definitions based on the current context, such as adding dynamic descriptions or hiding tools based on user permissions.
§Example
ⓘ
use serdes_ai_toolsets::{PreparedToolset, FunctionToolset};
let toolset = FunctionToolset::new().tool(admin_tool);
// Hide admin tools for non-admin users
let prepared = PreparedToolset::new(toolset, |ctx, defs| {
if ctx.deps.is_admin {
Some(defs)
} else {
Some(defs.into_iter().filter(|d| !d.name.starts_with("admin_")).collect())
}
});Implementations§
Source§impl<T, F, Deps> PreparedToolset<T, F, Deps>where
T: AbstractToolset<Deps>,
F: Fn(&RunContext<Deps>, Vec<ToolDefinition>) -> Option<Vec<ToolDefinition>> + Send + Sync,
impl<T, F, Deps> PreparedToolset<T, F, Deps>where
T: AbstractToolset<Deps>,
F: Fn(&RunContext<Deps>, Vec<ToolDefinition>) -> Option<Vec<ToolDefinition>> + Send + Sync,
Trait Implementations§
Source§impl<T, F, Deps> AbstractToolset<Deps> for PreparedToolset<T, F, Deps>where
T: AbstractToolset<Deps>,
F: Fn(&RunContext<Deps>, Vec<ToolDefinition>) -> Option<Vec<ToolDefinition>> + Send + Sync,
Deps: Send + Sync,
impl<T, F, Deps> AbstractToolset<Deps> for PreparedToolset<T, F, Deps>where
T: AbstractToolset<Deps>,
F: Fn(&RunContext<Deps>, Vec<ToolDefinition>) -> Option<Vec<ToolDefinition>> + Send + Sync,
Deps: Send + Sync,
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,
PreparedToolset<T, F, 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,
PreparedToolset<T, F, 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,
PreparedToolset<T, F, 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,
PreparedToolset<T, F, Deps>: 'async_trait,
Call a tool by name.
Source§fn enter<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
PreparedToolset<T, F, Deps>: 'async_trait,
fn enter<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
PreparedToolset<T, F, Deps>: 'async_trait,
Enter context (for resource setup). Read more
Source§fn exit<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
PreparedToolset<T, F, Deps>: 'async_trait,
fn exit<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
PreparedToolset<T, F, Deps>: 'async_trait,
Exit context (for cleanup). Read more
Source§fn tool_name_conflict_hint(&self) -> String
fn tool_name_conflict_hint(&self) -> String
Hint for resolving name conflicts.
Auto Trait Implementations§
impl<T, F, Deps> Freeze for PreparedToolset<T, F, Deps>
impl<T, F, Deps> RefUnwindSafe for PreparedToolset<T, F, Deps>where
T: RefUnwindSafe,
F: RefUnwindSafe,
impl<T, F, Deps> Send for PreparedToolset<T, F, Deps>
impl<T, F, Deps> Sync for PreparedToolset<T, F, Deps>
impl<T, F, Deps> Unpin for PreparedToolset<T, F, Deps>
impl<T, F, Deps> UnwindSafe for PreparedToolset<T, F, Deps>where
T: UnwindSafe,
F: UnwindSafe,
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