fix(subagent): append output-language.md to subagent system prompt and prioritize project-level settings#1993
Conversation
…d prioritize project-level settings - SubAgentScope now automatically appends global memory (including QWEN.md and output-language.md) to its system prompt, ensuring subagents respect project conventions and language preferences. - The CLI config loader now checks for `.qwen/output-language.md` in the project directory before falling back to the global `~/.qwen/output-language.md`, allowing project-specific language settings. Made-with: Cursor
|
@zhangxy-zju Thanks for your contribution! |
…pt for project conventions)
|
hi @zhangxy-zju 👋 Thanks for the contribution! 🎉 Code looks great — clean, consistent, and solves the problem perfectly. LGTM! 🚀 My only suggestion would be to add some unit tests in a follow-up PR when you have time. No worries for this one though — the implementation is solid and the manual test plan covers the Thanks again, and welcome to Qwen Code! ❤ |
…guage path priority - Add 3 tests for SubAgentScope.buildChatSystemPrompt appending userMemory - Add 3 tests for project-level output-language.md path resolution priority Made-with: Cursor
Thanks for the warm welcome and the review! 🙏 I've just pushed a follow-up commit (0788003) that adds unit tests covering the changes:
Note: the existing config.test.ts and config.integration.test.ts in packages/cli have a pre-existing https module resolution failure in the test environment, so the path resolution tests were placed in languageUtils.test.ts where they can run cleanly. I also have a separate PR #2005 coming for strengthening the output-language template wording (from "Prefer" to "MUST always respond") — splitting it out to keep this PR focused. |



TLDR
SubAgent's system prompt was missing global user memory context (QWEN.md and output-language.md), causing it to ignore project conventions and language preferences. Additionally,
output-language.mdonly supported user-level (~/.qwen/) configuration with no project-level override.This PR fixes both issues:
getUserMemory()(which includes QWEN.md and output-language.md) to its system prompt, consistent with the main Agent..qwen/output-language.mdin the project directory first, falling back to the global~/.qwen/output-language.md.Dive Deeper
Problem 1: SubAgent ignores output-language.md and QWEN.md
In
packages/core/src/subagents/subagent.ts, thebuildChatSystemPromptmethod only assembled the subagent's own prompt and hardcoded non-interactive rules. It never calledthis.runtimeContext.getUserMemory(), which is the combined content ofQWEN.mdfiles andoutput-language.md. The main Agent does this viagetCoreSystemPrompt(userMemory, model)inclient.ts.Fix: Append
this.runtimeContext.getUserMemory()at the end of the subagent's system prompt using the same\n\n---\n\nseparator pattern as the main Agent.Problem 2: No project-level output-language.md support
In
packages/cli/src/config/config.ts,loadCliConfighardcoded the path toStorage.getGlobalQwenDir() + 'output-language.md'(i.e.,~/.qwen/output-language.md). There was no mechanism to allow per-project language overrides.Fix: Check for
.qwen/output-language.mdin the current working directory first. If it exists, use it; otherwise fall back to the global path.Reviewer Test Plan
SubAgent language inheritance:
~/.qwen/output-language.mdto Chinese (or any non-English language).Project-level override:
.qwen/output-language.mdin a project directory with a different language than the global one.qwenfrom that project directory and trigger a SubAgent task.Backward compatibility:
.qwen/output-language.md.~/.qwen/output-language.mdis still loaded correctly for both main Agent and SubAgent.Testing Matrix
Linked issues / bugs
Fixes #1986