feat:架构重构

This commit is contained in:
2026-10-01 23:08:06 -07:00
parent b82dc93404
commit 68588d1f92
74 changed files with 1131 additions and 3492 deletions
+5 -17
View File
@@ -53,13 +53,7 @@ class AgentService:
payload = request.model_dump(mode="json")
# 历史只信任服务端记录,覆盖前端可能携带的同名扩展字段
payload["history"] = [
{
"user": turn.prompt,
"assistant": turn.summary,
"outcome": turn.outcome,
# 助手提出的待确认修改,意图节点据此判断用户是否同意
**({"offer": turn.offer} if turn.offer else {}),
}
{"user": turn.prompt, "assistant": turn.summary, "outcome": turn.outcome}
for turn in turns
]
@@ -161,9 +155,7 @@ class AgentService:
return _clip(f"处理失败:{result.answer or '未知原因'}")
if result.answer:
return _clip(result.answer)
requirement = state.get("requirement")
goal = requirement.goal if requirement is not None else "修改大屏"
return _clip(f"{goal}(已生成 {len(result.actions)} 个画布动作)")
return f"已生成 {len(result.actions)} 个画布动作"
async def _save_turn(self, state, result: AgentResult) -> None:
# 历史写入失败不影响本次结果交付,只记录日志
@@ -176,10 +168,6 @@ class AgentService:
prompt=state["request"]["prompt"],
outcome=result.status,
summary=self._summarize(state, result),
# 回答或失败说明中的提议等待用户确认,等待补充和取消时没有提议
offer=state.get("offer")
if result.status in ("completed", "failed")
else None,
created_at=datetime.now(timezone.utc),
)
)
@@ -189,15 +177,15 @@ class AgentService:
@staticmethod
def _result(state, thread_id):
waiting = bool(state.get("__interrupt__"))
# 只交付校验通过的完整动作批次,失败草稿留在后端
deliver = state["status"] == "completed" and state.get("validation_passed")
# 只交付完成状态下的动作;actions 是 agent 最后一次成功提交、已通过模拟执行的整批动作
deliver = state["status"] == "completed"
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["actions"] if deliver else [],
actions=(state.get("actions") or []) if deliver else [],
answer=state.get("answer"),
clarification=state.get("clarification") if waiting else None,
)