2026-04-07 18:43:24 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2026-04-28 17:19:47 +08:00
|
|
|
def test_system_prompt_enforces_language_en() -> None:
|
2026-04-07 18:43:24 +08:00
|
|
|
prompt = build_system_prompt(
|
|
|
|
|
agent_type=AgentType.WORKER,
|
2026-04-28 17:19:47 +08:00
|
|
|
language="en-US",
|
2026-04-07 18:43:24 +08:00
|
|
|
llm_config=SystemAgentLLMConfig(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
assert "English" in prompt
|
|
|
|
|
assert "<!-- SAFETY_START -->" in prompt
|
|
|
|
|
assert "<!-- OUTPUT_START -->" in prompt
|
2026-04-07 18:43:24 +08:00
|
|
|
|
|
|
|
|
|
2026-04-28 17:19:47 +08:00
|
|
|
def test_system_prompt_enforces_language_zh_cn() -> None:
|
2026-04-07 18:43:24 +08:00
|
|
|
prompt = build_system_prompt(
|
|
|
|
|
agent_type=AgentType.WORKER,
|
2026-04-28 17:19:47 +08:00
|
|
|
language="zh-CN",
|
2026-04-07 18:43:24 +08:00
|
|
|
llm_config=SystemAgentLLMConfig(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
assert "简体中文" in prompt
|
|
|
|
|
assert "<!-- SAFETY_START -->" in prompt
|
2026-04-07 18:43:24 +08:00
|
|
|
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
def test_system_prompt_safety_restricts_to_divination() -> None:
|
|
|
|
|
prompt = build_system_prompt(
|
2026-04-07 18:43:24 +08:00
|
|
|
agent_type=AgentType.WORKER,
|
2026-04-28 17:19:47 +08:00
|
|
|
language="zh-CN",
|
2026-04-07 18:43:24 +08:00
|
|
|
llm_config=SystemAgentLLMConfig(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
assert "只回答与六爻占卜" in prompt or "解卦" in prompt
|
2026-04-07 18:43:24 +08:00
|
|
|
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
def test_system_prompt_does_not_contain_env_section() -> None:
|
|
|
|
|
prompt = build_system_prompt(
|
|
|
|
|
agent_type=AgentType.WORKER,
|
2026-04-28 17:19:47 +08:00
|
|
|
language="zh-CN",
|
2026-04-15 16:45:57 +08:00
|
|
|
llm_config=SystemAgentLLMConfig(),
|
|
|
|
|
)
|
2026-04-07 18:43:24 +08:00
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
assert "USER_CONTEXT_JSON" not in prompt
|
|
|
|
|
assert "Runtime Context" not in prompt
|
|
|
|
|
assert "<!-- ENV_START -->" not in prompt
|
2026-04-07 18:43:24 +08:00
|
|
|
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
def test_agent_prompt_keeps_only_identity_and_domain_flow() -> None:
|
|
|
|
|
prompt = build_agent_prompt(
|
2026-04-07 18:43:24 +08:00
|
|
|
agent_type=AgentType.WORKER,
|
|
|
|
|
llm_config=SystemAgentLLMConfig(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
assert "focus_points" in prompt
|
|
|
|
|
assert "段间用\\n\\n" in prompt
|
|
|
|
|
assert "[role_playing]" in prompt
|
|
|
|
|
assert "[output_json_rules]" in prompt
|
2026-04-07 18:43:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_system_prompt_sections_are_not_duplicated() -> None:
|
|
|
|
|
prompt = build_system_prompt(
|
|
|
|
|
agent_type=AgentType.WORKER,
|
2026-04-28 17:19:47 +08:00
|
|
|
language="zh-CN",
|
2026-04-07 18:43:24 +08:00
|
|
|
llm_config=SystemAgentLLMConfig(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-15 16:45:57 +08:00
|
|
|
assert prompt.count("<!-- SAFETY_START -->") == 1
|
2026-04-07 18:43:24 +08:00
|
|
|
assert prompt.count("<!-- AGENT_START -->") == 1
|
|
|
|
|
assert prompt.count("<!-- OUTPUT_START -->") == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_system_prompt_requires_paragraph_breaks_for_answer() -> None:
|
2026-04-14 11:18:59 +08:00
|
|
|
prompt = build_agent_prompt(
|
2026-04-07 18:43:24 +08:00
|
|
|
agent_type=AgentType.WORKER,
|
|
|
|
|
llm_config=SystemAgentLLMConfig(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-14 11:18:59 +08:00
|
|
|
assert "段间用\\n\\n" in prompt
|