feat:将action记录置入planner,有效减少重复调用action问题

This commit is contained in:
SengokuCola
2025-07-11 01:24:44 +08:00
parent 6bfc8b2d8c
commit f144883826
4 changed files with 147 additions and 38 deletions

View File

@@ -11,7 +11,7 @@ from json_repair import repair_json
from src.chat.utils.utils import get_chat_type_and_target_info
from datetime import datetime
from src.chat.message_receive.chat_stream import get_chat_manager
from src.chat.utils.chat_message_builder import build_readable_messages, get_raw_msg_before_timestamp_with_chat
from src.chat.utils.chat_message_builder import build_readable_actions, build_readable_messages, get_actions_by_timestamp_with_chat, get_raw_msg_before_timestamp_with_chat
import time
logger = get_logger("planner")
@@ -27,6 +27,9 @@ def init_prompt():
你现在需要根据聊天内容选择的合适的action来参与聊天。
{chat_context_description},以下是具体的聊天内容:
{chat_content_block}
你刚刚进行过的action是
{actions_before_now_block}
{moderation_prompt}
现在请你根据{by_what}选择合适的action:
@@ -221,6 +224,16 @@ class ActionPlanner:
truncate=True,
show_actions=True,
)
actions_before_now = get_actions_by_timestamp_with_chat(
chat_id=self.chat_id,
timestamp_end=time.time(),
limit=5,
)
actions_before_now_block = build_readable_actions(
actions=actions_before_now,
)
self.last_obs_time_mark = time.time()
@@ -285,6 +298,7 @@ class ActionPlanner:
by_what=by_what,
chat_context_description=chat_context_description,
chat_content_block=chat_content_block,
actions_before_now_block=actions_before_now_block,
no_action_block=no_action_block,
action_options_text=action_options_block,
moderation_prompt=moderation_prompt_block,