[bug]exit_loop with Escalate=true stops parent SequentialAgent pipeline
Describe the bug
When using exit_loop tool inside a loopagent that is nested within a sequentialagent, the Escalate=true flag propagates up and stops the entire sequential pipeline, not just the inner loop.
Pipeline structure:
Sequential(Loop(Researcher → Executor → Evaluator), Summary)
When the Evaluator agent calls exit_loop:
- Loop exits ✅
- Sequential also exits ❌ (should continue)
- Summary never executes ❌
- Pipeline hangs with no response
To Reproduce
Minimal code to reproduce:
package main
import (
"context"
"google.golang.org/adk/agent"
"google.golang.org/adk/agent/llmagent"
"google.golang.org/adk/agent/workflowagents/loopagent"
"google.golang.org/adk/agent/workflowagents/sequentialagent"
"google.golang.org/adk/genai/genaiagent"
"google.golang.org/adk/tool/exitlooptool"
)
func main() {
ctx := context.Background()
model := genaiagent.Model("gemini-2.0-flash-exp")
// Agent that calls exit_loop
evaluator, _ := llmagent.New(llmagent.Config{
Config: agent.Config{
Name: "evaluator",
Description: "Evaluates if loop should exit",
},
Model: model,
Toolsets: []agent.Toolset{exitlooptool.Toolset()},
})
// Other agents (simple for reproduction)
researcher, _ := llmagent.New(llmagent.Config{
Config: agent.Config{Name: "researcher"},
Model: model,
})
executor, _ := llmagent.New(llmagent.Config{
Config: agent.Config{Name: "executor"},
Model: model,
})
summary, _ := llmagent.New(llmagent.Config{
Config: agent.Config{Name: "summary"},
Model: model,
})
// Create loop with exit_loop tool
loop, _ := loopagent.New(loopagent.Config{
AgentConfig: agent.Config{
Name: "research-loop",
SubAgents: []agent.Agent{researcher, executor, evaluator},
},
MaxIterations: 2,
})
// Create sequential pipeline
pipeline, _ := sequentialagent.New(sequentialagent.Config{
AgentConfig: agent.Config{
Name: "reasoning-pipeline",
SubAgents: []agent.Agent{loop, summary},
},
})
// Run with prompt that triggers exit_loop
// Result: Summary never executes
pipeline.Run(ctx, "Analyze metrics and exit loop after first iteration")
}
Steps to reproduce:
- Install ADK v0.3.0:
go get google.golang.org/[email protected] - Run the code above
- Send a request that causes evaluator to call
exit_loop - Observe that Summary agent never starts (check logs)
Expected behavior
When exit_loop is called inside the nested loop:
- The loop should exit immediately
- The sequential agent should continue to the next sub-agent (Summary)
- Summary should execute and return a response
Desktop (please complete the following information):
- OS: Linux
- Go version: 1.24+
- ADK version: v0.3.0
Model Information:
- Which model is being used: claude-sonnet-4-20250514 / gemini-2.0-flash-exp (bug happens with both)
Additional context
Root Cause Analysis
The issue occurs because:
- exit_loop sets Escalate=true (
tool/exitlooptool/tool.go):
func exitLoop(ctx tool.Context, myArgs EmptyArgs) (map[string]string, error) {
ctx.Actions().Escalate = true // <-- Sets escalate
ctx.Actions().SkipSummarization = true
return map[string]string{}, nil
}
- loopagent propagates Escalate event before exiting (
agent/workflowagents/loopagent/agent.go):
for event, err := range subAgent.Run(ctx) {
if !yield(event, err) { // <-- Event with Escalate=true is yielded UP
return
}
if event.Actions.Escalate {
shouldExit = true // <-- Loop detects escalate
}
}
if shouldExit {
return // <-- Exits but event already propagated
}
- sequentialagent IS a loopagent (
agent/workflowagents/sequentialagent/agent.go):
func New(cfg Config) (agent.Agent, error) {
sequentialAgent, err := loopagent.New(loopagent.Config{
MaxIterations: 1, // <-- Sequential is just a loop with 1 iteration
})
Since sequentialagent is internally a loopagent, it also reacts to the propagated Escalate=true and exits immediately, skipping remaining sub-agents.
I hit the very same bug today. I had to wrap the inner loop agent using an inner function.
type escalateClearingAgent struct {
wrappedAgent agent.Agent
}
func (a *escalateClearingAgent) Run(ctx agent.InvocationContext) iter.Seq2[*session.Event, error] {
return func(
yield func(*session.Event, error) bool) {
if err != nil {
if !yield(nil, err) {
return
}
continue
}
for event, err := range a.wrappedAgent.Run(ctx) {
if event != nil && event.Actions.Escalate {
event.Actions.Escalate = false <--- prevent escalate to propagate
}
if !yield(event, nil) {
return
}
}
}
}
Now it would look like this: Sequential(Wrapper (Loop(Researcher → Executor → Evaluator)), Summary)
This is fixed on main, and your root-cause analysis was exactly right, so it's worth recording what happened.
When you filed this, sequentialagent was implemented by delegating to loopagent.New, which is why an inner loop's Escalate=true terminated the whole sequential pipeline. That dependency was removed in 57630642 ("feat: remove loopagent dependency from sequential agent").
sequentialagent.Run now iterates its sub-agents directly and inspects no Escalate flag at all, so Sequential(Loop(...), Summary) runs Summary after the loop exits.
Closing on that basis. Please reopen if you still see the pipeline stop on a current release.