Skip to content
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
e65936d
feat: Add documentation for early exit mechanism to SequentialAgent u…
tommyhutcheson Sep 22, 2025
4001465
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Sep 27, 2025
db4f63c
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Sep 30, 2025
8a8ad36
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 1, 2025
26fdbb4
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 2, 2025
7e2b1a5
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 7, 2025
f0dcebb
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 10, 2025
6190b80
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 13, 2025
f4503f2
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 15, 2025
26f8dca
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 16, 2025
7bc31d0
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 19, 2025
f5b8da6
docs: Update early exit mechanism documentation for SequentialAgent t…
tommyhutcheson Oct 19, 2025
4b602f0
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 20, 2025
2845385
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 21, 2025
32c4f2f
Merge branch 'main' into early-exit-mechanism-to-SequentialAgent
tommyhutcheson Oct 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions docs/agents/workflow-agents/sequential-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,62 @@ When the `SequentialAgent`'s `Run Async` method is called, it performs the follo

![Sequential Agent](../../assets/sequential-agent.png){: width="600"}

### Early Exit with `exit_sequence`

The `SequentialAgent` supports early termination when a sub-agent encounters a terminal condition that makes continuing the sequence unnecessary or impossible.

#### When to use early exit:
- **Validation failures:** A validation agent detects critical errors
- **Empty results:** A search agent finds no data to process
- **Blocking conditions:** An agent hits an unrecoverable state
- **Conditional logic:** Based on input analysis, remaining steps aren't needed

#### Usage

Sub-agents can call the `exit_sequence` tool to terminate the sequence early:

```python
from google.adk.tools import exit_sequence

# In your agent's tool function
def validate_input(tool_context: ToolContext):
if critical_validation_fails:
exit_sequence(tool_context) # Stops the sequence here
return "Validation failed - terminating sequence"
```

#### Example: Search → Analysis → Report Pipeline

```python
from google.adk.agents import LlmAgent, SequentialAgent
from google.adk.tools import exit_sequence, google_search

search_agent = LlmAgent(
name="SearchAgent",
instruction="Search for results. If no useful results found, call exit_sequence.",
tools=[google_search, exit_sequence]
)

analysis_agent = LlmAgent(
name="AnalysisAgent",
instruction="Analyze the search results."
)

report_agent = LlmAgent(
name="ReportAgent",
instruction="Generate final report."
)

# If search finds no results, analysis and report agents won't execute
pipeline = SequentialAgent(sub_agents=[search_agent, analysis_agent, report_agent])
```

!!! note "Live Mode Support"
Early exit via `exit_sequence` is supported in both async and live streaming modes. In live mode, the escalate action provides immediate termination, whilst `task_completed()` remains available for natural completion signals.

!!! info "Similar to LoopAgent"
The `exit_sequence` tool works similarly to [`exit_loop`](loop-agents.md) in LoopAgent, providing a consistent early-exit pattern across workflow agents.

### Full Example: Code Development Pipeline

Consider a simplified code development pipeline:
Expand Down Expand Up @@ -51,5 +107,3 @@ This ensures the code is written, *then* reviewed, and *finally* refactored, in
```java
--8<-- "examples/java/snippets/src/main/java/agents/workflow/SequentialAgentExample.java:init"
```