Skip to content

fix(delegate): respect chat.defaultAgent setting when no agent is specified#3720

Open
sandikodev wants to merge 1 commit intoaws:mainfrom
sandikodev:fix/delegate-default-agent
Open

fix(delegate): respect chat.defaultAgent setting when no agent is specified#3720
sandikodev wants to merge 1 commit intoaws:mainfrom
sandikodev:fix/delegate-default-agent

Conversation

@sandikodev
Copy link
Copy Markdown

@sandikodev sandikodev commented Apr 4, 2026

Issue

Closes #3174

Problem

When the delegate tool is invoked without an explicit agent parameter, it unconditionally falls back to the hardcoded DEFAULT_AGENT_NAME ("q_cli_default"), ignoring the user's chat.defaultAgent setting.

Reproduction:

q settings chat.defaultAgent my-agent
q chat
# delegate a task without specifying an agent
# → uses q_cli_default instead of my-agent

Fix

Change the fallback chain from:

// Before: always falls back to hardcoded default
let agent_name = self.agent.as_deref().unwrap_or(DEFAULT_AGENT_NAME);

To:

// After: respects chat.defaultAgent setting
let configured_default = os.database.settings.get_string(Setting::ChatDefaultAgent);
let agent_name = self
    .agent
    .as_deref()
    .or(configured_default.as_deref())
    .unwrap_or(DEFAULT_AGENT_NAME);

New fallback chain:

  1. Explicitly provided agent parameter (unchanged)
  2. chat.defaultAgent setting (if configured)
  3. DEFAULT_AGENT_NAME as last resort

Testing

# Run the targeted tests
cargo test -p chat_cli 'delegate::tests'

# Run the full test suite to check for regressions
cargo test -p chat_cli

Four tests cover the full fallback chain:

  1. explicit_agent_takes_priority — explicit parameter overrides everything
  2. configured_default_used_when_no_explicit_agentchat.defaultAgent is used when no explicit agent is given
  3. falls_back_to_default_agent_name_when_nothing_configuredDEFAULT_AGENT_NAME is used as last resort
  4. get_schema — existing schema test (unchanged)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…cified

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 aws#3174
@sandikodev sandikodev force-pushed the fix/delegate-default-agent branch from d01266a to f0e3706 Compare April 4, 2026 16:02
@sandikodev
Copy link
Copy Markdown
Author

Update (amended commit): Tests were added after initial submission to verify the fallback chain logic:

  1. Explicit agent parameter takes priority over everything
  2. chat.defaultAgent setting is used when no explicit agent is given
  3. DEFAULT_AGENT_NAME is used as last resort when nothing is configured

The resolution logic was extracted into a local resolve_agent_name helper inside the test module to make it directly testable without requiring a full Os + Agents setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delegate command uses q_cli_default by default instead of chat.defaultAgent setting

1 participant