@@ -111,81 +111,125 @@ def __init__(self, name: str):
111111 super ().__init__ ()
112112 self .name = name
113113
114+ if TYPE_CHECKING :
115+
116+ async def on_user_message_callback (
117+ self ,
118+ * ,
119+ callback_context : Optional [CallbackContext ] = None ,
120+ user_message : types .Content ,
121+ invocation_context : Optional [InvocationContext ] = None ,
122+ ) -> Optional [types .Content ]:
123+ """Callback executed when a user message is received before an invocation starts.
124+
125+ Plugins can implement this with either callback_context (new) or
126+ invocation_context (deprecated) or both.
127+ """
128+
129+ async def before_run_callback (
130+ self ,
131+ * ,
132+ callback_context : Optional [CallbackContext ] = None ,
133+ invocation_context : Optional [InvocationContext ] = None ,
134+ ) -> Optional [types .Content ]:
135+ """Callback executed before the ADK runner runs.
136+
137+ Plugins can implement this with either callback_context (new) or
138+ invocation_context (deprecated) or both.
139+ """
140+
141+ async def on_event_callback (
142+ self ,
143+ * ,
144+ callback_context : Optional [CallbackContext ] = None ,
145+ event : Event ,
146+ invocation_context : Optional [InvocationContext ] = None ,
147+ ) -> Optional [Event ]:
148+ """Callback executed after an event is yielded from runner.
149+
150+ Plugins can implement this with either callback_context (new) or
151+ invocation_context (deprecated) or both.
152+ """
153+
154+ async def after_run_callback (
155+ self ,
156+ * ,
157+ callback_context : Optional [CallbackContext ] = None ,
158+ invocation_context : Optional [InvocationContext ] = None ,
159+ ) -> None :
160+ """Callback executed after an ADK runner run has completed.
161+
162+ Plugins can implement this with either callback_context (new) or
163+ invocation_context (deprecated) or both.
164+ """
165+
166+ # Runtime implementation accepts both via **kwargs
114167 async def on_user_message_callback (
115- self ,
116- * ,
117- invocation_context : InvocationContext ,
118- user_message : types .Content ,
168+ self , ** kwargs : Any
119169 ) -> Optional [types .Content ]:
120170 """Callback executed when a user message is received before an invocation starts.
121171
122172 This callback helps logging and modifying the user message before the
123173 runner starts the invocation.
124174
125175 Args:
126- invocation_context : The context for the entire invocation .
176+ callback_context : The context for the callback execution .
127177 user_message: The message content input by user.
178+ invocation_context: DEPRECATED. Use callback_context instead. The context
179+ for the entire invocation. This parameter is maintained for backward
180+ compatibility and will be removed in a future version.
128181
129182 Returns:
130- An optional `types.Content` to be returned to the ADK. Returning a
131- value to replace the user message. Returning `None` to proceed
132- normally.
183+ The modified user message or None if no modification is needed.
133184 """
134- pass
185+ return None
135186
136- async def before_run_callback (
137- self , * , invocation_context : InvocationContext
138- ) -> Optional [types .Content ]:
187+ async def before_run_callback (self , ** kwargs : Any ) -> Optional [types .Content ]:
139188 """Callback executed before the ADK runner runs.
140189
141- This is the first callback to be called in the lifecycle, ideal for global
142- setup or initialization tasks .
190+ This is the first lifecycle hook and is ideal for global setup, logging,
191+ or checks that may stop the invocation from running .
143192
144193 Args:
145- invocation_context: The context for the entire invocation, containing
146- session information, the root agent, etc.
194+ callback_context: The context for the callback execution.
195+ invocation_context: DEPRECATED. Use callback_context instead. The context
196+ for the entire invocation. This parameter is maintained for backward
197+ compatibility and will be removed in a future version.
147198
148199 Returns:
149- An optional `Event` to be returned to the ADK. Returning a value to
150- halt execution of the runner and ends the runner with that event. Return
151- `None` to proceed normally.
200+ Optional `types.Content` to halt execution and return the value to the
201+ caller. Return `None` to proceed normally.
152202 """
153- pass
203+ return None
154204
155- async def on_event_callback (
156- self , * , invocation_context : InvocationContext , event : Event
157- ) -> Optional [Event ]:
205+ async def on_event_callback (self , ** kwargs : Any ) -> Optional [Event ]:
158206 """Callback executed after an event is yielded from runner.
159207
160- This is the ideal place to make modification to the event before the event
161- is handled by the underlying agent app.
162-
163208 Args:
164- invocation_context : The context for the entire invocation .
209+ callback_context : The context for the callback execution .
165210 event: The event raised by the runner.
211+ invocation_context: DEPRECATED. Use callback_context instead. The context
212+ for the entire invocation. This parameter is maintained for backward
213+ compatibility and will be removed in a future version.
166214
167215 Returns:
168- An optional value. A non-`None` return may be used by the framework to
169- modify or replace the response. Returning `None` allows the original
170- response to be used.
216+ The modified event or None if no modification is needed.
171217 """
172- pass
218+ return None
173219
174- async def after_run_callback (
175- self , * , invocation_context : InvocationContext
176- ) -> None :
220+ async def after_run_callback (self , ** kwargs : Any ) -> None :
177221 """Callback executed after an ADK runner run has completed.
178222
179- This is the final callback in the ADK lifecycle, suitable for cleanup, final
180- logging, or reporting tasks.
181-
182223 Args:
183- invocation_context: The context for the entire invocation.
224+ callback_context: The context for the callback execution.
225+ invocation_context: DEPRECATED. Use callback_context instead. The context
226+ for the entire invocation. This parameter is maintained for backward
227+ compatibility and will be removed in a future version.
184228
185229 Returns:
186230 None
187231 """
188- pass
232+ return None
189233
190234 async def before_agent_callback (
191235 self , * , agent : BaseAgent , callback_context : CallbackContext
0 commit comments