Commit 6eac2c29 by sunqi02 Committed by 胡悦

fix: preserve original text content in _handle_actionable when rewritten_query loses it

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent cce7bb5f
...@@ -481,7 +481,15 @@ class MessageGate: ...@@ -481,7 +481,15 @@ class MessageGate:
bot_id_mapping: Dict[str, str], bot_id_mapping: Dict[str, str],
) -> None: ) -> None:
"""actionable 分支:分发到 AgentHub。""" """actionable 分支:分发到 AgentHub。"""
query = decision.rewritten_query or "" rewritten = decision.rewritten_query or ""
original = self._merge_text_from_pending(pending)
if rewritten and original and original not in rewritten:
query = f"{rewritten}\n\n---\n{original}"
elif rewritten:
query = rewritten
else:
query = original
if not query: if not query:
logger.warning("[MessageGate] session=%s actionable 但无 query,跳过", session_id) logger.warning("[MessageGate] session=%s actionable 但无 query,跳过", session_id)
return return
......
...@@ -423,4 +423,81 @@ class TestMergeTextFromPending: ...@@ -423,4 +423,81 @@ class TestMergeTextFromPending:
{"msg_type": "text", "msg_content": "有效内容"}, {"msg_type": "text", "msg_content": "有效内容"},
] ]
result = MessageGate._merge_text_from_pending(pending) result = MessageGate._merge_text_from_pending(pending)
assert result == "有效内容"
\ No newline at end of file \ No newline at end of file
assert result == "有效内容"
class TestHandleActionableContentPreservation:
"""测试 _handle_actionable 的原文合并逻辑。"""
@pytest.mark.asyncio
async def test_handle_actionable_preserves_original_text(self, message_gate_with_deps):
"""rewritten_query 使用指代时,原文应被合并到 query 中。"""
gate = message_gate_with_deps
pending = [
{"msg_type": "text", "msg_content": "130行的转写文本内容..."},
]
decision = GateDecision(
intent="actionable",
rewritten_query="请将上面提供的对话记录整理成会议纪要",
)
await gate._handle_actionable(
session_id="sess_test",
room_id="room1",
user_id="u1",
decision=decision,
pending=pending,
bot_id_mapping={"agent_meeting": "bot_123"},
)
call_args = gate.agent_hub.process_message.call_args
query = call_args.kwargs["user_query"]
assert "请将上面提供的对话记录整理成会议纪要" in query
assert "130行的转写文本内容..." in query
@pytest.mark.asyncio
async def test_handle_actionable_no_duplicate_when_rewritten_contains_original(self, message_gate_with_deps):
"""rewritten_query 已包含原文时,不重复拼接。"""
gate = message_gate_with_deps
pending = [
{"msg_type": "text", "msg_content": "你好"},
]
decision = GateDecision(
intent="actionable",
rewritten_query="你好,请帮我查一下天气",
)
await gate._handle_actionable(
session_id="sess_test",
room_id="room1",
user_id="u1",
decision=decision,
pending=pending,
bot_id_mapping={},
)
call_args = gate.agent_hub.process_message.call_args
query = call_args.kwargs["user_query"]
assert query.count("你好") == 1
@pytest.mark.asyncio
async def test_handle_actionable_empty_rewritten_uses_original(self, message_gate_with_deps):
"""rewritten_query 为空时,用原文兜底。"""
gate = message_gate_with_deps
pending = [
{"msg_type": "text", "msg_content": "请总结这个录音"},
]
decision = GateDecision(intent="actionable", rewritten_query="")
await gate._handle_actionable(
session_id="sess_test",
room_id="room1",
user_id="u1",
decision=decision,
pending=pending,
bot_id_mapping={},
)
call_args = gate.agent_hub.process_message.call_args
query = call_args.kwargs["user_query"]
assert query == "请总结这个录音"
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!