Skip to content

Commit e7cf300

Browse files
committed
refactor: optimize CallbackExecutor for better performance
- Execute plugin_callback directly instead of wrapping in CallbackPipeline - Makes plugin callback priority more explicit - Fixes incorrect lambda in docstring example - Reduces unnecessary overhead for single callback execution Addresses feedback from gemini-code-assist bot review (round 2)
1 parent 9b76072 commit e7cf300

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/google/adk/agents/callback_pipeline.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,20 @@ async def execute_with_plugins(
228228
First non-None result from plugin or agent callbacks, or None.
229229
230230
Example:
231+
>>> # Assuming `plugin_manager` is an instance available on the
232+
>>> # context `ctx`
231233
>>> result = await CallbackExecutor.execute_with_plugins(
232-
... plugin_callback=lambda: plugin_manager.run_before_model_callback(
233-
... callback_context=ctx,
234-
... llm_request=request,
235-
... ),
234+
... plugin_callback=ctx.plugin_manager.run_before_model_callback,
236235
... agent_callbacks=normalize_callbacks(agent.before_model_callback),
237236
... callback_context=ctx,
238237
... llm_request=request,
239238
... )
240239
"""
241240
# Step 1: Execute plugin callback (priority)
242-
result = await CallbackPipeline([plugin_callback]).execute(*args, **kwargs)
241+
result = plugin_callback(*args, **kwargs)
242+
if inspect.isawaitable(result):
243+
result = await result
244+
243245
if result is not None:
244246
return result
245247

0 commit comments

Comments
 (0)