Skip to main content

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:
  1. Configure the Output Key of each sub-agent
  2. The result is automatically saved in the loop state
  3. Use placeholders {{output_key_name}} in instructions to access data
  4. State persists across all loop iterations
  5. At the end, the agent with loop_output consolidates the final response
Example flow:

When to Use Loop Agent

✅ Use Loop Agent when:
  • Iterative refinement: Improve result with each attempt
  • Optimization: Seek best solution through iterations
  • Validation with retry: Try until achieving valid result
  • Incremental learning: Improve based on feedback
  • Convergence: Iterate until reaching quality criteria
Practical examples:
  • Content refinement until desired quality is achieved
  • Parameter optimization through trials
  • Code generation with iterative corrections
  • Multi-round negotiation
  • Analysis with feedback-based refinement
❌ Avoid Loop Agent when:
  • Single result: Process only needs to execute once
  • No possible improvement: Iterations don’t add value
  • Limited resources: Multiple executions are too costly
  • Time critical: No time for multiple attempts
  • Deterministic: Result will always be the same

Creating a Loop Agent

Step-by-Step on the Platform

  1. On the Evo AI main screen, click “New Agent”
  2. In the “Type” field, select “Loop Agent”
  3. You’ll see specific fields for loop configuration
Creating Loop Agent
Name: Descriptive name for the loop agent
Description: Summary of the iterative process
Goal: Objective of the iterative process
Sub-Agents: Add agents that will execute in each iteration💡 Important: Sub-agent order defines sequence within each iteration🛑 Stop Control: For each sub-agent, you can enable the use of exit_loop tool🎯 Final Response: One sub-agent must have output_key: "loop_output" to generate final responseContent refinement example:
  1. Content Generator - Creates or refines content
  2. Quality Analyzer - Evaluates content quality
  3. Feedback Collector - Identifies improvement points
  4. Criteria Checker - Decides whether to continue (🛑 can use exit_loop)
  5. Finalizer - Generates final response (🎯 output_key: “loop_output”)
Configuring Loop Sub-Agents
Instructions: How the agent should coordinate iterations
exit_loop()
Output Key: Field available for all agent typesAgent types that support output_key:
  • LLM Agent - Saves model response to state
  • Task Agent - Saves task result to state
  • Workflow Agent - Saves workflow result to state
  • A2A Agent - Saves A2A protocol response to state
Special Output Key:
  • loop_output - Sub-agent that generates final response presented to user
How to configure:
Usage in instructions:
Configuring Output Keys
Control via exit_loop Tool:During sub-agent configuration, you select which ones can use the exit_loop tool. Only enabled sub-agents have the power to stop the loop.Configuration in interface:
How it works:
Example stop instruction:
Loop Agent Settings

Practical Examples

1. Marketing Content Refinement

Objective: Refine content until achieving high quality and effectivenessSub-Agents in each iteration:1. Content Generator
  • Name: content_generator
  • Description: Generates or refines content based on feedback
  • Instructions:
  • Output Key: current_content
2. Quality Analyzer
  • Name: quality_analyzer
  • Description: Evaluates content quality across multiple dimensions
  • Instructions:
  • Output Key: quality_analysis
3. Feedback Collector
  • Name: feedback_collector
  • Description: Identifies specific improvements based on analysis
  • Instructions:
  • Output Key: improvement_feedback
4. Criteria Checker
  • Name: criteria_checker
  • Description: Decides whether to continue iterating or use exit_loop
  • ✅ Can use exit_loop: Enabled
  • Instructions:
  • Output Key: stop_decision
5. Finalizer
  • Name: final_consolidator
  • Description: Generates consolidated final response for user
  • ✅ Can use exit_loop: Disabled (executes after loop)
  • Instructions:
  • Output Key: loop_output

2. Optimization with Different Agent Types

Objective: Optimize parameters using different agent typesSub-Agents in each iteration:1. Parameter Adjuster (LLM Agent)
  • Type: LLM Agent
  • Description: Adjusts parameters based on previous performance
  • Instructions: Analyze request {{user_input}} and previous performance: {{previous_performance}}. Adjust parameters to improve results.
  • Output Key: current_parameters
2. Performance Simulator (Task Agent)
  • Type: Task Agent
  • Description: Executes simulation with new parameters
  • Task: Campaign simulation with parameters in {{current_parameters}}
  • Output Key: simulated_performance
3. Data Analyzer (A2A Agent)
  • Type: A2A Agent
  • Description: Analyzes data via external protocol
  • Endpoint: Analysis system that receives {{simulated_performance}}
  • Output Key: detailed_analysis
4. Convergence Decider (LLM Agent)
  • Type: LLM Agent
  • Description: Decides if satisfactory optimization achieved
  • ✅ Can use exit_loop: Enabled
  • Instructions: Based on analysis {{detailed_analysis}}, if improvement < 5% use exit_loop.
  • Output Key: optimization_decision
5. Final Consolidator (LLM Agent)
  • Type: LLM Agent
  • Description: Generates final response with optimized parameters
  • ✅ Can use exit_loop: Disabled
  • Instructions: Based on complete optimization {{current_parameters}} and {{detailed_analysis}}, present final result for {{user_input}}.
  • Output Key: loop_output

3. Development with Workflow Agents

Objective: Develop code using complex workflowsSub-Agents in each iteration:1. Code Generator (LLM Agent)
  • Type: LLM Agent
  • Description: Generates or fixes code based on requirements
  • Instructions: Based on request {{user_input}}, generate code for: {{requirements}}. If there are errors in {{test_results}}, fix them.
  • Output Key: current_code
2. Testing Pipeline (Workflow Agent)
  • Type: Workflow Agent (Sequential)
  • Description: Executes complete testing pipeline
  • Sub-agents: [syntax_validator, test_executor, coverage_analyzer]
  • Output Key: test_results
3. Quality Analyzer (A2A Agent)
  • Type: A2A Agent
  • Description: Analyzes quality via external system
  • Endpoint: Code analysis system that receives {{current_code}}
  • Output Key: quality_analysis
4. Final Checker (LLM Agent)
  • Type: LLM Agent
  • Description: Decides if code is ready
  • ✅ Can use exit_loop: Enabled
  • Instructions: Analyze results {{test_results}} and quality {{quality_analysis}}. If all tests passed and quality >= 8, use exit_loop.
  • Output Key: final_check
5. Final Deliverer (LLM Agent)
  • Type: LLM Agent
  • Description: Delivers final code to user
  • ✅ Can use exit_loop: Disabled
  • Instructions: Present final code {{current_code}} with documentation based on {{test_results}} and {{quality_analysis}} for {{user_input}}.
  • Output Key: loop_output

Advanced Loop Configurations

Output Keys - Shared State

Output Key is available for all agent types:LLM Agent:
Task Agent:
Workflow Agent:
A2A Agent:
How data flows in the loop:
Automatic placeholders:
  • Use {{code}} to access previous agent result
  • Use {{tests}} to access test results
  • Use {{requirements}} to access initial data
  • All data persists between iterations
Naming:
  • Use snake_case: analysis_result, processed_data
  • Be descriptive: quality_feedback instead of feedback
  • Avoid conflicts: don’t use names already existing in state
Data structure:
  • Keep data structured when possible
  • Use JSON for complex data
  • Document expected format in instructions
Performance:
  • Avoid saving unnecessarily large data
  • Clean temporary data when no longer needed
  • Use output_key only when data will be reused

Stop Control with exit_loop

The exit_loop tool is automatically made available to the agent and should be used in instructions to control when to stop the loop.1. Score-based Stop:
2. Improvement-based Stop:
3. Criteria-based Stop:
4. Custom Condition:
Timeouts by level:Iteration Timeout: Time limit per iteration
Total Loop Timeout: Total loop time limit
Sub-Agent Timeout: Time limit per sub-agent
Convergence metrics:Progress Tracking:
Trend Analysis:
  • Detects improvement trends
  • Identifies performance plateaus
  • Predicts required number of iterations
  • Suggests parameter adjustments

Optimization Strategies

Speed optimizations:Smart Cache:
Early Termination:
Adaptive Timeouts:
State control between iterations:State Management:
Memory Limits:
Data Persistence:

Monitoring and Debugging

Tracking Iterations

Real-time visualization:
Common problems:1. Infinite Loop
2. Slow Convergence
3. Quality Regression
4. Frequent Timeout

Best Practices

Fundamental principles:
  • Quality feedback: Each iteration should provide specific and actionable feedback
  • Clear criteria with exit_loop: Define in instructions when to use exit_loop
  • Multiple stop conditions: Implement various conditions with exit_loop
  • Progress monitoring: Track improvement metrics
  • Regression validation: Prevent iterations from worsening result
  • Stop documentation: Use reason parameter to explain why it stopped
Strategies for fast convergence:
  • Incremental feedback: Focus on one improvement at a time
  • Prioritization: Address most impactful problems first
  • Adaptive learning: Adjust strategy based on progress
  • Early stopping: Stop when marginal improvement is low
  • Quality gates: Validate minimum quality each iteration
Ensuring stable execution:
  • Error handling: Handle sub-agent failures gracefully
  • State persistence: Save state between iterations
  • Recovery mechanisms: Allow restart from failure points
  • Resource management: Monitor CPU, memory and time usage
  • Circuit breakers: Prevent failure cascades

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.