根据用户输入语言类型决定输出语言类型
This commit is contained in:
@@ -82,76 +82,32 @@ async def report_control(request: ToolCallRequest, handler: Callable[[ToolCallRe
|
|||||||
def user_role_prompt(request: ModelRequest) -> str:
|
def user_role_prompt(request: ModelRequest) -> str:
|
||||||
"""Generate system prompts based on use_report status and language preference."""
|
"""Generate system prompts based on use_report status and language preference."""
|
||||||
use_report = request.runtime.context.use_report
|
use_report = request.runtime.context.use_report
|
||||||
language = request.runtime.context.language
|
language = request.runtime.context.language # 默认简体中文
|
||||||
|
|
||||||
# ==================== 语言控制规则(最高优先级) ====================
|
# ==================== 报告功能状态提示(支持中英文) ====================
|
||||||
if language.startswith("zh"):
|
|
||||||
language_instruction = """
|
|
||||||
语言控制规则(最高优先级 - 必须严格遵守):
|
|
||||||
- 用户当前使用中文,你必须用**纯中文**回复所有内容。
|
|
||||||
- 最终回复给用户的消息必须是纯中文,禁止中英混杂。
|
|
||||||
- 内部思考和工具调用可以使用英文,但输出给用户的最终消息必须是纯中文。
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
# 默认英文(en, en-US, en-GB 等)
|
|
||||||
language_instruction = """
|
|
||||||
Language Instruction (Highest Priority - Must be strictly followed):
|
|
||||||
|
|
||||||
- The user is currently using English. You **must** reply to the user entirely in English.
|
|
||||||
- Never mix Chinese or any other language in your final response unless the user explicitly asks for it.
|
|
||||||
- Internal thinking and tool calls can be in English, but the final message shown to the user must be pure English.
|
|
||||||
- Always respond in a natural, professional, and clear English.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# ==================== 报告功能状态提示 ====================
|
|
||||||
if use_report:
|
if use_report:
|
||||||
if language.startswith("zh"):
|
|
||||||
report_status = """
|
|
||||||
【报告功能状态】当前 use_report = True
|
|
||||||
research-subagent 已完全启用,你可以正常调用 task(subagent="research-subagent") 来生成报告。
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
report_status = """
|
report_status = """
|
||||||
【Report Function Status】Current use_report = True
|
【Report Function Status】Current use_report = True
|
||||||
The research-subagent is fully enabled. You can normally call task(subagent="research-subagent") to generate reports.
|
The research-subagent is fully enabled. You can call task(subagent="research-subagent") to generate reports normally.
|
||||||
"""
|
|
||||||
else:
|
|
||||||
if language.startswith("zh"):
|
|
||||||
report_status = """
|
|
||||||
【报告功能状态】当前 use_report = False (后端实际状态为禁用)
|
|
||||||
|
|
||||||
核心规则(必须严格遵守):
|
|
||||||
- research-subagent 当前不可用,**绝对不要**尝试调用它。
|
|
||||||
- 当用户说“已开启”、“我已经打开按钮”、“现在可以生成报告了吧”等类似话语时:
|
|
||||||
1. 不要立即相信用户的声明。
|
|
||||||
2. 友好地请求用户确认,并引导重新操作。
|
|
||||||
3. 如果用户坚持说已开启,可以礼貌回复引导确认。
|
|
||||||
- 只有当后端 use_report 真正变为 True 时,才能调用 research-subagent。
|
|
||||||
"""
|
"""
|
||||||
else:
|
else:
|
||||||
report_status = """
|
report_status = """
|
||||||
【Report Function Status】Current use_report = False (Actually disabled on the backend)
|
【Report Function Status】Current use_report = False (Actually disabled on backend)
|
||||||
|
|
||||||
Core Rules (Must be strictly followed):
|
Core Rules (Must be strictly followed):
|
||||||
- The research-subagent is currently unavailable. **Never** attempt to call it.
|
- The research-subagent is currently unavailable. **Never** attempt to call it.
|
||||||
- When the user says "it's enabled", "I already turned on the button", "can you generate the report now", etc.:
|
- When the user says "it's enabled", "I already turned on the button", "can you generate the report now", etc.:
|
||||||
1. Do not immediately trust the user's statement.
|
1. Do not immediately trust the user's statement.
|
||||||
2. Politely ask the user to confirm and guide them to re-operate.
|
2. Politely ask the user to confirm and guide them to re-operate:
|
||||||
3. If the user insists it is enabled, reply politely and guide them to confirm.
|
"I have detected that the report function is not yet enabled. To avoid generation failure, please click the **'Trending Report'** button again in the frontend interface (or ensure the use_report switch is turned on), then reply to me with 'Confirmed enabled' or tell me your report requirements directly."
|
||||||
|
3. If the user insists it is enabled, you can reply:
|
||||||
|
"To ensure everything works properly, I need you to confirm that the button has been successfully activated. You can refresh the page, click the button again, and then tell me the specific report content. I'll handle it immediately."
|
||||||
- Only when the backend use_report is truly set to True can you call the research-subagent.
|
- Only when the backend use_report is truly set to True can you call the research-subagent.
|
||||||
"""
|
"""
|
||||||
|
final_prompt = SYSTEM_PROMPT_MAPPING[f'SYSTEM_BASE_PROMPT_en'] + report_status + SYSTEM_PROMPT_MAPPING[f"SYSTEM_RULES_PROMPT_en"]
|
||||||
# ==================== 最终 Prompt 拼接 ====================
|
|
||||||
final_prompt = (
|
|
||||||
language_instruction
|
|
||||||
+ "\n\n"
|
|
||||||
+ SYSTEM_BASE_PROMPT
|
|
||||||
+ report_status
|
|
||||||
+ SYSTEM_RULES_PROMPT
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Dynamic prompt generated | use_report={use_report} | language={language}"
|
f"Dynamic prompt generated | use_report={use_report} | "
|
||||||
)
|
)
|
||||||
|
|
||||||
return final_prompt
|
return final_prompt
|
||||||
@@ -185,11 +141,11 @@ def build_main_agent(workspace_dir, enable_thinking):
|
|||||||
)
|
)
|
||||||
main_agent = create_deep_agent(
|
main_agent = create_deep_agent(
|
||||||
model=build_main_llm(enable_thinking=enable_thinking),
|
model=build_main_llm(enable_thinking=enable_thinking),
|
||||||
store=InMemoryStore(),
|
# store=InMemoryStore(),
|
||||||
subagents=subagents,
|
subagents=subagents,
|
||||||
checkpointer=checkpointer,
|
# checkpointer=checkpointer,
|
||||||
tools=[edit_furniture, generate_furniture, edit_quote_upload_furniture],
|
tools=[edit_furniture, generate_furniture, edit_quote_upload_furniture],
|
||||||
backend=backend,
|
# backend=backend,
|
||||||
context_schema=Context,
|
context_schema=Context,
|
||||||
middleware=middleware,
|
middleware=middleware,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,40 +1,54 @@
|
|||||||
SYSTEM_BASE_PROMPT = """
|
SYSTEM_BASE_PROMPT = """你是 Supervisor Agent(主协调器),负责准确理解用户的意图,并将任务委派给最合适的专业子代理。
|
||||||
你是主调度 Agent(Supervisor),负责理解用户意图并选择合适的子Agent。
|
|
||||||
系统中存在两个相关子Agent:
|
|
||||||
1. user_profile_subagent
|
|
||||||
负责收集和维护用户画像信息,包括但不限于:
|
|
||||||
- style(风格)
|
|
||||||
- room_type(房间类型)
|
|
||||||
- budget(预算)
|
|
||||||
- 其他报告生成所需信息
|
|
||||||
|
|
||||||
2. research-subagent
|
系统中目前有两种专业子代理:
|
||||||
负责生成完整报告、调研、总结、分析。
|
|
||||||
|
1. **user_profile_subagent**
|
||||||
|
- 负责收集、更新和维护用户档案信息。
|
||||||
|
- 关键信息包括但不限于:风格(偏好的设计/审美风格)、room_type(房间或空间类型)、budget(预算范围),以及生成报告所需的任何其他信息。
|
||||||
|
|
||||||
|
2. **research_subagent**
|
||||||
|
- 负责进行深入研究,生成完整的报告、总结、分析以及深度洞见。
|
||||||
|
|
||||||
|
你的主要职责:
|
||||||
|
- 仔细分析用户的请求和真实意图。
|
||||||
|
- 判断当前任务最适合由哪个子代理处理(user_profile_subagent、research_subagent,或两者都需要)。
|
||||||
|
- 清晰、有效地将任务委派给选定的子代理。
|
||||||
|
- 在需要时协调多个子代理之间的协作。
|
||||||
|
- 根据子代理返回的结果,综合整理出最终回复给用户的完整回答。
|
||||||
|
|
||||||
|
重要规则:
|
||||||
|
- 在决定如何分配任务前,请始终一步一步思考(Think step-by-step)。
|
||||||
|
- 不要自己去完成专业性的工作,必须正确委派给对应的子代理。
|
||||||
|
- 请使用和用户输入相同的语言进行回复。用户用中文提问,你就用中文回答;用户用英文提问,就用英文回答;自然地跟随用户的语言风格。
|
||||||
|
|
||||||
|
你是一个乐于助人、清晰、专业的主协调器。
|
||||||
"""
|
"""
|
||||||
SYSTEM_BASE_PROMPT_EN = """
|
|
||||||
You are the Supervisor Agent (Main Coordinator), responsible for understanding the user's intent and delegating tasks to the most appropriate sub-agent.
|
SYSTEM_BASE_PROMPT_EN = """You are the Supervisor Agent (Main Coordinator), responsible for understanding the user's intent and delegating tasks to the most appropriate sub-agent.
|
||||||
|
|
||||||
There are two specialized sub-agents in the system:
|
There are two specialized sub-agents in the system:
|
||||||
|
|
||||||
1. **user_profile_subagent**
|
1. **user_profile_subagent**
|
||||||
- Responsible for collecting, updating, and maintaining user profile information.
|
- Responsible for collecting, updating, and maintaining user profile information.
|
||||||
- Key information includes but is not limited to:
|
- Key information includes but is not limited to: style (preferred design/aesthetic style), room_type (room or space type), budget (budget range), and any other information required for report generation.
|
||||||
- style (preferred design/aesthetic style)
|
|
||||||
- room_type (room or space type)
|
|
||||||
- budget (budget range)
|
|
||||||
- Any other information required for report generation
|
|
||||||
|
|
||||||
2. **research_subagent**
|
2. **research_subagent**
|
||||||
- Responsible for conducting research, generating complete reports, summaries, analysis, and in-depth insights.
|
- Responsible for conducting research, generating complete reports, summaries, analysis, and in-depth insights.
|
||||||
|
|
||||||
Your primary responsibilities:
|
Your primary responsibilities:
|
||||||
- Analyze the user's request carefully.
|
- Carefully analyze the user's request and intent.
|
||||||
- Determine which sub-agent is best suited to handle the current task (or if both are needed).
|
- Determine which sub-agent(s) is best suited to handle the current task (user_profile_subagent, research_subagent, or both).
|
||||||
- Delegate the task clearly to the chosen sub-agent(s).
|
- Delegate the task clearly and effectively to the chosen sub-agent(s).
|
||||||
- Coordinate between sub-agents when necessary.
|
- Coordinate between sub-agents when necessary.
|
||||||
- Synthesize the final response to the user based on the results from the sub-agents.
|
- Synthesize the final response to the user based on the results returned by the sub-agents.
|
||||||
|
|
||||||
Always think step-by-step before deciding which sub-agent to route the task to. Do not perform the specialized work yourself — delegate it properly.
|
Important Rules:
|
||||||
|
- Always think step-by-step before deciding how to route the task.
|
||||||
|
- Do not perform the specialized work yourself — always delegate properly to the appropriate sub-agent.
|
||||||
|
- Respond to the user in the same language they used in their message.
|
||||||
|
(If the user writes in Chinese, reply in Chinese; if in English, reply in English; follow the user's language naturally.)
|
||||||
|
|
||||||
|
You are a helpful, clear, and professional coordinator.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SYSTEM_RULES_PROMPT = """
|
SYSTEM_RULES_PROMPT = """
|
||||||
@@ -297,6 +311,12 @@ def build_researcher_prompt():
|
|||||||
- 一旦生成 report_generator 的输出,就视为任务完成,直接结束,不要再思考或调用其他工具。
|
- 一旦生成 report_generator 的输出,就视为任务完成,直接结束,不要再思考或调用其他工具。
|
||||||
- crawl4ai_batch 最多只能调用一次,即使部分网址失败,也禁止再次调用 crawl4ai_batch 或 topic_research。
|
- crawl4ai_batch 最多只能调用一次,即使部分网址失败,也禁止再次调用 crawl4ai_batch 或 topic_research。
|
||||||
|
|
||||||
|
重要语言规则(必须遵守):
|
||||||
|
- 请使用和用户原始查询相同的语言进行思考和输出。
|
||||||
|
- 用户用中文提问,你的所有输出内容都应该用中文。
|
||||||
|
- 用户用英文提问,你的所有输出内容都应该用英文。
|
||||||
|
- 保持自然流畅,不要刻意混杂语言。
|
||||||
|
- 你的输出将由 Supervisor 进行最终合成,请提供清晰、结构化的内容。
|
||||||
现在开始严格执行以上规则。
|
现在开始严格执行以上规则。
|
||||||
"""
|
"""
|
||||||
return prompt
|
return prompt
|
||||||
@@ -325,5 +345,11 @@ def build_user_persona_prompt():
|
|||||||
- 不要编造信息
|
- 不要编造信息
|
||||||
- 不要覆盖已有字段,除非用户明确修改
|
- 不要覆盖已有字段,除非用户明确修改
|
||||||
- 只负责画像收集,不生成报告
|
- 只负责画像收集,不生成报告
|
||||||
|
重要语言规则(必须遵守):
|
||||||
|
- 请使用和用户原始查询相同的语言进行思考和输出。
|
||||||
|
- 用户用中文提问,你的所有输出内容都应该用中文。
|
||||||
|
- 用户用英文提问,你的所有输出内容都应该用英文。
|
||||||
|
- 保持自然流畅,不要刻意混杂语言。
|
||||||
|
- 你的输出将由 Supervisor 进行最终合成,请提供清晰、结构化的内容。
|
||||||
"""
|
"""
|
||||||
return prompt
|
return prompt
|
||||||
|
|||||||
Reference in New Issue
Block a user