Skip to content

Commit f0e3706

Browse files
committed
fix(delegate): respect chat.defaultAgent setting when no agent is specified
When the delegate tool is invoked without an explicit agent name, it was unconditionally falling back to the hardcoded DEFAULT_AGENT_NAME ("q_cli_default"), ignoring the user's chat.defaultAgent setting. Fix the fallback chain to: 1. Use the explicitly provided agent name (unchanged) 2. Fall back to chat.defaultAgent setting if set 3. Fall back to DEFAULT_AGENT_NAME as last resort Fixes #3174
1 parent e14ea18 commit f0e3706

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

crates/chat-cli/src/cli/chat/tools/delegate.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::cli::{
3636
Agent,
3737
DEFAULT_AGENT_NAME,
3838
};
39+
use crate::database::settings::Setting;
3940
use crate::os::Os;
4041
use crate::theme::StyledText;
4142
use crate::util::env_var::get_all_env_vars;
@@ -99,7 +100,14 @@ impl Delegate {
99100
.as_ref()
100101
.ok_or(eyre::eyre!("Task description is required for launch operation"))?;
101102

102-
let agent_name = self.agent.as_deref().unwrap_or(DEFAULT_AGENT_NAME);
103+
// Respect chat.defaultAgent setting before falling back to the hardcoded default.
104+
// See: #3174
105+
let configured_default = os.database.settings.get_string(Setting::ChatDefaultAgent);
106+
let agent_name = self
107+
.agent
108+
.as_deref()
109+
.or(configured_default.as_deref())
110+
.unwrap_or(DEFAULT_AGENT_NAME);
103111

104112
launch_agent(os, agent_name, agents, task).await?
105113
},
@@ -599,4 +607,27 @@ mod tests {
599607
let schema = schemars::schema_for!(Delegate);
600608
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
601609
}
610+
611+
/// Simulates the agent name resolution logic from Delegate::invoke.
612+
fn resolve_agent_name<'a>(
613+
explicit: Option<&'a str>,
614+
configured_default: Option<&'a str>,
615+
) -> &'a str {
616+
explicit.or(configured_default).unwrap_or(DEFAULT_AGENT_NAME)
617+
}
618+
619+
#[test]
620+
fn explicit_agent_takes_priority() {
621+
assert_eq!(resolve_agent_name(Some("my-agent"), Some("other")), "my-agent");
622+
}
623+
624+
#[test]
625+
fn configured_default_used_when_no_explicit_agent() {
626+
assert_eq!(resolve_agent_name(None, Some("configured-agent")), "configured-agent");
627+
}
628+
629+
#[test]
630+
fn falls_back_to_default_agent_name_when_nothing_configured() {
631+
assert_eq!(resolve_agent_name(None, None), DEFAULT_AGENT_NAME);
632+
}
602633
}

0 commit comments

Comments
 (0)