Hooks Overview
Hooks are decorator-based lifecycle handlers that let you observe and modify agent behavior at key execution points.Hook Categories
Egregore provides 5 hook categories:| Category | Purpose | Example |
|---|---|---|
| Tool | Tool execution lifecycle | Log tool calls, modify results |
| Context | Context tree operations | Validate changes, audit operations |
| Streaming | Real-time response streaming | Process chunks, filter content |
| Message | Message handling | Modify user/provider messages |
| Scaffold | Scaffold state changes | Track scaffold updates |
Basic Usage
Hook Registration
Use decorators directly on agent instance:Hook Context Objects
Every hook receives a context object with relevant data:Common Use Cases
Logging and Monitoring
Error Handling
Content Filtering
Validation
Hook Execution Order
Multiple hooks execute in registration order:What’s Next?
Tool Hooks
Tool execution lifecycle
Context Hooks
Context tree operations
Streaming Hooks
Real-time content processing
Message Hooks
Message handling and modification

