Loop Agent
Configure agents that execute sub-agents in iterative loops for continuous refinement and improvement
Overview
The Loop Agent is a type of workflow agent that executes sub-agents in an iterative cycle until a stop condition is met. This pattern is ideal for processes that need continuous refinement, iterative improvement, or multiple attempts until achieving a satisfactory result.
Unlike Sequential and Parallel agents, the Loop Agent repeats the execution of sub-agents multiple times, allowing each iteration to improve the result based on feedback from the previous iteration.
Based on Google ADK: Implementation following the patterns of the Google Agent Development Kit for iterative agents.
Key Features
Iterative Execution
Repeats sub-agent execution until stop condition is met
Continuous Improvement
Each iteration can improve the result based on the previous one
exit_loop Tool
Stop control via automatic tool in instructions
Full Flexibility
Customizable stop criteria via instructions
exit_loop Tool - Stop Control
Important: The Loop Agent allows you to select which sub-agents can use the exit_loop
tool. During sub-agent configuration, you define which ones have the power to stop the loop.
How it works:
- In each sub-agent configuration, you can enable the use of the
exit_loop
tool - Only selected sub-agents can decide to stop the loop
- The tool accepts parameters to document the reason for stopping
- Allows granular control over who can finalize the iterative process
Configuration in the interface:
- ✅ Sub-agents with exit_loop: Can use the tool to stop the loop
- ❌ Sub-agents without exit_loop: Execute normally without stopping power
How to use exit_loop:
The exit_loop
function accepts no arguments. It simply signals that the loop should stop.
Output Keys - State Sharing
Final Response: The sub-agent that has the Output Key defined as loop_output
will be used to generate the final response presented to the user at the end of the loop.
Agent types with Output Key:
- LLM Agent: Saves language model response
- Task Agent: Saves task execution result
- Workflow Agent: Saves executed workflow result
- A2A Agent: Saves Agent-to-Agent protocol response
Special Output Key - loop_output
:
- ⭐
loop_output
- Sub-agent that generates final response presented to user - This agent is executed after all iterations to consolidate result
- This agent’s response is presented to the user as the final result
- Only one sub-agent can have
loop_output
as output_key
How it works:
- Configure the Output Key of each sub-agent
- The result is automatically saved in the loop state
- Use placeholders
{{output_key_name}}
in instructions to access data - State persists across all loop iterations
- At the end, the agent with
loop_output
consolidates the final response
Example flow:
When to Use Loop Agent
Creating a Loop Agent
Step-by-Step on the Platform
Practical Examples
1. Marketing Content Refinement
2. Optimization with Different Agent Types
3. Development with Workflow Agents
Advanced Loop Configurations
Output Keys - Shared State
Stop Control with exit_loop
Optimization Strategies
Monitoring and Debugging
Tracking Iterations
Best Practices
Common Use Cases
Content Creation
Iterative Refinement:
- Text improvement until desired quality
- Copy optimization for conversion
- Commercial proposal refinement
Optimization
Optimal Parameter Search:
- Marketing campaign tuning
- Price optimization
- System configuration adjustment
Development
Generation and Correction:
- Code generation with iterative testing
- Algorithm refinement
- Automatic bug fixing
Negotiation
Iterative Processes:
- Automatic contract negotiation
- Proposal refinement
- Commercial terms optimization
Next Steps
Sequential Agent
Learn about ordered sequential execution
Parallel Agent
Explore parallel sub-agent execution
LLM Agent
Return to intelligent agent fundamentals
Configurations
Explore advanced agent configurations
The Loop Agent is perfect for processes that need continuous refinement and iterative improvement. Use it when you want to achieve high quality through multiple attempts and constant feedback.