Skip to content

fix(subagent): append output-language.md to subagent system prompt and prioritize project-level settings#1993

Merged
tanzhenxin merged 3 commits intoQwenLM:mainfrom
zhangxy-zju:fix/subagent-output-language
Mar 2, 2026
Merged

fix(subagent): append output-language.md to subagent system prompt and prioritize project-level settings#1993
tanzhenxin merged 3 commits intoQwenLM:mainfrom
zhangxy-zju:fix/subagent-output-language

Conversation

@zhangxy-zju
Copy link
Copy Markdown
Collaborator

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.md only supported user-level (~/.qwen/) configuration with no project-level override.

This PR fixes both issues:

  • SubAgent now appends getUserMemory() (which includes QWEN.md and output-language.md) to its system prompt, consistent with the main Agent.
  • The CLI config loader now checks for .qwen/output-language.md in 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, the buildChatSystemPrompt method only assembled the subagent's own prompt and hardcoded non-interactive rules. It never called this.runtimeContext.getUserMemory(), which is the combined content of QWEN.md files and output-language.md. The main Agent does this via getCoreSystemPrompt(userMemory, model) in client.ts.

Fix: Append this.runtimeContext.getUserMemory() at the end of the subagent's system prompt using the same \n\n---\n\n separator pattern as the main Agent.

Problem 2: No project-level output-language.md support

In packages/cli/src/config/config.ts, loadCliConfig hardcoded the path to Storage.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.md in the current working directory first. If it exists, use it; otherwise fall back to the global path.

Reviewer Test Plan

  1. SubAgent language inheritance:

    • Set ~/.qwen/output-language.md to Chinese (or any non-English language).
    • Run a task that spawns a SubAgent (e.g., use the Task tool).
    • Verify the SubAgent responds in the configured language.
  2. Project-level override:

    • Create .qwen/output-language.md in a project directory with a different language than the global one.
    • Run qwen from that project directory and trigger a SubAgent task.
    • Verify the project-level language takes precedence.
  3. Backward compatibility:

    • Remove any project-level .qwen/output-language.md.
    • Verify the global ~/.qwen/output-language.md is still loaded correctly for both main Agent and SubAgent.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes #1986

…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
Copy link
Copy Markdown
Collaborator Author

自测效果:subagent的system prompt后增加了output-language.md
image

@zhangxy-zju
Copy link
Copy Markdown
Collaborator Author

output-language.md 中用的措辞是 "Prefer"(偏好),这是一个较弱的指令。
LLM的输出语言可控性较差(可能会跟随用户的输入语言;跟随注入的QWEN.md, SKILL中的语言等),导致整个会话中英文混杂
image
image
通过把偏好改成强制。 在用户明确指定语言的情况下除外,有比较好的效果,整个会话风格能够保持一致

@pomelo-nwu
Copy link
Copy Markdown
Collaborator

@zhangxy-zju Thanks for your contribution!

@yiliang114
Copy link
Copy Markdown
Collaborator

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
important scenarios.

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
@zhangxy-zju
Copy link
Copy Markdown
Collaborator Author

zhangxy-zju commented Feb 28, 2026

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 important scenarios.

Thanks again, and welcome to Qwen Code! ❤

Thanks for the warm welcome and the review! 🙏

I've just pushed a follow-up commit (0788003) that adds unit tests covering the changes:

  • 3 tests for SubAgentScope.buildChatSystemPrompt: verifies userMemory is correctly appended, and that empty/whitespace-only memory doesn't inject separators
  • 3 tests for output-language.md path resolution: verifies project-level priority, global fallback, and the case when neither exists

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.

Copy link
Copy Markdown
Collaborator

@tanzhenxin tanzhenxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tanzhenxin tanzhenxin merged commit 74f5b76 into QwenLM:main Mar 2, 2026
13 checks passed
@zhangxy-zju zhangxy-zju deleted the fix/subagent-output-language branch March 2, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug/Feature] SubAgent does not respect output-language.md and QWEN.md context

4 participants