perf: reduce LLM input tokens by ~50% via prompt deduplication
- Remove JSON appendix from user_prompt (saves ~3000 chars, 85% reduction) - Consolidate identity: remove English system_prompt identity, merge into agent_prompt Chinese identity - Simplify system_prompt output rules: keep only Language Requirement, remove Answer Rules (duplicate with agent_prompt) - Enhance follow-up context: include more divination_derived fields (changing_yaos, fushen, wu_xing, etc.) - Fix bug: lowerName -> lower_name in user_prompt (Pydantic snake_case) - Update tests to reflect new prompt structure
This commit is contained in:
@@ -34,7 +34,7 @@ def test_system_prompt_enforces_ai_language_and_identity_signals() -> None:
|
||||
now_utc=datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
assert "ai_language=en-US" in prompt
|
||||
assert '"ai_language":"en-US"' in prompt
|
||||
assert (
|
||||
"interface_language and country are weak signals for user identity inference"
|
||||
in prompt
|
||||
@@ -65,8 +65,7 @@ def test_agent_prompt_keeps_only_identity_and_domain_flow() -> None:
|
||||
|
||||
assert "[输出约束]" not in prompt
|
||||
assert "[安全与拒答]" not in prompt
|
||||
assert "[六爻分析流程]" in prompt
|
||||
assert "匹配 ai_language" in prompt
|
||||
assert "[procedure]" in prompt
|
||||
assert "段间用\\n\\n" in prompt
|
||||
assert "优先四字表达,简洁且可复述" not in prompt
|
||||
|
||||
@@ -94,7 +93,7 @@ def test_system_prompt_sanitizes_invalid_language_and_country() -> None:
|
||||
now_utc=datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
assert "ai_language=zh-CN" in prompt
|
||||
assert '"ai_language":"zh-CN"' in prompt
|
||||
assert '"interface_language":"zh-CN"' in prompt
|
||||
assert '"country":"CN"' in prompt
|
||||
|
||||
@@ -113,11 +112,9 @@ def test_system_prompt_sections_are_not_duplicated() -> None:
|
||||
|
||||
|
||||
def test_system_prompt_requires_paragraph_breaks_for_answer() -> None:
|
||||
prompt = build_system_prompt(
|
||||
prompt = build_agent_prompt(
|
||||
agent_type=AgentType.WORKER,
|
||||
llm_config=SystemAgentLLMConfig(),
|
||||
user_context=_build_user_context(ai_language="zh-CN"),
|
||||
now_utc=datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
assert "multiple short paragraphs" in prompt
|
||||
assert "段间用\\n\\n" in prompt
|
||||
|
||||
Reference in New Issue
Block a user