pub struct ApprovalHook { /* private fields */ }Expand description
A hook that requires user approval before each tool call.
When on_before_tool_call is invoked, it always returns ToolCallAction::Reject
with a message indicating approval is needed. In a real application, this
would block on user input (e.g., via a channel or callback).
§Example
ⓘ
use lc_agents::hooks::ApprovalHook;
let hook = ApprovalHook::new();
let executor = AgentExecutor::new(agent, tools).hook(hook);Implementations§
Source§impl ApprovalHook
impl ApprovalHook
Sourcepub fn auto_approve() -> Self
pub fn auto_approve() -> Self
Creates an ApprovalHook that automatically approves all tool calls.
Sourcepub fn with_auto_approve(self, auto_approve: bool) -> Self
pub fn with_auto_approve(self, auto_approve: bool) -> Self
Sets the auto-approve mode.
Trait Implementations§
Source§impl AgentHook for ApprovalHook
impl AgentHook for ApprovalHook
Source§fn on_before_tool_call(&self, ctx: &mut ToolCallContext) -> ToolCallAction
fn on_before_tool_call(&self, ctx: &mut ToolCallContext) -> ToolCallAction
Called before a tool call. Can approve, reject, modify, or skip.
Source§fn on_before_completion(&self, _ctx: &mut CompletionContext) -> CompletionAction
fn on_before_completion(&self, _ctx: &mut CompletionContext) -> CompletionAction
Called before an LLM completion. Can modify messages or reject the call.
Source§fn on_after_completion(
&self,
_ctx: &mut CompletionResult,
) -> Result<(), HookError>
fn on_after_completion( &self, _ctx: &mut CompletionResult, ) -> Result<(), HookError>
Called after an LLM completion. Can modify the response.
Source§fn on_after_tool_call(
&self,
_ctx: &mut ToolResultContext,
) -> Result<(), HookError>
fn on_after_tool_call( &self, _ctx: &mut ToolResultContext, ) -> Result<(), HookError>
Called after a tool call. Can modify the result.
Source§fn on_stream_chunk(&self, chunk: &str) -> StreamAction
fn on_stream_chunk(&self, chunk: &str) -> StreamAction
Called for each streaming token. Can filter, replace, or forward.
Source§fn on_agent_start(&self, _input: &str) -> Result<(), HookError>
fn on_agent_start(&self, _input: &str) -> Result<(), HookError>
Called when the agent starts execution.
Source§fn on_agent_end(&self, _output: &str) -> Result<(), HookError>
fn on_agent_end(&self, _output: &str) -> Result<(), HookError>
Called when the agent finishes execution.
Source§fn on_error(&self, _error: &HookError) -> ErrorAction
fn on_error(&self, _error: &HookError) -> ErrorAction
Called when an error occurs. Can retry, ignore, or propagate.
Auto Trait Implementations§
impl Freeze for ApprovalHook
impl RefUnwindSafe for ApprovalHook
impl Send for ApprovalHook
impl Sync for ApprovalHook
impl Unpin for ApprovalHook
impl UnsafeUnpin for ApprovalHook
impl UnwindSafe for ApprovalHook
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