1 unstable release
Uses new Rust 2024
| 0.4.0 | Mar 2, 2026 |
|---|
#1277 in Asynchronous
Used in 5 crates
14KB
155 lines
neuron-hooks
Hook registry and lifecycle middleware for neuron operators
Overview
neuron-hooks provides the Hook trait and HookRegistry for attaching pre- and post-execution
middleware to operators. Hooks receive lifecycle events (before a turn, after a turn, on error) and
can observe, mutate, or short-circuit execution.
Hooks compose cleanly: register multiple hooks in a registry and they execute in order.
Built into the neuron ecosystem: neuron-hook-security provides
ready-made security hooks for redaction and exfiltration detection.
Usage
[dependencies]
neuron-hooks = "0.4"
Implementing a custom hook
use neuron_hooks::{Hook, HookContext, HookError};
use async_trait::async_trait;
pub struct LoggingHook;
#[async_trait]
impl Hook for LoggingHook {
async fn before_turn(&self, ctx: &HookContext) -> Result<(), HookError> {
println!("Starting turn for operator: {}", ctx.operator_id());
Ok(())
}
async fn after_turn(&self, ctx: &HookContext) -> Result<(), HookError> {
println!("Turn completed");
Ok(())
}
}
Registering hooks
use neuron_hooks::HookRegistry;
let mut registry = HookRegistry::new();
registry.register(LoggingHook);
Part of the neuron workspace
neuron is a composable async agentic AI framework for Rust. See the book for architecture and guides.
Dependencies
~1.1–2.1MB
~43K SLoC