feat(file-check): 持久化 chat_tool_runs 并统一 agent_runtime_context 注入

新增跨 worker 进度绑定表与显式 hxops_turn_id 链路;Dify Start 仅注入
agent_runtime_context,task_id/turn_id 写入 refs 供画布解析后回传 Tool。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-07-09 18:39:05 +08:00
1 parent c778f40fbc
commit f4e74f7b07
23 files changed
+1580 -196

No files matched your search

+50 -4
View File
@@ -19,7 +19,6 @@ from app.services.agent_runtime_context import AGENT_RUNTIME_CONTEXT_INPUT
from app.services.agent_runtime_context.bootstrap import load_context_adapters
from app.services.agent_runtime_context.registry import build_chat_dify_inputs
from app.services.chat.executors import stream_chat_via_executor
from app.services.file_check_tools.dify_inputs import FILE_CHECK_TASK_ID_INPUT
@pytest.fixture(autouse=True)
@@ -142,7 +141,7 @@ def test_hybrid_executor_injects_shipping_agent_runtime_context(app, monkeypatch
def test_file_check_adapter_outputs_task_id_and_runtime_context(app):
"""file_check Agent 应同时输出 task_id 与 agent_runtime_context(迭代 5)。"""
"""file_check Agent 仅输出 agent_runtime_context;task_id / turn_id 在 refs 内。"""
agent = _agent(
agent_code='file_check',
runtime_provider='dify',
@@ -156,11 +155,58 @@ def test_file_check_adapter_outputs_task_id_and_runtime_context(app):
agent,
session_id='conv-file-check-start-001',
request_id='req-file-check-001',
hxops_turn_id='turn-file-check-start-001',
)
assert inputs[FILE_CHECK_TASK_ID_INPUT] == '42'
assert AGENT_RUNTIME_CONTEXT_INPUT in inputs
assert set(inputs.keys()) == {AGENT_RUNTIME_CONTEXT_INPUT}
payload = json.loads(inputs[AGENT_RUNTIME_CONTEXT_INPUT])
assert payload['agent_code'] == 'file_check'
assert payload['refs']['schedule_task_id'] == '42'
assert payload['refs']['hxops_turn_id'] == 'turn-file-check-start-001'
assert payload['domain']['state_hint']['schedule_task_id'] == '42'
assert payload['domain']['state_hint']['hxops_turn_id'] == 'turn-file-check-start-001'
def test_file_check_executor_injects_turn_id_via_handler(app, monkeypatch):
"""file_check Handler.prepare_stream 生成 turn 后,Executor 应向 Dify 注入 hxops_turn_id。"""
from app.services.agent_registry.handlers.bootstrap import load_handlers
captured: dict = {}
def fake_stream_chat(*args, **kwargs):
captured['inputs'] = kwargs.get('inputs')
captured['hxops_turn_id'] = kwargs.get('hxops_turn_id')
yield 'data: {"event":"message_end"}\n\n'
monkeypatch.setattr(
'app.services.chat.executors.dify_chat.DifyService.stream_chat',
staticmethod(fake_stream_chat),
)
with app.app_context():
load_handlers()
ctx = ChatStreamContext(
query='立即执行检核',
display_query='立即执行检核',
user=SimpleNamespace(id=1),
agent=_agent(
agent_code='file_check',
runtime_provider='dify',
conversation_mode='task_chat',
name='RoHS 检核 Agent',
bound_schedule_task_id=42,
capabilities={'task_progress': True},
),
session=SimpleNamespace(session_id='conv-file-check-exec-001'),
external_conversation_id=None,
request_id='req-file-check-exec-001',
)
from app.services.chat.executors import stream_chat_via_executor
list(stream_chat_via_executor(ctx))
assert captured.get('hxops_turn_id')
inputs = captured.get('inputs') or {}
assert set(inputs.keys()) == {AGENT_RUNTIME_CONTEXT_INPUT}
runtime_context = json.loads(inputs[AGENT_RUNTIME_CONTEXT_INPUT])
assert runtime_context['refs']['hxops_turn_id'] == captured['hxops_turn_id']