Commit 573558da by sunqi02 Committed by 胡悦

fix:修复sub agent 重复写会内存消息的问题,在多伦任务的时候。

1 parent f23adaf9
......@@ -180,8 +180,7 @@ async def _bg_finalize_sub_agent(
room_id=agent_code,
channel="sub_agent",
)
sub_memory_msgs = await sub_agent.memory.get_memory()
from app.agent_core.memory import SessionMemory
sub_memory_msgs = await sub_agent.memory.get_memory(exclude_mark="history")
sub_session_memory = SessionMemory(
session_id=sub_session_id,
store=hub.session_service.store,
......@@ -648,8 +647,7 @@ class AgentHub:
agent_memory = InMemoryMemory()
history_msgs = [Msg.from_dict(m) for m in messages if "name" in m]
if history_msgs:
await agent_memory.add(history_msgs)
history_msg_count = len(history_msgs) # 用于后续只保存本次 ReAct 新增的工具消息
await agent_memory.add(history_msgs, marks=["history"])
# Create per-request ReActAgent with per-agent toolkit
agent = ReActAgent(
......@@ -689,10 +687,9 @@ class AgentHub:
response_text = response_msg.get_text_content() or "" # 纯文本,用于返回值和日志
target_agent_name = target_agent
# 1. 保存工具交互(只保存本次 ReAct 新增的,避免历史工具消息重复追加)
# 1. 保存工具交互(只保存本次 ReAct 新增的,排除 history 标记)
try:
msg_list = await agent.memory.get_memory()
new_msgs = msg_list[history_msg_count:]
new_msgs = await agent.memory.get_memory(exclude_mark="history")
self._save_tool_interactions(memory, new_msgs)
except Exception:
logger.warning(
......@@ -823,7 +820,7 @@ class AgentHub:
sub_history = sub_session_memory.get_messages(max_rounds=10)
history_msgs = [Msg.from_dict(m) for m in sub_history if "name" in m]
if history_msgs:
await sub_memory.add(history_msgs)
await sub_memory.add(history_msgs, marks=["history"])
logger.info(
"[子Agent 开始] agent_code=%s history=%d instruction=%s",
agent_code, len(history_msgs), instruction[:80],
......
This diff could not be displayed because it is too large.
......@@ -15,7 +15,7 @@
"sender_id": "",
"sender_name": "孙奇",
"msg_type": "text",
"msg_content": "问界M8的价格和吸引客户的亮点",
"msg_content": "问界M8的延保价格和吸引客户的亮点",
"payload": {}
}
]
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!