Hook Definition • Rust AI Agent SDK

HookDefinition: Hook definition

HookDefinition

Defined in the hooks module.

Rust AI Agent SDK

Hook definition

Diagram

Allow

Deny

Event Trigger

Hook: HookDefinition

Decision

Process

Block

Fields

NameTypeDescription
idStringUnique ID
eventHookEventEvent to hook
matcherOption<String>Optional matcher pattern (regex for tool names, etc.)
funcHookFnHook function
enabledboolWhether hook is enabled
nameOption<String>Hook name (for debugging)

Methods

new

rust
fn new(
        event: HookEvent,
        func: impl Fn(&HookInput) -> HookResult + Send + Sync + 'static,
    ) -> Self

Create a new hook definition

Parameters:

NameType
eventHookEvent
funcimpl Fn(&HookInput

with_matcher

rust
fn with_matcher(mut self, pattern: impl Into<String>) -> Self

Set matcher pattern

Parameters:

NameType
patternimpl Into&lt;String&gt;

with_name

rust
fn with_name(mut self, name: impl Into<String>) -> Self

Set name

Parameters:

NameType
nameimpl Into&lt;String&gt;

matches

rust
fn matches(&self, target: &str) -> bool

Check if this hook matches the target

Parameters:

NameType
target&str

execute

rust
fn execute(&self, input: &HookInput) -> HookResult

Execute the hook

Parameters:

NameType
input&HookInput

Source

View on GitHub

praisonai/src/hooks/mod.rs at line 285


Related Documentation