fix(agent): increase tool iteration limit from 10 to 25 and add budget awareness#27
Conversation
…t awareness Increases the default maximum tool iterations from 10 to 25 to accommodate complex multi-step tasks while maintaining safety bounds. Changes: - Update DEFAULT_MAX_TOOL_ITERATIONS from 10 to 25 in loop_.rs - Update default_agent_max_tool_iterations() from 10 to 25 in schema.rs - Add iteration budget awareness section to system prompt - Agent now knows its tool-use budget and can plan efficiently Fixes #26
PR Intake Checks - Warnings (non-blocking)The following are recommendations:
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
Note
|
| Cohort / File(s) | Summary |
|---|---|
Tool Iteration Limit & Budget Guidance src/agent/loop_.rs, src/config/schema.rs |
Increased max_tool_iterations default from 10 to 25. Added a new "Tool Use Budget" section injected into the system prompt that communicates the iteration budget and provides tiered guidance for task planning (Complex/Medium/Simple tasks). Updated configuration documentation to reflect the new default and rationale. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. | |
| Linked Issues check | ❓ Inconclusive | The PR addresses issue #26 by increasing iteration limit (10→25) and adding budget awareness. However, several objectives remain unimplemented: graceful degradation, resume capability, state persistence, and optimized batching strategies. |
Clarify whether partial objectives are intentional (addressed in this PR vs. future work) or if resume/graceful-degradation mechanisms should be included. Consider tracking unaddressed objectives in follow-up issues. |
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly and accurately summarizes the main changes: increasing the tool iteration limit and adding budget awareness to prevent task failures. |
| Description check | ✅ Passed | The description covers problem statement, solution, changes, acceptance criteria, testing, and rollback plan. Some template sections are missing (labels, security impact, i18n), but core content is well-documented. |
| Out of Scope Changes check | ✅ Passed | All changes are directly related to the stated objectives: two files modified (loop_.rs and schema.rs) with focused updates to the iteration limit constant and default configuration function. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
- Commit unit tests in branch
fix/agent-iteration-limit
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/config/schema.rs (1)
545-547: Add explicit compatibility/rollback note in the field docs.This documents the new default well, but it should also state compatibility and rollback explicitly (e.g., explicit user configs are unchanged; set
max_tool_iterations = 10to revert behavior).
As per coding guidelines, forsrc/config/*.rschanges, treat keys as public contract and document defaults, compatibility impact, and migration/rollback path.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/config/schema.rs` around lines 545 - 547, Update the field doc comment for max_tool_iterations to explicitly state compatibility and rollback guidance: note that this change only alters the default (public contract key "max_tool_iterations") and does not change explicit user configurations, describe the compatibility impact for existing setups, and provide a clear rollback/migration instruction such as "to restore previous behavior set max_tool_iterations = 10" so users know how to revert; ensure this text appears alongside the existing default/behavior note in src/config/schema.rs near the max_tool_iterations field.src/agent/loop_.rs (1)
3024-3033: Static tier ranges can contradict configured low limits.When configured max is small (e.g., 5–10), the fixed “Complex: ~15–20” guidance conflicts with the actual cap and can push poor planning. Consider deriving these ranges from
max_iterations.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/agent/loop_.rs` around lines 3024 - 3033, The hardcoded tier ranges in the system prompt can contradict a low configured cap; compute dynamic ranges from the existing max_iterations variable (derived from config.agent.max_tool_iterations) and replace the fixed "15–20 / 8–12 / 3–5" text in the system_prompt.push_str call with derived values (e.g., set simple ≈ max*0.25 rounded, medium ≈ max*0.5, complex ≈ max*0.8, and clamp minimums to sensible floors like 1–2) so the guidance reflects the actual limit; update the system_prompt formatting logic where system_prompt.push_str(...) is called to inject these computed ranges instead of the static strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/agent/loop_.rs`:
- Around line 3024-3033: The budget-awareness text block is only appended to
system_prompt inside the run path, so the process_message flow never receives
the tool-use guidance; extract the logic that computes max_iterations (using
config.agent.max_tool_iterations and DEFAULT_MAX_TOOL_ITERATIONS) and the
formatted budget string into a reusable helper (e.g., build_tool_budget_prompt
or add_tool_budget_to_prompt) and call it from both run and process_message
where system_prompt is constructed; ensure the helper accepts/configures the
same symbols (max_iterations, config.agent.max_tool_iterations) and
appends/returns the exact formatted string so both prompt-construction paths
include the same budget guidance.
In `@src/config/schema.rs`:
- Around line 561-563: The default in fn default_agent_max_tool_iterations() was
changed to 25 but tests still expect 10; update any tests that assert the
previous default (e.g., the agent_config_defaults test) to assert 25 instead of
10 so the test suite passes, and run cargo fmt, cargo clippy, and cargo test to
verify no other defaults mismatch.
---
Nitpick comments:
In `@src/agent/loop_.rs`:
- Around line 3024-3033: The hardcoded tier ranges in the system prompt can
contradict a low configured cap; compute dynamic ranges from the existing
max_iterations variable (derived from config.agent.max_tool_iterations) and
replace the fixed "15–20 / 8–12 / 3–5" text in the system_prompt.push_str call
with derived values (e.g., set simple ≈ max*0.25 rounded, medium ≈ max*0.5,
complex ≈ max*0.8, and clamp minimums to sensible floors like 1–2) so the
guidance reflects the actual limit; update the system_prompt formatting logic
where system_prompt.push_str(...) is called to inject these computed ranges
instead of the static strings.
In `@src/config/schema.rs`:
- Around line 545-547: Update the field doc comment for max_tool_iterations to
explicitly state compatibility and rollback guidance: note that this change only
alters the default (public contract key "max_tool_iterations") and does not
change explicit user configurations, describe the compatibility impact for
existing setups, and provide a clear rollback/migration instruction such as "to
restore previous behavior set max_tool_iterations = 10" so users know how to
revert; ensure this text appears alongside the existing default/behavior note in
src/config/schema.rs near the max_tool_iterations field.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 097e9c72-1caf-4ae1-820c-aaa8a80f0ebd
📒 Files selected for processing (2)
src/agent/loop_.rssrc/config/schema.rs
…agent-iteration-limit
Changes: - Extract tool budget prompt into reusable helper function build_tool_budget_prompt() - Use dynamic tier ranges based on max_iterations (12%/20%/32%/48%/60%/80%) - Apply budget awareness to both run() and process_message() code paths - Update all test assertions from 10 to 25 - Add comprehensive doc comment with rollback guidance in schema.rs Fixes review comments on PR #27
Summary
Fixes #26 by increasing the agent tool iteration limit and adding budget awareness to prevent task failures on complex multi-step operations.
Problem statement
The agent was limited to 10 tool iterations, causing failures on complex tasks like building a Next.js project. When a user requested a landing page website, the agent would:
❌ Agent exceeded the 10-tool limit and failed before providing the preview URL to the user.
This caused:
Proposed solution
1. Increase Iteration Limit (10 → 25)
Update the default maximum tool iterations to accommodate complex multi-step tasks:
DEFAULT_MAX_TOOL_ITERATIONSfrom 10 to 25 insrc/agent/loop_.rsdefault_agent_max_tool_iterations()from 10 to 25 insrc/config/schema.rs2. Add Budget Awareness to System Prompt
Inject iteration budget information into the agent's system prompt so it can plan efficiently:
This helps the agent:
Changes
src/agent/loop_.rs:
DEFAULT_MAX_TOOL_ITERATIONSconstant from 10 to 25src/config/schema.rs:
default_agent_max_tool_iterations()from 10 to 25Acceptance criteria
cargo checkpasses)Testing
cargo checkRisk and Rollback
Risk: Increased resource usage from more tool calls.
Mitigation: Limit still enforced at 25; agent is now aware and plans better.
Rollback:
max_tool_iterations: 10in configBreaking Change?
No
Existing configs with explicit
max_tool_iterationsvalues are respected. Only the default changes.