Skip to main content

codetether_agent/session/helper/
loop_constants.rs

1//! Loop-control constants shared by the agentic prompt loops.
2//!
3//! The session's `prompt*` methods run an agentic loop that repeatedly calls
4//! the LLM and executes any tool calls it emits. The constants here tune the
5//! guardrails that detect and break pathological loops (e.g. the model keeps
6//! running the same tool, keeps promising to call a tool without ever doing
7//! it, etc.).
8
9/// Reminder sent when the build-mode agent responds with a plan-only answer
10/// despite the user asking for a file change.
11pub(crate) const BUILD_MODE_TOOL_FIRST_NUDGE: &str = "Build mode policy reminder: execute directly. \
12Start by calling at least one appropriate tool now (or emit <tool_call> markup for non-native \
13tool providers). Do not ask for permission and do not provide a plan-only response.";
14
15/// Maximum number of "tool-first" retries before we surface an error to the
16/// caller instead of nudging again.
17pub(crate) const BUILD_MODE_TOOL_FIRST_MAX_RETRIES: u8 = 2;
18
19/// Maximum number of retries when the model claims it is about to use a tool
20/// but never actually emits a tool call.
21pub(crate) const NATIVE_TOOL_PROMISE_RETRY_MAX_RETRIES: u8 = 1;
22
23/// Threshold of consecutive codesearch "no matches" results before we nudge
24/// the model away from brute-force variant retries.
25pub(crate) const MAX_CONSECUTIVE_CODESEARCH_NO_MATCHES: u32 = 5;
26
27/// Maximum retries for post-edit validation (build/lint/test) failures before
28/// we give up and surface the report to the caller.
29pub(crate) const POST_EDIT_VALIDATION_MAX_RETRIES: u8 = 3;
30
31/// Maximum number of consecutive identical tool calls allowed before the loop
32/// forces a final answer.
33pub(crate) const MAX_CONSECUTIVE_SAME_TOOL: u32 = 3;
34
35/// Nudge sent when the model keeps trying punctuation/casing variants of the
36/// same identifier via codesearch.
37pub(crate) const CODESEARCH_THRASH_NUDGE: &str = "Stop brute-force codesearch variant retries. \
38You already got repeated \"No matches found\" results. Do not try punctuation/casing/underscore \
39variants of the same token again. Either switch to a broader strategy (e.g., inspect likely files \
40directly) or conclude the identifier is absent and continue with the best available evidence.";
41
42/// Nudge sent when the model describes an upcoming tool call in prose instead
43/// of actually emitting one.
44pub(crate) const NATIVE_TOOL_PROMISE_NUDGE: &str = "You said you would use tools. Do not describe the tool \
45call or promise a next step. Emit the actual tool call now. If native tool calling fails, emit a \
46<tool_call> JSON block immediately instead of prose.";
47
48/// Message sent when the loop-detection guard is forcing a final answer.
49pub(crate) const FORCE_FINAL_ANSWER_NUDGE: &str = "STOP using tools. Provide your final answer NOW \
50in plain text based on the tool results you already received. Do NOT output any <tool_call> blocks.";