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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright 2026 Chris Olson
// Portions derived from ADK-Go (https://github.com/google/adk-go), Copyright 2026 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Callback types: the agent callbacks, the model and tool callbacks, and the plugin callbacks.
use Arc;
use BoxFuture;
use Content;
use ;
use Event;
use ;
use crateAgent;
use crate;
use crate;
use crateTool;
/// Runs before the agent. `Some` content with no error is yielded as an event and skips the
/// remaining before-agent callbacks, the agent run, and the after-agent callbacks.
///
/// An error takes precedence over content, skips the remaining before-agent callbacks, and is
/// yielded as an `Err` item. If the caller keeps polling, the agent and after-agent callbacks can
/// still run.
pub type BeforeAgentCallback =
;
/// Runs after the agent completes. It is skipped if the invocation has ended or the caller stops
/// polling before that point. `Some` content or an error skips the remaining after-agent callbacks.
/// Content is yielded as an event; an error takes precedence and is yielded as an `Err` item.
pub type AfterAgentCallback =
;
/// Called before sending a request to the model. If it returns `Some` response or an error, the
/// actual model call is skipped and the returned response/error is used. The request (possibly
/// edited) is always handed back.
pub type BeforeModelCallback = ;
/// Called after receiving a response from the model. If it returns `Some` response or an error, the
/// actual model response/error is replaced with the returned response/error.
///
/// The response (possibly edited) is always handed back, mirroring [`BeforeModelCallback`]: an
/// in-place edit made by a callback that returns `Ok(None)` reaches the later callbacks and the
/// rest of the flow. Return the received response unchanged when there is nothing to edit.
pub type AfterModelCallback = ;
/// Called when the model returns an error. If it returns `Some` response or an error, the actual
/// model response/error is replaced with the returned response/error.
pub type OnModelErrorCallback = ;
/// Called before a tool runs. If it returns `Some` result or an error, the remaining callbacks and
/// the tool call are skipped and the returned result is used as the tool result.
///
/// The arguments (possibly edited) are always handed back, mirroring [`BeforeModelCallback`]: the
/// callbacks and the tool get one copy of the call's arguments, so an edit made by a callback
/// that returns `Ok(None)` reaches the later callbacks, the tool, and the
/// on-tool-error and after-tool callbacks. The function call event keeps the model's arguments.
/// Return the received arguments unchanged when there is nothing to edit.
pub type BeforeToolCallback = ;
/// Called after a tool runs, whether it returned a result or an error. If it returns `Some` result
/// or an error, the remaining callbacks are skipped and the returned result/error is the final
/// tool output.
pub type AfterToolCallback = ;
/// Called when a tool returns an error. If it returns `Some` result or an error, the tool's
/// result/error is replaced with the returned one.
pub type OnToolErrorCallback = ;
/// Invoked when the user sends a message; may return a replacement message.
pub type OnUserMessageCallback = ;
/// Invoked for each event; may return a replacement event.
pub type OnEventCallback = ;
/// Invoked before a run starts; may return content that short-circuits the run.
pub type BeforeRunCallback = ;
/// Invoked after a run completes.
pub type AfterRunCallback = ;
/// Invoked when an error escapes an agent's run.
///
/// Notification only: the callbacks of every plugin run in registration order, synchronously,
/// before the error is yielded, and the error is yielded to the caller unchanged. The agent is the
/// one that failed (identify it by [`Agent::name`]). The context is a callback context for the
/// invocation whose actions are discarded: state changes made through it are not persisted, and
/// artifact saves through it are written but no artifact delta records them.
///
/// A panicking callback is caught, so the remaining callbacks still run and the original error is
/// still yielded; the panic is recorded on the agent's span. The error is compared against the
/// failing agent's own context: when that context is cancelled, an error that is (or wraps)
/// [`AgentError::Cancelled`], [`AgentError::DeadlineExceeded`] or the context's cancel cause is
/// not reported. Errors that escape while the context is live are reported. Parallel sub-agents may
/// invoke callbacks concurrently. An error from a sub-agent is reported once for each ancestor as
/// it propagates. A live run (`run_live`) does not invoke this callback.
pub type OnAgentErrorCallback = ;
/// A plugin's close function.
pub type CloseFn = ;