Skip to content

A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物

feat(i18n): inject language instruction into LLM system prompts

ghostubborn8f6110df0fa0
diff --git a/backend/app/services/ontology_generator.py b/backend/app/services/ontology_generator.py
index 2d3e39bd..2d0b2304 100644
--- a/backend/app/services/ontology_generator.py
+++ b/backend/app/services/ontology_generator.py
@@ -6,6 +6,7 @@
import json
from typing import Dict, Any, List, Optional
from ..utils.llm_client import LLMClient
+from ..utils.locale import get_language_instruction
# 本体生成的系统提示词
@@ -188,8 +189,9 @@ class OntologyGenerator:
additional_context
)
+ system_prompt = f"{ONTOLOGY_SYSTEM_PROMPT}\n\n{get_language_instruction()}"
messages = [
- {"role": "system", "content": ONTOLOGY_SYSTEM_PROMPT},
+ {"role": "system", "content": system_prompt},
{"role": "user", "content": user_message}
]
diff --git a/backend/app/services/report_agent.py b/backend/app/services/report_agent.py
index 02ca5bdc..7a4c8b34 100644
--- a/backend/app/services/report_agent.py
+++ b/backend/app/services/report_agent.py
@@ -21,6 +21,7 @@ from enum import Enum
from ..config import Config
from ..utils.llm_client import LLMClient
from ..utils.logger import get_logger
+from ..utils.locale import get_language_instruction
from .zep_tools import (
ZepToolsService,
SearchResult,
@@ -1162,7 +1163,7 @@ class ReportAgent:
if progress_callback:
progress_callback("planning", 30, "正在生成报告大纲...")
- system_prompt = PLAN_SYSTEM_PROMPT
+ system_prompt = f"{PLAN_SYSTEM_PROMPT}\n\n{get_language_instruction()}"
user_prompt = PLAN_USER_PROMPT_TEMPLATE.format(
simulation_requirement=self.simulation_requirement,
total_nodes=context.get('graph_statistics', {}).get('total_nodes', 0),
@@ -1258,6 +1259,7 @@ class ReportAgent:
section_title=section.title,
tools_description=self._get_tools_description(),
)
+ system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
# 构建用户prompt - 每个已完成章节各传入最大4000字
if previous_sections:
@@ -1805,6 +1807,7 @@ class ReportAgent:
report_content=report_content if report_content else "(暂无报告)",
tools_description=self._get_tools_description(),
)
+ system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
# 构建消息
messages = [{"role": "system", "content": system_prompt}]
diff --git a/backend/app/services/simulation_config_generator.py b/backend/app/services/simulation_config_generator.py
index cc362508..328369de 100644
--- a/backend/app/services/simulation_config_generator.py
+++ b/backend/app/services/simulation_config_generator.py
@@ -20,6 +20,7 @@ from openai import OpenAI
from ..config import Config
from ..utils.logger import get_logger
+from ..utils.locale import get_language_instruction
from .zep_entity_reader import EntityNode, ZepEntityReader
logger = get_logger('mirofish.simulation_config')
@@ -585,7 +586,8 @@ class SimulationConfigGenerator:
- reasoning (string): 简要说明为什么这样配置"""
system_prompt = "你是社交媒体模拟专家。返回纯JSON格式,时间配置需符合中国人作息习惯。"
-
+ system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
+
try:
return self._call_llm_with_retry(prompt, system_prompt)
except Exception as e:
@@ -701,7 +703,8 @@ class SimulationConfigGenerator:
}}"""
system_prompt = "你是舆论分析专家。返回纯JSON格式。注意 poster_type 必须精确匹配可用实体类型。"
-
+ system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
+
try:
return self._call_llm_with_retry(prompt, system_prompt)
except Exception as e:
@@ -864,7 +867,8 @@ class SimulationConfigGenerator:
}}"""
system_prompt = "你是社交媒体行为分析专家。返回纯JSON,配置需符合中国人作息习惯。"
-
+ system_prompt = f"{system_prompt}\n\n{get_language_instruction()}"
+
try:
result = self._call_llm_with_retry(prompt, system_prompt)
llm_configs = {cfg["agent_id"]: cfg for cfg in result.get("agent_configs", [])}