feat:统一节点进度事件
This commit is contained in:
+35
-6
@@ -19,10 +19,20 @@ class AgentService:
|
||||
async def run(self, request: DesignRequest) -> AgentResult:
|
||||
# 新请求始终独立建任务,不用 conversation_id 充当检查点 ID
|
||||
thread_id = str(uuid4())
|
||||
# 暂无会话创建接口,未传会话 ID 时先分配标识,不创建数据库记录
|
||||
conversation_id = request.context.conversation_id or str(uuid4())
|
||||
payload = request.model_dump(mode="json")
|
||||
payload["context"]["conversation_id"] = conversation_id
|
||||
|
||||
return await self._invoke(
|
||||
thread_id,
|
||||
{"request": request.model_dump(mode="json")},
|
||||
request.context.conversation_id,
|
||||
{
|
||||
"request": payload,
|
||||
"conversation_id": conversation_id,
|
||||
"thread_id": thread_id,
|
||||
"message_id": str(uuid4()),
|
||||
},
|
||||
conversation_id,
|
||||
)
|
||||
|
||||
async def resume(self, request: ResumeRequest) -> AgentResult:
|
||||
@@ -46,11 +56,28 @@ class AgentService:
|
||||
and reply.option_id not in {item.id for item in clarification.options}
|
||||
):
|
||||
raise BizException(422, "请选择当前问题的有效选项")
|
||||
session_id = (
|
||||
snapshot.values["request"].get("context", {}).get("conversation_id")
|
||||
)
|
||||
|
||||
conversation_id = snapshot.values["conversation_id"]
|
||||
# 恢复同一任务不能切换会话,补充编辑上下文时也保留原会话标识
|
||||
if reply.context is not None:
|
||||
if reply.context.conversation_id not in (None, conversation_id):
|
||||
raise BizException(422, "恢复任务时不能切换会话")
|
||||
reply = reply.model_copy(
|
||||
update={
|
||||
"context": reply.context.model_copy(
|
||||
update={"conversation_id": conversation_id}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
# 每次有效补充或取消生成新的输入 ID,任务和会话保持不变
|
||||
return await self._execute(
|
||||
thread_id, Command(resume=reply.model_dump(mode="json")), session_id
|
||||
thread_id,
|
||||
Command(
|
||||
resume=reply.model_dump(mode="json"),
|
||||
update={"message_id": str(uuid4())},
|
||||
),
|
||||
conversation_id,
|
||||
)
|
||||
finally:
|
||||
self._active.discard(thread_id)
|
||||
@@ -91,7 +118,9 @@ class AgentService:
|
||||
|
||||
# 只交付校验通过的完整动作批次,失败草稿留在后端
|
||||
return AgentResult(
|
||||
conversation_id=state["conversation_id"],
|
||||
thread_id=thread_id,
|
||||
message_id=state["message_id"],
|
||||
status="waiting_for_input" if waiting else state["status"],
|
||||
actions=state.get("actions") or []
|
||||
if state.get("validation_passed") is True and state["status"] == "completed"
|
||||
|
||||
Reference in New Issue
Block a user