Skip to content

Commit 65d9a72

Browse files
cchinchilla-devcopybara-github
authored andcommitted
chore: add @OverRide decorators to LoggingPlugin callback methods
Merge #4572 ### Link to Issue or Description of Change **1. Link to an existing issue (if applicable):** - Closes: #4496 **2. Or, if no issue exists, describe the change:** **Problem:** `LoggingPlugin` overrides 12 callback methods from `BasePlugin` but none use the `@override` decorator. Every other plugin in the package (`DebugLoggingPlugin`, `ReplayPlugin`, `RecordingsPlugin`, `EnsureRetryOptionsPlugin`, `_RequestIntercepterPlugin`) already follows this practice. With `mypy --strict` enabled in `pyproject.toml`, missing `@override` means renamed or removed base-class methods would be silently missed in `LoggingPlugin` while being caught everywhere else. **Solution:** Import `override` from `typing_extensions` and decorate all 12 overridden callbacks. Purely additive: one import line and 12 decorators. No behavioral, API, or runtime change. ### Testing Plan **Unit Tests:** - [ ] I have added or updated unit tests for my change. - [x] All unit tests pass locally. No new tests are required — `@override` is a static-analysis-only decorator with no runtime effect. Ran `mypy` on the file before and after the change: same preexisting warnings, no new errors introduced. CI will validate via the existing test suite and linting checks. **Manual End-to-End (E2E) Tests:** Not applicable. This change adds only decorators with no runtime behavior. Verified by comparing `mypy` output before and after — no new errors. ### Checklist - [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document. - [x] I have performed a self-review of my own code. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have added tests that prove my fix is effective or that my feature works. - [x] New and existing unit tests pass locally with my changes. - [ ] I have manually tested my changes end-to-end. - [ ] Any dependent changes have been merged and published in downstream modules. ### Additional context I am the author of the original issue (#4496). A previous PR (#4544) was opened but is pending clarification, so I'm submitting this complete PR as the original issue author. COPYBARA_INTEGRATE_REVIEW=#4572 from cchinchilla-dev:feat/add_override_decorators_to_loggingplugin_4496 142ed87 PiperOrigin-RevId: 875811966
1 parent 4dd4d5e commit 65d9a72

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/google/adk/plugins/logging_plugin.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import TYPE_CHECKING
2020

2121
from google.genai import types
22+
from typing_extensions import override
2223

2324
from ..agents.base_agent import BaseAgent
2425
from ..agents.callback_context import CallbackContext
@@ -66,6 +67,7 @@ def __init__(self, name: str = "logging_plugin"):
6667
"""
6768
super().__init__(name)
6869

70+
@override
6971
async def on_user_message_callback(
7072
self,
7173
*,
@@ -87,6 +89,7 @@ async def on_user_message_callback(
8789
self._log(f" Branch: {invocation_context.branch}")
8890
return None
8991

92+
@override
9093
async def before_run_callback(
9194
self, *, invocation_context: InvocationContext
9295
) -> Optional[types.Content]:
@@ -99,6 +102,7 @@ async def before_run_callback(
99102
)
100103
return None
101104

105+
@override
102106
async def on_event_callback(
103107
self, *, invocation_context: InvocationContext, event: Event
104108
) -> Optional[Event]:
@@ -122,6 +126,7 @@ async def on_event_callback(
122126

123127
return None
124128

129+
@override
125130
async def after_run_callback(
126131
self, *, invocation_context: InvocationContext
127132
) -> Optional[None]:
@@ -134,6 +139,7 @@ async def after_run_callback(
134139
)
135140
return None
136141

142+
@override
137143
async def before_agent_callback(
138144
self, *, agent: BaseAgent, callback_context: CallbackContext
139145
) -> Optional[types.Content]:
@@ -145,6 +151,7 @@ async def before_agent_callback(
145151
self._log(f" Branch: {callback_context._invocation_context.branch}")
146152
return None
147153

154+
@override
148155
async def after_agent_callback(
149156
self, *, agent: BaseAgent, callback_context: CallbackContext
150157
) -> Optional[types.Content]:
@@ -154,6 +161,7 @@ async def after_agent_callback(
154161
self._log(f" Invocation ID: {callback_context.invocation_id}")
155162
return None
156163

164+
@override
157165
async def before_model_callback(
158166
self, *, callback_context: CallbackContext, llm_request: LlmRequest
159167
) -> Optional[LlmResponse]:
@@ -179,6 +187,7 @@ async def before_model_callback(
179187

180188
return None
181189

190+
@override
182191
async def after_model_callback(
183192
self, *, callback_context: CallbackContext, llm_response: LlmResponse
184193
) -> Optional[LlmResponse]:
@@ -206,6 +215,7 @@ async def after_model_callback(
206215

207216
return None
208217

218+
@override
209219
async def before_tool_callback(
210220
self,
211221
*,
@@ -221,6 +231,7 @@ async def before_tool_callback(
221231
self._log(f" Arguments: {self._format_args(tool_args)}")
222232
return None
223233

234+
@override
224235
async def after_tool_callback(
225236
self,
226237
*,
@@ -237,6 +248,7 @@ async def after_tool_callback(
237248
self._log(f" Result: {self._format_args(result)}")
238249
return None
239250

251+
@override
240252
async def on_model_error_callback(
241253
self,
242254
*,
@@ -251,6 +263,7 @@ async def on_model_error_callback(
251263

252264
return None
253265

266+
@override
254267
async def on_tool_error_callback(
255268
self,
256269
*,

0 commit comments

Comments
 (0)