feat(plugins): add on_agent_error_callback and on_run_error_callback#5483
Draft
caohy1988 wants to merge 3 commits intogoogle:mainfrom
Draft
feat(plugins): add on_agent_error_callback and on_run_error_callback#5483caohy1988 wants to merge 3 commits intogoogle:mainfrom
caohy1988 wants to merge 3 commits intogoogle:mainfrom
Conversation
Merges PRs google#5045 and google#5047 onto latest main, resolving conflicts. Implements RFC google#5044 to close the error callback coverage gap: - Add on_agent_error_callback and on_run_error_callback to BasePlugin - Wire try/except in BaseAgent.run_async(), run_live(), and Runner._exec_with_plugin() - Add _run_notification_callbacks to PluginManager (best-effort: logs and continues on plugin errors, never masks app exceptions) - Add AGENT_ERROR and INVOCATION_ERROR event types to BQAA plugin with traceback capture and TraceManager cleanup - Add v_agent_error and v_invocation_error views with error_traceback column - Keep after_agent_callback and after_run_callback as success-only - Catch Exception, not BaseException Fixes google#4863, implements google#5044 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Collaborator
|
Response from ADK Triaging Agent Hello @caohy1988, thank you for your contribution! It looks like the Contributor License Agreement (CLA) has not been signed yet. Before we can review this PR, please sign the CLA. You can find more information and sign it at https://cla.developers.google.com/. Thanks! |
- Move try/except in _exec_with_plugin to cover the full run lifecycle (before_run_callback, early-exit, execution loop). Previously only the execution loop was covered, so failures in before_run_callback escaped without run-error notification or BQAA cleanup. - Fix traceback truncation: use max_len > 0 instead of bare if max_len, so -1 (no truncation sentinel) is not misinterpreted as enabled. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Closes the coverage gap for the error callback BQAA integration: - test_on_agent_error_callback_logs_correctly: AGENT_ERROR event with error_message, status=ERROR, and traceback in content - test_on_run_error_callback_logs_correctly: INVOCATION_ERROR event with same fields - test_on_run_error_callback_cleanup_runs_on_log_failure: TraceManager cleanup and context var reset run even when _log_event raises - test_traceback_not_truncated_with_negative_max_len: max_content_length=-1 does not truncate (validates the max_len > 0 fix) - test_error_views_contain_traceback_column: view SQL includes error_traceback for both AGENT_ERROR and INVOCATION_ERROR views Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Merges #5045 and #5047 onto latest main with all conflicts resolved. Implements RFC #5044. Fixes #4863.
What this adds
Two new notification-only plugin callbacks that complete the error coverage gap:
Changes by file
base_plugin.pyon_agent_error_callbackandon_run_error_callbackabstract methodsplugin_manager.pyrun_on_agent_error_callback,run_on_run_error_callback, and_run_notification_callbacks(best-effort dispatch: logs and continues on plugin errors)base_agent.pytry/exceptaround_run_async_impland_run_live_impl; new_handle_agent_error_callbackmethodrunners.pytry/exceptaroundexecute_fn()in_exec_with_plugin;after_run_callbacknow success-onlybigquery_agent_analytics_plugin.pyon_agent_error_callback(AGENT_ERROR + span cleanup),on_run_error_callback(INVOCATION_ERROR + TraceManager cleanup + flush);AGENT_ERRORandINVOCATION_ERRORviews witherror_tracebackcolumntest_error_callbacks.pyDesign decisions
after_*callbacks remain success-only — no semantic change to existing callbacksExceptiononly, notBaseException—CancelledError,KeyboardInterrupt,SystemExitdo not trigger error callbacks_run_notification_callbacks) — if a plugin raises during error notification, it's logged and iteration continues. The original application exception is always re-raisedon_run_error_callbackhastry/finally— TraceManager cleanup, context var reset, and flush run even if_log_eventraisesTest plan
_run_async_implcrash_run_live_implcrashafter_agent_callback/after_run_callbackNOT called on crash🤖 Generated with Claude Code