Skip to content

Conversation

@copybara-service
Copy link

refactor: Fix CallbackPlugin to on add callbacks once

This CL refactors the CallbackPlugin to ensure that callbacks are only added once, making the add*Callback methods idempotent.

Key changes include:

  • Introduction of a new private method addCallbackImpl that checks for the existence of a callback before adding it and its corresponding plugin.
  • Modification of all add*Callback methods (e.g., addBeforeAgentCallback, addAfterAgentCallback) to utilize addCallbackImpl.
  • Removal of a temporary workaround method clearBeforeModelCallbacks from both CallbackPlugin and LlmAgent.
  • Addition of a new test case addBeforeModelCallback_isIdempotent in CallbackPluginTest to verify the new idempotent behavior.

This CL refactors the `CallbackPlugin` to ensure that callbacks are only added once, making the `add*Callback` methods idempotent.

Key changes include:
*   Introduction of a new private method `addCallbackImpl` that checks for the existence of a callback before adding it and its corresponding plugin.
*   Modification of all `add*Callback` methods (e.g., `addBeforeAgentCallback`, `addAfterAgentCallback`) to utilize `addCallbackImpl`.
*   Removal of a temporary workaround method `clearBeforeModelCallbacks` from both `CallbackPlugin` and `LlmAgent`.
*   Addition of a new test case `addBeforeModelCallback_isIdempotent` in `CallbackPluginTest` to verify the new idempotent behavior.

PiperOrigin-RevId: 858210973
@copybara-service copybara-service bot closed this Jan 20, 2026
@copybara-service copybara-service bot deleted the test_858210973 branch January 20, 2026 11:00
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.

1 participant