Skip to content

Add SequentialAgent early exit mechanism #3000

@tommyhutcheson

Description

@tommyhutcheson

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Is your feature request related to a problem? Please describe.
Currently, SequentialAgent executes all sub-agents in sequence without the ability to terminate early when a certain condition is encountered. This can lead to unnecessary execution of subsequent agents when the first agent hits a blocking condition.
LoopAgent already has this capability using the escalate action and exit_loop tool, but SequentialAgent lacks this functionality.

Describe the solution you'd like
Implement an early exit mechanism for SequentialAgent that:

  1. Creates a new exit_sequence tool - similar to the existing exit_loop tool
  2. Updates SequentialAgent._run_async_impl - to check for event.actions.escalate and terminate the sequence early
  3. Provides consistent API - follows the same pattern as LoopAgent for developer familiarity

Describe alternatives you've considered
The alternative would be separating out any sub agents that could have a function leading to not requiring the rest of the sequence to run, but it would be much easier and cleaner to have the option to stop further executions and exit gracefully.

Additional context

  • Create exit_sequence_tool.py following same pattern as exit_loop_tool.py
  • Update SequentialAgent._run_async_impl with escalation detection
  • Export new tool in tools/init.py
  • Add comprehensive test coverage for async mode scenarios
  • Ensure backward compatibility with existing SequentialAgent usage
  • Update live mode (deferred due to complexity)

Scope Limitation

This initial implementation focuses on the async mode (_run_async_impl) only. The live mode (_run_live_impl) presents additional complexity due to:

  • Continuous streaming semantics
  • Function call detection in event streams
  • Interaction with existing task_completed() mechanism

Metadata

Metadata

Assignees

Labels

bot triaged[Bot] This issue is triaged by ADK botcore[Component] This issue is related to the core interface and implementation

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions