add last_message

This commit is contained in:
朱潮 2025-12-08 22:15:49 +08:00
parent 55651c38d0
commit ee41279569
3 changed files with 11 additions and 3 deletions

View File

@ -280,7 +280,7 @@ async def load_mcp_settings_async(project_dir: str, mcp_settings: list=None, bot
return merged_settings return merged_settings
async def load_guideline_prompt(chat_history: str, guidelines_text: str, tools: str, scenarios: str, terms: str, language: str, user_identifier: str = "") -> str: async def load_guideline_prompt(chat_history: str, last_message: str, guidelines_text: str, tools: str, scenarios: str, terms: str, language: str, user_identifier: str = "") -> str:
""" """
加载并处理guideline提示词 加载并处理guideline提示词
@ -317,6 +317,7 @@ async def load_guideline_prompt(chat_history: str, guidelines_text: str, tools:
datetime_str = format_datetime_by_language(language) if language else format_datetime_by_language('en') datetime_str = format_datetime_by_language(language) if language else format_datetime_by_language('en')
# 替换模板中的占位符 # 替换模板中的占位符
system_prompt = safe_replace(guideline_template, '{chat_history}', chat_history) system_prompt = safe_replace(guideline_template, '{chat_history}', chat_history)
system_prompt = safe_replace(system_prompt, '{last_message}', last_message)
system_prompt = safe_replace(system_prompt, '{guidelines_text}', guidelines_text) system_prompt = safe_replace(system_prompt, '{guidelines_text}', guidelines_text)
system_prompt = safe_replace(system_prompt, '{terms}', terms) system_prompt = safe_replace(system_prompt, '{terms}', terms)
system_prompt = safe_replace(system_prompt, '{tools}', tools) system_prompt = safe_replace(system_prompt, '{tools}', tools)

View File

@ -5,9 +5,10 @@
## 思考框架 ## 思考框架
### 1. 理解阶段 (Understanding) ### 1. 理解阶段 (Understanding)
- **目标分析**: 用户的核心需求是什么? - **目标分析**: 分析用户最新问题的核心需求是什么?
- **上下文总结**: 从聊天记录中提取关键信息 - **上下文总结**: 从聊天记录中提取关键信息
- **约束识别**: 识别限制条件、规则和要求 - **约束识别**: 识别限制条件、规则和要求
- **关注当前问题**: 只需要对用户最新问题进行答复
### 2. 分析阶段 (Analysis) ### 2. 分析阶段 (Analysis)
- **问题拆解**: 将复杂问题分解为可管理的小任务 - **问题拆解**: 将复杂问题分解为可管理的小任务
@ -28,6 +29,11 @@
{chat_history} {chat_history}
``` ```
## 用户最新问题 (User's Last Message)
```
{last_message}
```
## 工具列表 (Tools) ## 工具列表 (Tools)
``` ```
{tools} {tools}

View File

@ -165,7 +165,8 @@ Action: Provide concise, friendly, and personified natural responses.
""" """
if guidelines: if guidelines:
chat_history = format_messages_to_chat_history(messages) chat_history = format_messages_to_chat_history(messages)
guideline_prompt = await load_guideline_prompt(chat_history, guidelines, tools, scenarios, terms_analysis, language, user_identifier) query_text = get_user_last_message_content(messages)
guideline_prompt = await load_guideline_prompt(chat_history, query_text, guidelines, tools, scenarios, terms_analysis, language, user_identifier)
guideline_task = process_guideline( guideline_task = process_guideline(
chat_history=chat_history, chat_history=chat_history,
guideline_prompt=guideline_prompt, guideline_prompt=guideline_prompt,