修复通用风险问答会话历史丢失
This commit is contained in:
@@ -5,6 +5,7 @@ import pytest
|
||||
from app.core.contracts import (
|
||||
AgentDefinition,
|
||||
AgentRequest,
|
||||
ConversationTurn,
|
||||
IntentResult,
|
||||
RequestContext,
|
||||
ResolvedAgentConfig,
|
||||
@@ -341,6 +342,38 @@ async def test_autonomous_tool_loop_supports_multiple_rounds() -> None:
|
||||
assert events[-1].payload["result"]["result"]["text"].startswith("ALERT-001")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_autonomous_reply_includes_same_session_history() -> None:
|
||||
model_client = StubRiskModelClient([
|
||||
{"content": "上一轮提到的高风险预警主要涉及客户 CUST-001。"},
|
||||
])
|
||||
factory, _ = build_factory(
|
||||
{INTENT_SEARCH: (SEARCH_TOOL,)},
|
||||
[],
|
||||
model_client=model_client,
|
||||
)
|
||||
ctx = context()
|
||||
agent = factory.create("risk", ctx)
|
||||
agent._classified_intent = IntentResult(intent=INTENT_GENERAL, confidence=0.95)
|
||||
req, _ = request("他们主要涉及哪些客户?", INTENT_GENERAL)
|
||||
req = req.model_copy(update={
|
||||
"history": (
|
||||
ConversationTurn(role="user", content="当前高风险预警有哪些?"),
|
||||
ConversationTurn(role="assistant", content="当前高风险预警涉及客户 CUST-001。"),
|
||||
),
|
||||
})
|
||||
|
||||
events = [event async for event in agent.execute(req, ctx, "run-risk-history")]
|
||||
|
||||
assert events[-1].payload["result"]["result"]["text"].startswith("上一轮提到")
|
||||
messages, _ = model_client.calls[0]
|
||||
assert messages[1:3] == [
|
||||
{"role": "user", "content": "当前高风险预警有哪些?"},
|
||||
{"role": "assistant", "content": "当前高风险预警涉及客户 CUST-001。"},
|
||||
]
|
||||
assert messages[-1] == {"role": "user", "content": "他们主要涉及哪些客户?"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_protocol_marker_falls_back_without_leaking() -> None:
|
||||
model_client = StubRiskModelClient([
|
||||
|
||||
Reference in New Issue
Block a user