Convergence
Convergence is the process by which AgentGate determines when an agent has successfully completed a task. Instead of simply running a fixed number of iterations, convergence strategies intelligently decide when to continue iterating, when to stop, and how to interpret progress.What Is Convergence
Traditional automation runs for a predetermined number of attempts. Convergence goes further by:- Detecting completion: Recognizing when the agent has achieved the desired state
- Measuring progress: Tracking improvements across iterations
- Preventing loops: Identifying when the agent is stuck in repetitive behavior
- Optimizing cost: Stopping when further iterations are unlikely to help
Convergence Strategies
AgentGate supports five convergence strategies:- Fixed
- Hybrid
- Ralph
- Adaptive
- Manual
Run exactly N iterationsThe simplest strategy. Runs a predetermined number of iterations regardless of outcome.Best for:
- Simple tasks with predictable completion
- Cost-controlled environments
- Testing and debugging
- May waste iterations on already-completed tasks
- May stop before completion on complex tasks
Configuration Options
Strategy-Specific Options
| Strategy | Option | Type | Default | Description |
|---|---|---|---|---|
| fixed | iterations | number | 3 | Exact iteration count |
| hybrid | baseIterations | number | 3 | Guaranteed iterations |
| hybrid | bonusIterations | number | 2 | Extra iterations if progressing |
| hybrid | progressThreshold | number | 0.7 | Progress score needed (0-1) |
| ralph | convergenceThreshold | number | 0.05 | Similarity threshold |
| ralph | windowSize | number | 3 | Outputs to compare |
| ralph | minIterations | number | 1 | Minimum before termination |
| ralph | promptHotReload | boolean | false | Allow prompt updates |
Resource Limits
Every convergence configuration should include limits:Convergence State
During execution, AgentGate tracks convergence state:Convergence Decisions
Each iteration ends with a convergence decision:| Field | Description |
|---|---|
continue | Whether to run another iteration |
reason | Human-readable explanation |
confidence | How confident the strategy is (0-1) |
metadata | Strategy-specific details |
Progress Metrics
AgentGate calculates progress metrics across iterations:Understanding Trends
| Trend | Meaning | Action |
|---|---|---|
improving | Gates passing at increasing rate | Continue iterations |
stagnant | No change in gate passage | Consider stopping |
regressing | Gates that passed are now failing | Investigate agent behavior |
Choosing a Strategy
When to use Fixed
When to use Fixed
Use fixed when:
- You have a well-understood task
- Cost predictability is important
- You’re testing or debugging
- Tasks typically complete in 1-3 iterations
When to use Hybrid
When to use Hybrid
Use hybrid when:
- Tasks have variable complexity
- You want to balance cost and completion
- Progress is measurable through gates
- Most common choice for production
When to use Ralph
When to use Ralph
Use ralph when:
- Tasks are complex or open-ended
- Agent needs flexibility to explore
- Loop detection is important
- You trust the agent’s judgment
When to use Manual
When to use Manual
Use manual when:
- Changes require human approval
- Learning how the agent behaves
- Compliance requires oversight
- High-risk or sensitive code
Convergence with Gates
Convergence strategies work with gates to determine completion:Gate Interaction
- All gates pass → Task complete, stop iterating
- Some gates fail with
iterate→ Generate feedback, continue - Any gate fails with
stop→ Task failed, stop immediately - Limits reached → Task failed, stop with partial results
Best Practices
1
Start with Hybrid
For most tasks,
hybrid provides the best balance. Start with conservative settings and adjust based on results.2
Set Reasonable Limits
Always set limits to control costs. Consider your task complexity:
| Task Type | Recommended Max |
|---|---|
| Simple fix | 5 iterations |
| Feature | 10-15 iterations |
| Complex feature | 20-30 iterations |
| Major refactor | 50+ iterations |
3
Monitor Progress
Use the strategy state API to monitor convergence:
4
Adjust Based on Results
After completing several tasks, review convergence patterns:
- Tasks completing too early? Lower
progressThreshold - Wasting iterations? Raise
progressThreshold - Loop detection triggering? Adjust
convergenceThreshold