Skip to content

Commit 28b59e8

Browse files
fix(agent): let config enabled = false override per-agent reasoning settings (#2994)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a18a4b0 commit 28b59e8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

crates/forge_app/src/agent.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ impl AgentExt for Agent {
145145

146146
// Apply workflow reasoning configuration to agents.
147147
// Agent-level fields take priority; config fills in any unset fields.
148+
// Exception: config `enabled = false` always wins — it is an explicit
149+
// global disable that must override any per-agent setting.
148150
if let Some(ref config_reasoning) = config.reasoning {
149151
use forge_config::Effort as ConfigEffort;
150152
let config_as_domain = ReasoningConfig {
@@ -164,6 +166,11 @@ impl AgentExt for Agent {
164166
// Start from the agent's own settings and fill unset fields from config.
165167
let mut merged = agent.reasoning.clone().unwrap_or_default();
166168
merged.merge(config_as_domain);
169+
// If the config explicitly disables reasoning, honour that override
170+
// regardless of what the agent definition says.
171+
if config_reasoning.enabled == Some(false) {
172+
merged.enabled = Some(false);
173+
}
167174
agent.reasoning = Some(merged);
168175
}
169176

@@ -233,4 +240,28 @@ mod tests {
233240

234241
assert_eq!(actual, expected);
235242
}
243+
244+
/// When config sets `enabled = false`, it must override the agent's
245+
/// `enabled = true`. This prevents reasoning parameters from being sent to
246+
/// models that don't support them (e.g. claude-haiku with effort set).
247+
#[test]
248+
fn test_config_disabled_overrides_agent_enabled() {
249+
let config = ForgeConfig::default().reasoning(
250+
ConfigReasoningConfig::default()
251+
.enabled(false)
252+
.effort(ConfigEffort::None),
253+
);
254+
255+
// Agent has reasoning explicitly enabled.
256+
let agent = fixture_agent().reasoning(
257+
ReasoningConfig::default()
258+
.enabled(true)
259+
.effort(Effort::High),
260+
);
261+
262+
let actual = agent.apply_config(&config).reasoning;
263+
264+
// enabled must be false even though the agent said true.
265+
assert_eq!(actual.as_ref().and_then(|r| r.enabled), Some(false));
266+
}
236267
}

0 commit comments

Comments
 (0)