after_agent_callback is not called when stop processing events after is_final_response is True #1927
Replies: 3 comments
-
|
I also see this when using adk web as well, although not consistently. A change like in rcleveng@39d9e8e seems to fix the issue for me. |
Beta Was this translation helpful? Give feedback.
-
|
thank you for reporting the issue. The guide is wrong. is_final_response cannot be taken as a signal of agent run complete in a multi-agent system:
|
Beta Was this translation helpful? Give feedback.
-
|
sorry, I should have transfer this discussion to github.com/google/adk-docs. Would you mind open an issue there ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the Bug
Hi, I'm Boris, currently working on the Opik integration for Google ADK (documentation).
Google ADK is easily one of the best agent frameworks I’ve used, but I encountered a subtle issue while following the quickstart tutorial. The guide instructs users to stop processing events by breaking the loop after detecting
event.is_final_response():When following this approach in combination with Opik's integration and callback hooks, the
after_agent_callbackis never invoked. This callback is essential for finalizing the Opik trace, and its absence results in unexpected and inconsistent behavior. This has led to confusion among several Opik users, as reported in #2467, #2386, and internal tickets.Interestingly, this issue does not appear when running the agent via adk run or adk web, the callback is invoked as expected in those environments. The problem seems specific to direct usage of runner.run_async as shown in the quickstart loop.
To Reproduce
Use the script below, adapted from the ADK quickstart, to reproduce the issue:
Click to expand full script
When executed, the output is as follows:
Notably, the
After agent callbackis never printed, indicating that it was not executed.However, when the
breakstatement (line 128 in the script) is commented out, theafter_agent_callbackis correctly triggered.Expected Behavior
The presence of the
breakin the quickstart guide is misleading. Users following this example may unknowingly prevent critical callbacks from firing, leading to trace finalization issues and data loss in observability tools like Opik.It would be beneficial if:
after_agent_callbackwere guaranteed to run even before yielding afinal_response, orbreakaltogether.Environment
Model Information
gemini-2.0-flashBeta Was this translation helpful? Give feedback.
All reactions