Skip to content

Implement OnAgentErrorCallback for error metrics#708

Open
jlapenna wants to merge 2 commits intogoogle:mainfrom
jlapenna:fix-agent-error-metrics
Open

Implement OnAgentErrorCallback for error metrics#708
jlapenna wants to merge 2 commits intogoogle:mainfrom
jlapenna:fix-agent-error-metrics

Conversation

@jlapenna
Copy link
Copy Markdown

@jlapenna jlapenna commented Apr 7, 2026

Summary

This PR introduces an OnAgentErrorCallback mechanism to the ADK framework. This allows agents and plugins to register callbacks that are executed when an agent encounters an error during its execution.

Fixes #709

Rationale

Currently, there is no standardized way for plugins to intercept and handle or record errors that occur during agent execution (e.g., in agent.Run). This makes it difficult to implement observability metrics for agent failures, such as counting invocation errors.

By adding OnAgentErrorCallback, we enable plugins to listen for these errors and perform actions like incrementing error counters, logging, or attempting recovery.

Changes

agent/agent.go

  • Added OnAgentErrorCallback type definition.
  • Added OnAgentErrorCallbacks to Config struct.
  • Updated Run method to trigger runOnAgentErrorCallbacks when a.run(ctx) yields an error.
  • Implemented runOnAgentErrorCallbacks helper to execute callbacks from both the agent and registered plugins.
  • Added RunOnAgentErrorCallback to the pluginManager interface.

plugin/plugin.go

  • Added OnAgentErrorCallback to Config and Plugin structs.
  • Added accessor method OnAgentErrorCallback().

internal/plugininternal/plugin_manager.go

  • Implemented RunOnAgentErrorCallback to iterate over registered plugins and execute their OnAgentErrorCallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add OnAgentErrorCallback for error observability

1 participant