Files
eryao/backend/tests/unit/test_agentscope_prompts.py
ZL-Q b9617ae152 refactor(settings): 统一语言设置,合并 interface_language 和 ai_language
- 后端 Schema 将 interface_language 和 ai_language 合并为 language
- 前端设置界面只保留一个语言选项
- AI 回复语言统一使用 language 设置
- 更新协议文档
- 新增数据库迁移脚本
2026-04-28 17:19:47 +08:00

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_language_en() -> None:
prompt = build_system_prompt(
agent_type=AgentType.WORKER,
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_language_zh_cn() -> None:
prompt = build_system_prompt(
agent_type=AgentType.WORKER,
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,
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,
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,
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