Commit acfaa04
feat: Improving LoggingPlugin
This CL refactors and improves the `LoggingPlugin` in the ADK core.
Here's a summary of the changes:
1. **Consistent Agent Name Logging**: The plugin now consistently retrieves the agent name from `callbackContext.agentName()` in `beforeAgentCallback` and `afterAgentCallback`, instead of using `agent.name()`.
2. **Enhanced LLM Response Logging**: The `formatContent` method has been significantly updated to provide more detailed logging for different types of `Content.parts()` within an LLM response. It now explicitly logs:
* Trimmed and potentially truncated text.
* The name of `functionCall` and `functionResponse`.
* Indicators for `codeExecutionResult` and other part types.
The different parts are joined by " | ".
3. **Improved Optional Field Logging**: Optional fields like `llmResponse.errorMessage()` and `toolContext.functionCallId()` are now always logged, displaying "None" when the optional is empty, rather than only logging when the value is present.
4. **Simplified Argument Formatting**: The `formatArgs` method now uses `args.toString()` for formatting, simplifying the code while still handling truncation for long argument strings.
5. **Removed Redundant Error Logging**: Duplicate `logger.error` calls within `onLlmError` and `onToolError` have been removed, as the preceding `log` calls already capture the necessary error information.
6. **Test Updates**: `LoggingPluginTest.java` has been updated to mock `mockCallbackContext.invocationContext()` and remove an unnecessary mock for `mockCallbackContext.branch()`.
PiperOrigin-RevId: 8596112741 parent c11fe22 commit acfaa04
2 files changed
Lines changed: 31 additions & 26 deletions
File tree
- core/src
- main/java/com/google/adk/plugins
- test/java/com/google/adk/plugins
Lines changed: 30 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
| 262 | + | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | 265 | | |
267 | 266 | | |
268 | 267 | | |
| |||
274 | 273 | | |
275 | 274 | | |
276 | 275 | | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
288 | 296 | | |
289 | 297 | | |
290 | 298 | | |
291 | 299 | | |
292 | 300 | | |
293 | 301 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
300 | 305 | | |
301 | | - | |
| 306 | + | |
302 | 307 | | |
303 | 308 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
0 commit comments