agent_works/guard/config.rs
1/// Reasoning-only handling strategy
2#[derive(Debug, Clone, Default)]
3pub enum ReasoningOnlyAction {
4 /// Default: fail after N nudges
5 #[default]
6 Fail,
7 /// New: disable thinking after N nudges, continue running
8 DisableThinking,
9}
10
11/// Default guard configuration
12pub struct DefaultGuardConfig {
13 // ─── reasoning-only configuration ─────────────────────────
14 /// Maximum retries for reasoning-only responses
15 pub reasoning_only_max_strikes: usize,
16 /// Nudge message for reasoning-only responses
17 pub reasoning_only_nudge: String,
18 /// Reasoning-only handling strategy
19 pub reasoning_only_action: ReasoningOnlyAction,
20
21 // ─── thinking guard configuration (for DisableThinking strategy) ──
22 /// Nudge message when disabling thinking
23 pub disable_thinking_nudge: String,
24
25 // ─── empty-response configuration ─────────────────────────
26 /// Maximum retries for empty responses
27 pub empty_response_max_strikes: usize,
28 /// Nudge message for empty responses
29 pub empty_response_nudge: String,
30
31 // ─── text-only configuration ─────────────────────────────
32 /// Whether to use LLM judge for text-only after tools
33 pub use_llm_judge: bool,
34 /// Timeout in seconds for the LLM judge call
35 pub judge_timeout_secs: u64,
36 /// Skip judge if response is longer than this (likely complete)
37 pub judge_skip_threshold: usize,
38 /// Whether to trust LLM when judge fails or times out.
39 /// - true: fail-open (trust the model, end loop)
40 /// - false: fail-closed (don't trust, force continue)
41 pub judge_fail_open: bool,
42 /// Enable short-response detection (merged from CompletionGateMiddleware).
43 /// When the user input is long but the model response is very short,
44 /// treat it as potentially incomplete and nudge/judge accordingly.
45 pub detect_short_response: bool,
46 /// Minimum user input character count to trigger short-response detection.
47 pub short_response_min_input: usize,
48 /// Maximum LLM output character count to be considered a short response.
49 pub short_response_max_output: usize,
50 /// Nudge message for short responses
51 pub short_response_nudge: String,
52 /// Number of recent user messages to include in the judge prompt.
53 /// Helps the judge understand context like "继续" after a multi-turn discussion.
54 pub recent_user_count: usize,
55
56 // ─── stream-integrity retry (turn-as-transaction) ─────────
57 /// Silent retries per round for structurally corrupt tool-call batches
58 /// (wire truncation / misplaced args). A retry discards the response
59 /// whole — nothing committed, nothing executed — and re-asks the LLM
60 /// from the same state. 0 disables the gate entirely.
61 pub max_silent_retries: u32,
62 /// Treat thinking content as visible output (blocking silent discard).
63 /// Default false: a thought glimpsed in the thoughts panel is tolerable;
64 /// visible TEXT is not.
65 pub thinking_is_visible: bool,
66}
67
68impl Default for DefaultGuardConfig {
69 fn default() -> Self {
70 Self {
71 // reasoning-only
72 reasoning_only_max_strikes: 3,
73 reasoning_only_nudge: "You produced internal reasoning but no tool call \
74 and no final answer. Make a decision now: call a tool to make progress, \
75 or write your final answer as plain text."
76 .to_string(),
77 reasoning_only_action: ReasoningOnlyAction::Fail,
78
79 // thinking guard
80 disable_thinking_nudge: "Thinking has been disabled due to excessive reasoning. \
81 You MUST now either call a tool or write your final answer. \
82 Do NOT attempt to reason further."
83 .to_string(),
84
85 // empty-response
86 empty_response_max_strikes: 3,
87 empty_response_nudge: "Your response was empty. Please provide a response \
88 with either a tool call or your final answer."
89 .to_string(),
90
91 // text-only
92 use_llm_judge: true,
93 judge_timeout_secs: 10,
94 judge_skip_threshold: 256,
95 judge_fail_open: false, // Default: don't trust LLM on judge failure
96 detect_short_response: true,
97 short_response_min_input: 128,
98 short_response_max_output: 64,
99 short_response_nudge: "Your response may be incomplete — \
100 you may need to continue."
101 .to_string(),
102 recent_user_count: 5,
103
104 // stream-integrity retry (turn-as-transaction)
105 max_silent_retries: 1,
106 thinking_is_visible: false,
107 }
108 }
109}