Quick Start
1
Register Hooks
2
Create Agent
Alternative: HooksConfig
Hook Types
Available Hooks
Configuration
Common Patterns
Logging
Cost Tracking
Tool Validation
Multi-Agent Hooks
For multi-agent workflows, useMultiAgentHooksConfig:
Middleware
Middleware wraps the entire request/response cycle:Async vs Sync Hook Execution
Choose the right execution method based on your context:Migration Example
Best Practices
Keep hooks lightweight
Keep hooks lightweight
Hooks run synchronously. Heavy operations should be queued for async processing.
Handle errors gracefully
Handle errors gracefully
Wrap hook code in try/except to prevent hook failures from crashing the agent.
Use middleware for cross-cutting concerns
Use middleware for cross-cutting concerns
Logging, timing, and authentication are good middleware candidates.
Related
Callbacks
Event-driven notifications
Guardrails
Output validation

