before_model_callback and after_model_callback not invoked for live streaming sessions (run_live)
google-adk version 1.22.1 (Python)
Description
Plugin callbacks before_model_callback and after_model_callback defined in BasePlugin are correctly invoked during
regular async sessions (run_async), but are completely bypassed during live streaming sessions (run_live). This
causes plugins that depend on these callbacks for analytics, logging, request/response modification, or other
model-level interception to silently fail when used with live streaming.
Steps to Reproduce
- Create a plugin implementing before_model_callback and/or after_model_callback
- Register and run with run_async → callbacks fire ✅
- Run with run_live → callbacks never fire ❌
Code References
Path: run_async → _call_llm_async()
Behavior: ✅ Calls _handle_before_model_callback() and _handle_after_model_callback()
────────────────────────────────────────
Path: run_live → _receive_from_model() → _postprocess_live()
Behavior: ❌ Bypasses callback handlers entirely
Files:
- src/google/adk/flows/llm_flows/base_llm_flow.py (lines 86-186 for run_live, lines 733-822 for _call_llm_async)
- src/google/adk/agents/llm_agent.py
Callback Comparison
┌───────────────────────┬───────────┬───────────────┐
│ Callback │ run_async │ run_live │
├───────────────────────┼───────────┼───────────────┤
│ before_run_callback │ ✅ Works │ ✅ Works │
├───────────────────────┼───────────┼───────────────┤
│ after_run_callback │ ✅ Works │ ✅ Works │
├───────────────────────┼───────────┼───────────────┤
│ on_event_callback │ ✅ Works │ ✅ Works │
├───────────────────────┼───────────┼───────────────┤
│ before_model_callback │ ✅ Works │ ❌ Not called │
├───────────────────────┼───────────┼───────────────┤
│ after_model_callback │ ✅ Works │ ❌ Not called │
└───────────────────────┴───────────┴───────────────┘
Impact
- Analytics/telemetry plugins miss live session data
- Request/response modification plugins silently fail
- No warning or error - plugins just don't work
Suggested Fix
Add calls to _handle_before_model_callback() and _handle_after_model_callback() in the run_live() flow, similar to
_call_llm_async().
Hello @bashimr ,
Currently, [before_model_callback](https://google.github.io/adk-docs/callbacks/types-of-callbacks/#before-model-callback) is incompatible with run_live. The [adk-docs](https://google.github.io/adk-docs/callbacks/types-of-callbacks/#before-model-callback) also do not indicate support for this combination.
Hello @ankursharmas ,
Could you please take a look at this? We have successfully reproduced this issue on our end. While PR #1768 resolved the tool callback request, it appears that model callbacks are still pending. Additionally, This issue highlighted the need for agent callback support with BiDi-streaming, which was confirmed to be a work in progress.
Cross-linking #5282 — same structural pattern (a specific Runner dispatch path silently bypasses plugin lifecycle callbacks), different branch: #4181 covers the run_live path, #5282 covers _run_node_async (the BaseNode root path used by Workflow roots in 2.x). Both surface as silent no-ops with no warning. A fix for one doesn't automatically cover the other, so likely worth tracking together when post-run lifecycle dispatch gets revisited.
These are not supported yet. The concept of before/after model is incompatible with how bidi live stream works, i.e. constantly sending messages. Close this for now.
FYI. This is now supported https://github.com/google/adk-python/commit/ef2d68080a05f2fc3e00634c4f6c4d3d43c2a7f1