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 "" in prompt assert "" 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 "" 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 "" 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("") == 1 assert prompt.count("") == 1 assert prompt.count("") == 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