Is there an existing issue for this?
Current Behavior
For a chat's built-in workspace tools (execute, read_file, write_file, edit_files, process_output, process_list, process_signal), the agent to connect to is resolved once per chat, not per tool call, via agentselect.FindChatAgent (coderd/x/chatd/agentselect/agentselect.go):
- Filters to root agents only (
ParentID null) — this is a separate path from the devcontainer sub-agent issues above.
- Sorts deterministically by
DisplayOrder ASC, then Name ASC (case-insensitive), then Name ASC, then ID ASC.
- If exactly one root agent's name ends in the suffix
-coderd-chat, uses it.
- If zero agents match that suffix (the common case — most templates don't name agents this way), it silently falls back to whichever root agent sorts first. There is no prompt, no error, no indication to the user which agent was picked.
- If more than one agent matches the suffix, it errors.
None of the built-in tool argument schemas (ExecuteArgs, ReadFileArgs, etc. in coderd/x/chatd/chattool/) have an agent-selection field, so once a chat is bound to an agent via step 4 above, there is no way to redirect subsequent tool calls to a different root agent in the same workspace — not via a tool argument, not via a chat setting.
The -coderd-chat naming convention is explicitly flagged in source as a stopgap: "Suffix marks chat-designated agents during the current PoC. This naming convention is an implementation detail, not a stable contract."
Relevant Log Output
N/A — this is a source-code analysis of deterministic selection logic, not a runtime error with logs to attach.
Expected Behavior
For a composite/multi-root-agent template (e.g. a workspace with separate frontend, backend, and database agents, each a distinct root coder_agent resource with no parent/child relationship), the user should be able to either:
- See which agent the chat is currently targeting, and/or
- Explicitly pick or switch the target agent for a chat (or per tool call), rather than relying on alphabetical/
DisplayOrder sort order as a silent default.
For comparison, the newer MCP-exposed tool family (codersdk/toolsdk, e.g. coder_workspace_execute) already solves this cleanly: its workspace argument accepts [owner/]workspace[.agent], and findWorkspaceAndAgent (codersdk/toolsdk/workspaceagent.go) explicitly errors ("multiple agents found, please specify the agent name...") rather than silently guessing when the target is ambiguous. The chatd built-in tools used by the Coder Agents chat UI don't have an equivalent mechanism.
Steps to Reproduce
- Create a template with 3+ separate root
coder_agent resources (no devcontainers, no parent/child relationship) and none named with a -coderd-chat suffix.
- Start a Coder Agents chat against a workspace from that template.
- Ask the chat to run a shell command.
- Observe it silently runs against whichever agent sorts first alphabetically (or by
DisplayOrder), with no way to confirm or change which agent was used, and no way to target a different one later in the same chat.
Environment
- Host OS: N/A (control-plane logic, not host-dependent)
- Coder version: confirmed present as of
main @ a4b68ac (2026-10-08) and the pinned release v2.36.4+10fd510. agentselect.go is byte-identical between the two, so this isn't a regression — it's present in both.
Additional Context
The issue occurs consistently, I have tested this on the latest version
Is there an existing issue for this?
Current Behavior
For a chat's built-in workspace tools (
execute,read_file,write_file,edit_files,process_output,process_list,process_signal), the agent to connect to is resolved once per chat, not per tool call, viaagentselect.FindChatAgent(coderd/x/chatd/agentselect/agentselect.go):ParentIDnull) — this is a separate path from the devcontainer sub-agent issues above.DisplayOrderASC, thenNameASC (case-insensitive), thenNameASC, thenIDASC.-coderd-chat, uses it.None of the built-in tool argument schemas (
ExecuteArgs,ReadFileArgs, etc. incoderd/x/chatd/chattool/) have an agent-selection field, so once a chat is bound to an agent via step 4 above, there is no way to redirect subsequent tool calls to a different root agent in the same workspace — not via a tool argument, not via a chat setting.The
-coderd-chatnaming convention is explicitly flagged in source as a stopgap: "Suffix marks chat-designated agents during the current PoC. This naming convention is an implementation detail, not a stable contract."Relevant Log Output
Expected Behavior
For a composite/multi-root-agent template (e.g. a workspace with separate
frontend,backend, anddatabaseagents, each a distinct rootcoder_agentresource with no parent/child relationship), the user should be able to either:DisplayOrdersort order as a silent default.For comparison, the newer MCP-exposed tool family (
codersdk/toolsdk, e.g.coder_workspace_execute) already solves this cleanly: itsworkspaceargument accepts[owner/]workspace[.agent], andfindWorkspaceAndAgent(codersdk/toolsdk/workspaceagent.go) explicitly errors ("multiple agents found, please specify the agent name...") rather than silently guessing when the target is ambiguous. The chatd built-in tools used by the Coder Agents chat UI don't have an equivalent mechanism.Steps to Reproduce
coder_agentresources (no devcontainers, no parent/child relationship) and none named with a-coderd-chatsuffix.DisplayOrder), with no way to confirm or change which agent was used, and no way to target a different one later in the same chat.Environment
main@a4b68ac(2026-10-08) and the pinned releasev2.36.4+10fd510.agentselect.gois byte-identical between the two, so this isn't a regression — it's present in both.Additional Context
The issue occurs consistently, I have tested this on the latest version