feat(flows): 助手出站媒体写入会话历史(issue #1 验收标准 8)
智能体发的附件此前只下发不落库:下一轮模型不知道上一轮发过什么,用户说 「再发大点」时没有可回指的对象。新增 describe_outbound() 把出站分片整理成 一行引用说明(类型/大小/MIME/时长/本地路径),与入站 prepare_inbound 的 summary 格式对齐,只存引用不存字节。 两条处理链都改走 _persist_reply(): - 同步链:原先只在 reply 非空时落库,纯媒体回复会让这一轮完全消失 - 流式链:原先同样只写正文 历史写入保持在发送之前——发送失败不该让下一轮失去上下文,因此不回滚, 且刻意不写「已发送」。 tests: test_builtin 3 条(附件入库、纯媒体入库、发送失败仍入库), test_stream 补断流式分支的落库断言。变异验证:把两处调用点改回旧写法, 对应断言分别变红。
This commit is contained in:
1 parent
13b8d7a466
commit
d0e187f74d
4 files changed
+186
-21
No files matched your search
+11
-3
@@ -315,7 +315,9 @@ def test_agent_reply_sends_media_after_stream_finishes(
|
||||
|
||||
monkeypatch.setattr(builtin, "stream_task", fake_stream)
|
||||
|
||||
async def _run() -> tuple[list[tuple[str, bool]], list[list], list[RunStatus]]:
|
||||
async def _run() -> tuple[
|
||||
list[tuple[str, bool]], list[list], list[RunStatus], list
|
||||
]:
|
||||
bus = EventBus()
|
||||
bus.bind_loop()
|
||||
hub = RpcHub(bus)
|
||||
@@ -354,13 +356,19 @@ def test_agent_reply_sends_media_after_stream_finishes(
|
||||
await runner.stop()
|
||||
hub.close()
|
||||
await manager.stop()
|
||||
return channel.frames, channel.contents, statuses
|
||||
rows = await repo.list_messages(tmp_path / "bot.db", session_id="s1:u1")
|
||||
return channel.frames, channel.contents, statuses, rows
|
||||
|
||||
frames, contents, statuses = asyncio.run(_run())
|
||||
frames, contents, statuses, rows = asyncio.run(_run())
|
||||
assert frames[-1] == ("图来了", True) # 文本仍然走流式收尾
|
||||
assert statuses == [RunStatus.SUCCEEDED]
|
||||
assert len(contents) == 1 # 媒体单独一条,且只含媒体分片
|
||||
assert [type(part) for part in contents[0]] == [ImageContent]
|
||||
# 流式分支同样要落库附件:它和同步分支共用 _persist_reply,走的是另一处调用点
|
||||
assert rows[-1]["role"] == "assistant"
|
||||
assert rows[-1]["content"].startswith("图来了")
|
||||
assert "[附件] 图片" in rows[-1]["content"]
|
||||
assert str(picture) in rows[-1]["content"]
|
||||
|
||||
|
||||
def test_outbound_stream_payload_defaults() -> None:
|
||||
|
||||
Reference in new issue
Block a user