1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! The [`Observer`] trait — single extension point for lifecycle hooks.
//!
//! Observers see every step start/end and every tool start/end during an
//! agent's execution. They are the designated integration point for:
//!
//! - Audit logging (persist everything to an external system)
//! - Human-in-the-loop approval (block or deny tool calls)
//! - Event bus publishing (stream to NATS, Kafka, Redis)
//! - Metrics collection (latency histograms, error rates)
//! - OpenTelemetry spans (via a `tracing-opentelemetry` bridge)
//!
//! There is exactly ONE observer per [`Agent`](crate::Agent), not a Vec.
//! Users who want to fan out to multiple destinations can wrap their
//! concerns in a single composite `Observer` impl.
use crate;
/// Result of a tool execution, passed to observers after dispatch.
/// Context for a step lifecycle event.
///
/// Carries the session id and the user input that triggered this step.
/// Expands in v0.3 to include step number and deadline.
/// Disposition returned by [`Observer::should_dispatch`] — whether a tool
/// call should proceed, be refused, or be intercepted.
///
/// v0.3 C2. Added as the canonical extension point for trust tier enforcement,
/// human-in-the-loop approval, and policy gating. The agent treats
/// [`Disposition::Refused`] as a synthetic tool result (fed back to the model
/// as an error) so the loop continues instead of aborting.
/// Lifecycle observer. Every method has a default no-op implementation so
/// implementors override only the hooks they care about.
/// A no-op observer used as the default when the agent is constructed
/// without one.
;