Skip to main content

vtcode_config/constants/
tool_limits.rs

1/// Default maximum number of tool-loop iterations in one agent turn.
2pub const DEFAULT_MAX_TOOL_LOOPS: usize = 60;
3/// Default maximum number of turns in full-auto execution.
4pub const DEFAULT_FULL_AUTO_MAX_TURNS: usize = 100;
5/// Default conversation-turn retention limit. This is a context-retention
6/// limit, not a tool-execution budget.
7pub const DEFAULT_MAX_CONVERSATION_TURNS: usize = 150;
8
9/// Hard cap for ordinary tool-loop extensions.
10pub const MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP: usize = 120;
11/// Multiplier used to derive the ordinary extension hard cap.
12pub const MAX_TOOL_LOOP_CAP_MULTIPLIER: usize = 3;
13/// Maximum ordinary tool-loop extension accepted from one prompt.
14pub const MAX_TOOL_LOOP_INCREMENT_PER_PROMPT: usize = 50;
15/// One-time internal allowance applied when an approved plan enters execution.
16/// This is not a user-facing configuration field and remains bounded by the
17/// ordinary tool-loop hard cap.
18pub const APPROVED_PLAN_TOOL_LOOP_INCREMENT: usize = 50;
19/// Minimum tool-loop budget while planning research is active.
20pub const PLANNING_WORKFLOW_MIN_TOOL_LOOPS: usize = 60;
21/// Hard cap for planning tool-loop extensions.
22pub const PLANNING_WORKFLOW_MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP: usize = 240;
23/// Multiplier used to derive the planning extension hard cap.
24pub const PLANNING_WORKFLOW_TOOL_LOOP_CAP_MULTIPLIER: usize = 6;
25/// Maximum planning tool-loop extension accepted from one prompt.
26pub const PLANNING_WORKFLOW_MAX_TOOL_LOOP_INCREMENT_PER_PROMPT: usize = 80;
27
28/// Absolute ceiling for per-turn tool-loop extensions derived from a
29/// configured base limit. Values at or above the absolute cap are returned
30/// unchanged so an already-generous configuration is never shrunk.
31pub const fn tool_loop_hard_cap(base_limit: usize, planning_active: bool) -> usize {
32    if planning_active {
33        if base_limit >= PLANNING_WORKFLOW_MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP {
34            return base_limit;
35        }
36        let scaled = base_limit.saturating_mul(PLANNING_WORKFLOW_TOOL_LOOP_CAP_MULTIPLIER);
37        if scaled > PLANNING_WORKFLOW_MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP {
38            return PLANNING_WORKFLOW_MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP;
39        }
40        return scaled;
41    }
42    if base_limit >= MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP {
43        return base_limit;
44    }
45    let scaled = base_limit.saturating_mul(MAX_TOOL_LOOP_CAP_MULTIPLIER);
46    if scaled > MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP {
47        return MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP;
48    }
49    scaled
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn default_execution_loop_budgets_are_moderate_and_bounded() {
58        assert_eq!(DEFAULT_MAX_TOOL_LOOPS, 60);
59        assert_eq!(DEFAULT_FULL_AUTO_MAX_TURNS, 100);
60        assert_eq!(DEFAULT_MAX_CONVERSATION_TURNS, 150);
61    }
62
63    #[test]
64    fn planning_and_approved_plan_budgets_are_explicitly_separate() {
65        assert_eq!(PLANNING_WORKFLOW_MIN_TOOL_LOOPS, 60);
66        assert_eq!(MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP, 120);
67        assert_eq!(PLANNING_WORKFLOW_MAX_TOOL_LOOP_LIMIT_ABSOLUTE_CAP, 240);
68        assert_eq!(APPROVED_PLAN_TOOL_LOOP_INCREMENT, 50);
69    }
70
71    #[test]
72    fn tool_loop_hard_cap_scales_and_bounds() {
73        assert_eq!(tool_loop_hard_cap(20, false), 60);
74        assert_eq!(tool_loop_hard_cap(40, false), 120);
75        assert_eq!(tool_loop_hard_cap(60, false), 120);
76        assert_eq!(tool_loop_hard_cap(120, false), 120);
77        assert_eq!(tool_loop_hard_cap(200, false), 200);
78        assert_eq!(tool_loop_hard_cap(0, false), 0);
79        assert_eq!(tool_loop_hard_cap(40, true), 240);
80        assert_eq!(tool_loop_hard_cap(120, true), 240);
81        assert_eq!(tool_loop_hard_cap(300, true), 300);
82    }
83}