pub struct ContentFilterHook { /* private fields */ }Expand description
A hook that filters sensitive words from streaming output.
When on_stream_chunk is invoked, it checks the token for any of the
configured sensitive words. If found, the token is either filtered (dropped)
or replaced with a placeholder.
§Example
ⓘ
use lc_agents::hooks::ContentFilterHook;
let hook = ContentFilterHook::new(vec!["secret".to_string(), "password".to_string()]);
let executor = AgentExecutor::new(agent, tools).hook(hook);Implementations§
Source§impl ContentFilterHook
impl ContentFilterHook
Sourcepub fn new(sensitive_words: Vec<String>) -> Self
pub fn new(sensitive_words: Vec<String>) -> Self
Creates a new ContentFilterHook with the given sensitive words.
Sourcepub fn with_placeholder(self, placeholder: impl Into<String>) -> Self
pub fn with_placeholder(self, placeholder: impl Into<String>) -> Self
Sets the placeholder for replaced words.
Sourcepub fn with_drop_token(self, drop: bool) -> Self
pub fn with_drop_token(self, drop: bool) -> Self
Sets whether to drop entire tokens containing sensitive words.
Trait Implementations§
Source§impl AgentHook for ContentFilterHook
impl AgentHook for ContentFilterHook
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_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_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_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_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 ContentFilterHook
impl RefUnwindSafe for ContentFilterHook
impl Send for ContentFilterHook
impl Sync for ContentFilterHook
impl Unpin for ContentFilterHook
impl UnsafeUnpin for ContentFilterHook
impl UnwindSafe for ContentFilterHook
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