Commit dfd2944
feat: Adding OnModelErrorCallback
This Changelist (CL) introduces new error handling mechanisms for LLM model calls and tool invocations within the Agent Development Kit.
Specifically, it adds:
* **`OnModelErrorCallback`**: An interface for handling errors that occur during an LLM model call.
* **`OnToolErrorCallback`**: An interface for handling errors during a tool invocation.
These callbacks allow for asynchronous or synchronous handling of errors, providing an opportunity to override the error with a custom response or result. The `LlmAgent` class is updated to support these new callbacks, and they are integrated into `BaseLlmFlow` and `Functions` to be triggered upon model or tool failures, respectively. Plugin-defined error callbacks are given precedence over agent-defined ones.
Additionally, the CL introduces `canonical` methods (`canonicalBeforeAgentCallbacks`, `canonicalAfterAgentCallbacks`, etc.) to `BaseAgent` and `LlmAgent` to simplify accessing callback lists, and updates Javadoc for existing callback interfaces. New tests are included to verify the functionality and precedence of the error callbacks.
Also, this CL renames many test variables with "unused" prefixes.
PiperOrigin-RevId: 8590561901 parent 6dd51cc commit dfd2944
File tree
9 files changed
+912
-164
lines changed- core/src
- main/java/com/google/adk
- agents
- flows/llmflows
- test/java/com/google/adk/agents
9 files changed
+912
-164
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
182 | 200 | | |
183 | 201 | | |
184 | 202 | | |
| |||
Lines changed: 6 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
| 57 | + | |
| 58 | + | |
60 | 59 | | |
61 | 60 | | |
62 | | - | |
| 61 | + | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
| |||
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 89 | + | |
| 90 | + | |
93 | 91 | | |
94 | 92 | | |
95 | | - | |
| 93 | + | |
96 | 94 | | |
97 | 95 | | |
98 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 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 | + | |
78 | 105 | | |
79 | 106 | | |
| 107 | + | |
80 | 108 | | |
81 | 109 | | |
82 | 110 | | |
| |||
99 | 127 | | |
100 | 128 | | |
101 | 129 | | |
| 130 | + | |
102 | 131 | | |
103 | 132 | | |
104 | 133 | | |
| |||
121 | 150 | | |
122 | 151 | | |
123 | 152 | | |
| 153 | + | |
124 | 154 | | |
125 | 155 | | |
126 | 156 | | |
| |||
154 | 184 | | |
155 | 185 | | |
156 | 186 | | |
| 187 | + | |
157 | 188 | | |
158 | 189 | | |
159 | 190 | | |
| |||
188 | 219 | | |
189 | 220 | | |
190 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
191 | 259 | | |
192 | 260 | | |
0 commit comments