bamboo_agent_core/agent/hooks.rs
1//! Agent lifecycle hook trait.
2//!
3//! Hooks are invoked at well-defined points in the agent loop (see
4//! [`AgentHookPoint`](bamboo_domain::AgentHookPoint)).
5//! They can inspect state, mutate session, and control flow via
6//! [`HookResult`](bamboo_domain::HookResult).
7
8use async_trait::async_trait;
9use bamboo_domain::{AgentHookPoint, HookResult};
10
11use super::types::Session;
12
13/// Trait for agent lifecycle hooks.
14///
15/// Implementations must be `Send + Sync` because hooks may be invoked
16/// from multiple concurrent agent runs.
17#[async_trait]
18pub trait AgentHook: Send + Sync {
19 /// Which hook point this hook subscribes to.
20 fn point(&self) -> AgentHookPoint;
21
22 /// Execute the hook.
23 ///
24 /// Receives immutable access to the session and the current hook point.
25 /// Returns a [`HookResult`] to control flow.
26 async fn run(&self, point: AgentHookPoint, session: &Session) -> HookResult;
27
28 /// Optional priority (lower runs first). Default is 100.
29 fn priority(&self) -> u32 {
30 100
31 }
32
33 /// Optional name for logging and debugging.
34 fn name(&self) -> &str {
35 "unnamed_hook"
36 }
37}