feat(planner): 优化主动对话决策并记录动作历史

在主动对话规划器中引入最近的动作历史作为决策依据,以避免重复或不合时宜的主动行为。同时,在主动回复后,将该行为作为动作信息存储到数据库中,以便于未来的决策和分析。

- 在 `ActionPlanner` 中,获取并向prompt中添加最近5条动作历史记录
- 在 `ProactiveThinker` 中,当主动回复成功后,调用 `store_action_info` 记录动作
- 移除了 `@user` 插件中已废弃的 `planner_type` 属性
This commit is contained in:
minecraft1024a
2025-09-07 13:02:10 +08:00
parent e14bd950c3
commit dc67eb68fc
3 changed files with 21 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ from src.plugin_system.base.component_types import ComponentType
from src.config.config import global_config
from src.chat.utils.chat_message_builder import get_raw_msg_before_timestamp_with_chat, build_readable_messages_with_id
from src.mood.mood_manager import mood_manager
from src.common.database.sqlalchemy_database_api import store_action_info
if TYPE_CHECKING:
from ..cycle_processor import CycleProcessor
@@ -237,6 +238,13 @@ class ProactiveThinker:
await self.cycle_processor.response_handler.send_response(
response_set, time.time(), action_result.get("action_message")
)
await store_action_info(
chat_stream=self.context.chat_stream,
action_name="proactive_reply",
action_data={"topic": topic, "response": response_text},
action_prompt_display=f"主动发起对话: {topic}",
action_done=True,
)
else:
logger.error(f"{self.context.log_prefix} 主动思考生成回复失败。")

View File

@@ -98,6 +98,9 @@ def init_prompt():
## 最近的聊天内容
{chat_content_block}
## 最近的动作历史
{actions_before_now_block}
## 任务
基于以上所有信息(特别是最近的聊天内容),分析当前情况,决定是否适合主动开启一个**新的、但又与当前氛围相关**的话题。
@@ -678,6 +681,15 @@ class ActionPlanner:
)
prompt_template = await global_prompt_manager.get_prompt_async("proactive_planner_prompt")
actions_before_now = get_actions_by_timestamp_with_chat(
chat_id=self.chat_id,
timestamp_start=time.time() - 3600,
timestamp_end=time.time(),
limit=5,
)
actions_before_now_block = build_readable_actions(actions=actions_before_now)
actions_before_now_block = f"你刚刚选择并执行过的action是\n{actions_before_now_block}"
prompt = prompt_template.format(
time_block=time_block,
identity_block=identity_block,
@@ -685,6 +697,7 @@ class ActionPlanner:
mood_block=mood_block,
long_term_memory_block=long_term_memory_block,
chat_content_block=chat_content_block or "最近没有聊天内容。",
actions_before_now_block=actions_before_now_block,
)
return prompt, []

View File

@@ -24,7 +24,6 @@ class AtAction(BaseAction):
activation_type = ActionActivationType.LLM_JUDGE # 消息接收时激活(?)
parallel_action = False
chat_type_allow = ChatType.GROUP
planner_type = PlannerType.BIG_BRAIN
# === 功能描述(必须填写)===
action_parameters = {"user_name": "需要艾特用户的名字", "at_message": "艾特用户时要发送的消,注意消息里不要有@"}