Hooks System
The Radium hooks system provides a comprehensive framework for intercepting and customizing execution flow at various points in agent execution. This system enables advanced behavior customization, logging, error handling, and telemetry collection.
Quick Startβ
- Create a hook configuration in
.radium/hooks.toml:
[[hooks]]
name = "my-logging-hook"
type = "before_model"
priority = 100
enabled = true
- Register your hook programmatically:
use radium_core::hooks::registry::HookRegistry;
use std::sync::Arc;
let registry = Arc::new(HookRegistry::new());
// Register your hook implementation
- Use CLI commands to manage hooks:
rad hooks list
rad hooks info my-logging-hook
rad hooks enable my-logging-hook
Documentationβ
- Getting Started - Quick start guide and basic usage
- Architecture - System architecture and design patterns
- Configuration - Configuration file format and schema reference
- Creating Hooks - Guide for creating custom hooks
- Hook Types - Detailed reference for all 13 hook types
- Examples - Practical examples and patterns
- API Reference - Complete API documentation
- Development Guide - Advanced development topics
Featuresβ
- 13 Hook Types: Model, tool, error, and telemetry hooks
- Priority-Based Execution: Hooks execute in priority order
- Thread-Safe: Full async/await support with
Arc<RwLock> - Enable/Disable: Dynamic hook management
- Configuration-Based: TOML configuration for hook settings
- Extension Support: Distribute hooks via extensions
Hook Types Overviewβ
Model Hooksβ
before_model- Execute before model callsafter_model- Execute after model calls
Tool Hooksβ
before_tool- Execute before tool executionafter_tool- Execute after tool executiontool_selection- Execute during tool selection
Error Hooksβ
error_interception- Intercept errors before propagationerror_transformation- Transform error messageserror_recovery- Attempt error recoveryerror_logging- Log errors with custom formatting
Telemetry Hooksβ
telemetry_collection- Collect and aggregate telemetrycustom_logging- Custom logging hooksmetrics_aggregation- Aggregate metricsperformance_monitoring- Monitor performance
Example Implementationsβ
See example hooks in examples/hooks/:
logging-hook/- Logs model calls with timestampsmetrics-hook/- Aggregates telemetry data
Next Stepsβ
- Read the Getting Started Guide for basic usage
- Check out Creating Hooks to build your first hook
- Review Hook Types to understand all available hook types
- Explore Examples for practical patterns