pub struct ApprovalRequiredToolset<T, Deps = ()> { /* private fields */ }Expand description
Requires approval for tool calls.
When a tool is called, if approval is required, the toolset returns
ToolError::ApprovalRequired instead of executing the tool.
§Example
ⓘ
use serdes_ai_toolsets::{ApprovalRequiredToolset, FunctionToolset};
let toolset = FunctionToolset::new().tool(dangerous_tool);
// Require approval for all tools
let approved = ApprovalRequiredToolset::new(toolset);
// Or with a custom checker
let approved = ApprovalRequiredToolset::with_checker(toolset, |ctx, def, args| {
def.name.contains("delete") || def.name.contains("modify")
});Implementations§
Source§impl<T, Deps> ApprovalRequiredToolset<T, Deps>where
T: AbstractToolset<Deps>,
impl<T, Deps> ApprovalRequiredToolset<T, Deps>where
T: AbstractToolset<Deps>,
Sourcepub fn new(inner: T) -> ApprovalRequiredToolset<T, Deps>
pub fn new(inner: T) -> ApprovalRequiredToolset<T, Deps>
Create a toolset that requires approval for ALL tool calls.
Sourcepub fn with_checker<F>(inner: T, checker: F) -> ApprovalRequiredToolset<T, Deps>
pub fn with_checker<F>(inner: T, checker: F) -> ApprovalRequiredToolset<T, Deps>
Create a toolset with a custom approval checker.
The checker returns true if approval is required for the given
tool call, false if the call can proceed without approval.
Trait Implementations§
Source§impl<T, Deps> AbstractToolset<Deps> for ApprovalRequiredToolset<T, Deps>
impl<T, Deps> AbstractToolset<Deps> for ApprovalRequiredToolset<T, 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,
ApprovalRequiredToolset<T, 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,
ApprovalRequiredToolset<T, 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,
ApprovalRequiredToolset<T, 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,
ApprovalRequiredToolset<T, 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,
ApprovalRequiredToolset<T, Deps>: 'async_trait,
fn enter<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
ApprovalRequiredToolset<T, 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,
ApprovalRequiredToolset<T, Deps>: 'async_trait,
fn exit<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
ApprovalRequiredToolset<T, 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, Deps> Freeze for ApprovalRequiredToolset<T, Deps>where
T: Freeze,
impl<T, Deps = ()> !RefUnwindSafe for ApprovalRequiredToolset<T, Deps>
impl<T, Deps> Send for ApprovalRequiredToolset<T, Deps>where
T: Send,
impl<T, Deps> Sync for ApprovalRequiredToolset<T, Deps>where
T: Sync,
impl<T, Deps> Unpin for ApprovalRequiredToolset<T, Deps>where
T: Unpin,
impl<T, Deps = ()> !UnwindSafe for ApprovalRequiredToolset<T, 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