JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
refactor: simplify code agent prompt instructions and add language output constraint
ldstyle889f65439e1c1
diff --git a/jiuwenswarm/agents/harness/code/prompt/code_prompt_builder.py b/jiuwenswarm/agents/harness/code/prompt/code_prompt_builder.pyindex ed331e38ae..c86dacd223 100644--- a/jiuwenswarm/agents/harness/code/prompt/code_prompt_builder.py+++ b/jiuwenswarm/agents/harness/code/prompt/code_prompt_builder.py@@ -97,17 +97,7 @@ def _code_system_prompt() -> PromptSection:"- The system will automatically compress prior messages ""in your conversation as it approaches context limits. ""This means your conversation with the user "- "is not limited by the context window. "- "Older messages get condensed when length grows, "- "marked as `[OFFLOAD: handle=<id>, type=<type>]`. "- "Call `reload_original_context_messages` to retrieve condensed content. "- "Never invent or assume what was compressed away.\n"- "- Old tool results may be compressed or cleared in long conversations. "- "Preserve key facts needed for later reasoning (file paths, error summaries, "- "important decisions) in your responses, "- "but do not dump raw tool output to the user just to save context. "- "When you need to precisely recover compressed content, "- "call reload_original_context_messages; do not guess."+ "is not limited by the context window.")return PromptSection(name="code_system",@@ -130,7 +120,7 @@ def _code_session_guidance_prompt() -> PromptSection:"suggest they type `! <command>` in the prompt — ""the `!` prefix runs the command in this session ""so its output lands directly in the conversation.\n"- "- Use task_tool with specialized agents when the task at hand "+ "- Use the task_tool with specialized agents when the task at hand ""matches the agent's description. ""Subagents are valuable for parallelizing independent queries ""or for protecting the main context window from excessive results, "@@ -236,12 +226,10 @@ def _code_doing_tasks_prompt() -> PromptSection:"such as command injection, XSS, SQL injection, ""and other OWASP top 10 vulnerabilities. ""If you notice that you wrote insecure code, immediately fix it. "- "Prioritize writing safe, secure, and correct code.\n"- "- When handling user input or external API responses, "- "validate and sanitize before use — "- "never concatenate directly into commands, SQL, or HTML.\n"- "- Never hard-code secrets, tokens, or credentials in source code, "- "commit them to version control, or expose them in logs or output.\n"+ "Prioritize writing safe, secure, and correct code. "+ "Validate and sanitize external input before use. "+ "Never hard-code secrets, tokens, or credentials "+ "in source code, version control, or logs.\n""- Don't add features, refactor code, "'or make "improvements" beyond what was asked. '"A bug fix doesn't need surrounding code cleaned up. "diff --git a/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py b/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.pyindex 0bbebf351e..b9ce92c02d 100644--- a/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py+++ b/jiuwenswarm/agents/harness/common/rails/runtime_prompt_rail.py@@ -24,6 +24,8 @@ from jiuwenswarm.common.utils import get_agent_workspace_dir_CN_WEEKDAYS = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]+_LANGUAGE_NAMES = {"cn": "Chinese", "zh": "Chinese", "en": "English"}+class RuntimePromptRail(DeepAgentRail):"""在 before_model_call 中注入时间及运行时状态文件路径。"""@@ -57,6 +59,7 @@ class RuntimePromptRail(DeepAgentRail):if self.system_prompt_builder is not None:self.system_prompt_builder.remove_section("time")self.system_prompt_builder.remove_section("runtime")+ self.system_prompt_builder.remove_section("language_output")self.system_prompt_builder.remove_section("env")self.system_prompt_builder.remove_section("git_status")self.system_prompt_builder.remove_section("browser_tool_policy")@@ -197,6 +200,23 @@ class RuntimePromptRail(DeepAgentRail):priority=95,))+ # ── Language output constraint (injected near end, like Claude Code) ──+ self.system_prompt_builder.remove_section("language_output")+ language_name = _LANGUAGE_NAMES.get(language_val, language_val)+ language_output_content = (+ "# Language\n\n"+ f"Always respond in {language_name}. "+ f"Use {language_name} for all explanations, comments, "+ f"and communications with the user. "+ f"Technical terms and code identifiers should remain "+ f"in their original form."+ )+ self.system_prompt_builder.add_section(PromptSection(+ name="language_output",+ content={"cn": language_output_content, "en": language_output_content},+ priority=93,+ ))+# ── Platform / OS environment section ──os_type = sys.platformshell_path = os.environ.get("SHELL", "")diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_code.py b/jiuwenswarm/server/runtime/agent_adapter/interface_code.pyindex 0696c42546..1821e2a660 100644--- a/jiuwenswarm/server/runtime/agent_adapter/interface_code.py+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_code.py@@ -152,6 +152,22 @@ class JiuwenClawCodeAdapter(JiuWenClawDeepAdapter):"""Code mode always uses English for runtime language."""return "en"+ def _resolve_output_language(self) -> str:+ """Resolve user's preferred output language for runtime_state display.++ Distinct from prompt/runtime language (always "en" in code mode).+ Returns the normalized language code ("cn"/"en") based on+ config.yaml preferred_language, so the Language section injected+ by RuntimePromptRail can instruct the LLM to respond in the+ user's chosen language.+ """+ from openjiuwen.harness.prompts import resolve_language+ config_base = get_config()+ raw = str(config_base.get("preferred_language", "zh")).strip().lower()+ if raw == "zh":+ raw = "cn"+ return resolve_language(raw)+# ─── 初始化 ──────────────────────────────async def create_instance(self, config: dict[str, Any] | None = None, *,@@ -788,7 +804,7 @@ class JiuwenClawCodeAdapter(JiuWenClawDeepAdapter):)self._write_runtime_state(mode=runtime_config.mode,- language=resolved_language,+ language=self._resolve_output_language(),channel=resolved_channel,project_dir=runtime_config.project_diror runtime_config.cwd