9598d162dd
算法修复 (P0/P1): - P0-1: 空亡判断改为仅从日柱计算(年月空亡标注但不断事) - P0-2: 暗动判断重写为静爻+旺相+日冲三条件 - P1-1: 月破独立标注 - P1-2: 动不为空、旺不为空 - P1-3: 三合局判断 - P1-4: 反吟伏吟判断 - P1-5: 日辰十二长生 - P1-6: 回头生克判断 Prompt架构重构: - 删除system_prompt中_build_env_section,不再泄露用户上下文到prompt - 删除if is_chinese分支,_LANGUAGE_LABELS已覆盖全部语言映射 - 安全规则改为六爻专属约束,拒绝无关问题 - sign_level枚举值在所有语言版本中统一为简体中文(schema严格约束) - _WORKER_ROLE_PLAYING始终为中文,不因ai_language切换 - _WORKER_OUTPUT_RULES按ai_language分zh-CN/zh-Hant/en三版本 - worker_rules.py独立文件管理多语言输出规则 - runner ai_language从user_context.settings.preferences提取传入prompt 清理死代码: - 删除UserPreferences/RuntimePromptContext及辅助函数 - 删除runner中runtime_client_time参数链路 - 删除SystemAgentRuntimeConfig.extra_context - 删除sections.py中env section marker - 删除agent_prompt.py中AgentPromptRegistry死代码 安全规则: - AGENTS.md添加Git Safety规则(禁止未经批准的破坏性git操作) - opencode.json添加高危git命令审批配置 测试: - 新增22个六爻算法单元测试(空亡/暗动/月破/三合局等) - 重写7个prompt测试适配新签名 - 全部85个单元测试通过
84 lines
2.4 KiB
Python
84 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
from core.agentscope.prompts.agent_prompt import build_agent_prompt
|
|
from core.agentscope.prompts.system_prompt import build_system_prompt
|
|
from schemas.agent.system_agent import AgentType, SystemAgentLLMConfig
|
|
|
|
|
|
def test_system_prompt_enforces_ai_language_en() -> None:
|
|
prompt = build_system_prompt(
|
|
agent_type=AgentType.WORKER,
|
|
ai_language="en-US",
|
|
llm_config=SystemAgentLLMConfig(),
|
|
)
|
|
|
|
assert "English" in prompt
|
|
assert "<!-- SAFETY_START -->" in prompt
|
|
assert "<!-- OUTPUT_START -->" in prompt
|
|
|
|
|
|
def test_system_prompt_enforces_ai_language_zh_cn() -> None:
|
|
prompt = build_system_prompt(
|
|
agent_type=AgentType.WORKER,
|
|
ai_language="zh-CN",
|
|
llm_config=SystemAgentLLMConfig(),
|
|
)
|
|
|
|
assert "简体中文" in prompt
|
|
assert "<!-- SAFETY_START -->" in prompt
|
|
|
|
|
|
def test_system_prompt_safety_restricts_to_divination() -> None:
|
|
prompt = build_system_prompt(
|
|
agent_type=AgentType.WORKER,
|
|
ai_language="zh-CN",
|
|
llm_config=SystemAgentLLMConfig(),
|
|
)
|
|
|
|
assert "只回答与六爻占卜" in prompt or "解卦" in prompt
|
|
|
|
|
|
def test_system_prompt_does_not_contain_env_section() -> None:
|
|
prompt = build_system_prompt(
|
|
agent_type=AgentType.WORKER,
|
|
ai_language="zh-CN",
|
|
llm_config=SystemAgentLLMConfig(),
|
|
)
|
|
|
|
assert "USER_CONTEXT_JSON" not in prompt
|
|
assert "Runtime Context" not in prompt
|
|
assert "<!-- ENV_START -->" not in prompt
|
|
|
|
|
|
def test_agent_prompt_keeps_only_identity_and_domain_flow() -> None:
|
|
prompt = build_agent_prompt(
|
|
agent_type=AgentType.WORKER,
|
|
llm_config=SystemAgentLLMConfig(),
|
|
)
|
|
|
|
assert "focus_points" in prompt
|
|
assert "段间用\\n\\n" in prompt
|
|
assert "[role_playing]" in prompt
|
|
assert "[output_json_rules]" in prompt
|
|
|
|
|
|
def test_system_prompt_sections_are_not_duplicated() -> None:
|
|
prompt = build_system_prompt(
|
|
agent_type=AgentType.WORKER,
|
|
ai_language="zh-CN",
|
|
llm_config=SystemAgentLLMConfig(),
|
|
)
|
|
|
|
assert prompt.count("<!-- SAFETY_START -->") == 1
|
|
assert prompt.count("<!-- AGENT_START -->") == 1
|
|
assert prompt.count("<!-- OUTPUT_START -->") == 1
|
|
|
|
|
|
def test_system_prompt_requires_paragraph_breaks_for_answer() -> None:
|
|
prompt = build_agent_prompt(
|
|
agent_type=AgentType.WORKER,
|
|
llm_config=SystemAgentLLMConfig(),
|
|
)
|
|
|
|
assert "段间用\\n\\n" in prompt
|