Skip to content

Commit f16df7f

Browse files
committed
fix(agent): increase tool iteration limit from 10 to 25 and add budget 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
1 parent c6f8b70 commit f16df7f

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/agent/loop_.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const STREAM_CHUNK_MIN_CHARS: usize = 80;
2525

2626
/// Default maximum agentic tool-use iterations per user message to prevent runaway loops.
2727
/// Used as a safe fallback when `max_tool_iterations` is unset or configured as zero.
28-
const DEFAULT_MAX_TOOL_ITERATIONS: usize = 10;
28+
/// Increased from 10 to 25 to accommodate complex multi-step tasks while maintaining
29+
/// safety bounds. See issue #26 for context.
30+
const DEFAULT_MAX_TOOL_ITERATIONS: usize = 25;
2931

3032
/// Minimum user-message length (in chars) for auto-save to memory.
3133
/// Matches the channel-side constant in `channels/mod.rs`.
@@ -3019,6 +3021,17 @@ pub async fn run(
30193021
system_prompt.push_str(&build_tool_instructions(&tools_registry));
30203022
}
30213023

3024+
// Add iteration budget awareness to system prompt
3025+
let max_iterations = if config.agent.max_tool_iterations == 0 {
3026+
DEFAULT_MAX_TOOL_ITERATIONS
3027+
} else {
3028+
config.agent.max_tool_iterations
3029+
};
3030+
system_prompt.push_str(&format!(
3031+
"\n## Tool Use Budget\n\nYou have a maximum of {} tool-use iterations to complete this task. Plan efficiently:\n\n- **Complex tasks** (build projects, multiple files): ~15-20 iterations\n- **Medium tasks** (modify existing code): ~8-12 iterations\n- **Simple tasks** (read files, explain): ~3-5 iterations\n\nIf approaching the limit, prioritize:\n1. Complete the critical path first (create → build → verify)\n2. Skip verification steps if already confident\n3. Provide partial results with explanation rather than failing\n\n",
3032+
max_iterations
3033+
));
3034+
30223035
// ── Approval manager (supervised mode) ───────────────────────
30233036
let approval_manager = if interactive {
30243037
Some(ApprovalManager::from_config(&config.autonomy))

src/config/schema.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,9 @@ pub struct AgentConfig {
542542
/// When true: bootstrap_max_chars=6000, rag_chunk_limit=2. Use for 13B or smaller models.
543543
#[serde(default)]
544544
pub compact_context: bool,
545-
/// Maximum tool-call loop turns per user message. Default: `10`.
546-
/// Setting to `0` falls back to the safe default of `10`.
545+
/// Maximum tool-call loop turns per user message. Default: `25`.
546+
/// Setting to `0` falls back to the safe default of `25`.
547+
/// Increased from 10 to support complex multi-step tasks (see issue #26).
547548
#[serde(default = "default_agent_max_tool_iterations")]
548549
pub max_tool_iterations: usize,
549550
/// Maximum conversation history messages retained per session. Default: `50`.
@@ -558,7 +559,7 @@ pub struct AgentConfig {
558559
}
559560

560561
fn default_agent_max_tool_iterations() -> usize {
561-
10
562+
25
562563
}
563564

564565
fn default_agent_max_history_messages() -> usize {

0 commit comments

Comments
 (0)