Skip to main content
Hooks intercept and modify agent behavior at various lifecycle points - before/after tools, agents, and LLM calls.

Quick Start

1

Create a Hook with HookRegistry

2

Block Tool Execution

3

Hook with Matcher


User Interaction Flow


HookEvent

Events that hooks can subscribe to.

HookInput

Data provided to hooks.

Builder Methods


HookResult

Result returned from hook execution.

Factory Methods

Instance Methods


HookDecision

Decision types for hook outputs.

HookDefinition

Define individual hooks with functions and metadata.

Methods


HookRegistry

Manages a collection of hooks.

Methods


Common Patterns

Rate Limiter Hook


Best Practices

Only subscribe to events you need - reduces overhead and improves performance.
Hooks with higher priority run first. Use for security checks before logging.
Hooks run in the hot path - avoid expensive operations.
When denying, provide actionable error messages.

Guardrails

Output validation

Callbacks

UI event handlers