-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: Add early exit mechanism to SequentialAgent using escalate action #2999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @tommyhutcheson, I'm Gemini Code Assist1 ! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a critical early exit mechanism for the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Response from ADK Triaging Agent
Hello @tommyhutcheson, thank you for your contribution!
To help us track and review this new feature, could you please create and associate a GitHub issue with this PR?
Additionally, since this change introduces a new user-facing tool (exit_sequence), please consider if an update to the user documentation is needed. If so, please open a PR in the adk-docs repository.
This information will help reviewers to review your PR more efficiently. Thanks!
@gemini-code-assist
gemini-code-assist
bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces an early exit mechanism for SequentialAgent, which is a great feature for controlling agent flow. The implementation is clean and the new exit_sequence tool is well-defined. The tests are also comprehensive and cover the main scenarios.
I have a couple of suggestions for improvement:
- In
sequential_agent.py, the early exit logic can be simplified for better readability. - In
test_sequential_agent.py, one of the assertions is a bit confusing and could be removed to improve test clarity.
Additionally, I noticed that the early exit mechanism has been implemented for _run_async_impl, but it seems to be missing from _run_live_impl. For consistency and to fully implement the feature, you should consider adding similar logic to _run_live_impl to handle the escalate action and prevent subsequent agents from running in a live session as well.
Overall, this is a solid contribution. My comments are aimed at refining the implementation.
b7446cd to
bee8029
Compare
Hey @boyangsvl @hangfei @Jacksunwei I have updated the PR to include exit_sequence support to both the _run_async_impl and _run_live_impl by implementing the escalate check in async and live modes. docs updated here too google/adk-docs#707
When possible could I get a review on this chagne.
Thank you Tommy
7916dea to
2a420e9
Compare
2a420e9 to
7e061b2
Compare
Hi @tommyhutcheson , can we achieve the same goal with a LoopAgent that has max_iteration=1?
Hi @tommyhutcheson , can we achieve the same goal with a LoopAgent that has max_iteration=1?
Hey @DeanChensj I thought we might have had a workaround there! but unfortunately not - here's the issue:
Current Structure:
SequentialAgent (parent)
├── agent_1
├── LoopAgent (validation loop) ← calls exit_loop() when validation is successfull
├── agent_2
└── agent_3
The Problem:
When the nested LoopAgent calls exit_loop(), it sets escalate=True. If I change the parent to
LoopAgent(max_iterations=1), the escalate flag propagates upward and exits the parent immediately -
skipping agent_2 and agent_3.
Is this the expected behaviour for nested escalate flags, or is there a different pattern I should use?
Uh oh!
There was an error while loading. Please reload this page.
Summary
Implements early exit mechanism for SequentialAgent using escalate action to resolve #3000
Documentation PR: google/adk-docs#707
Implementation
New Tool:
exit_sequencetool that setsescalate=Trueandskip_summarization=Trueexit_loopfor consistencySequentialAgent Updates:
_run_async_implto enable early termination_run_live_implfor feature parity across modesTest Coverage:
test_run_async_with_escalate_action- Early exit when first agent escalatestest_run_async_escalate_action_in_middle- Escalation in middle of sequencetest_run_async_no_escalate_action- Normal operation without escalationtest_run_live_with_escalate_action- Live mode escalate supportBehaviour
When a sub-agent calls
exit_sequence(), the SequentialAgent terminates immediately, preventing both:This works consistently in both async and live streaming modes.
Key Features
exit_looppatternTesting
All 9 tests passing:
Fixes #3000