feat: 新增 react_reason 循环思考过程的流式显示
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m38s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m38s
- 修改 react_nodes.py,在推理时保存推理过程到状态 - 修改 agent_service.py,检测并发送推理过程事件到前端 - 修改 chat_area.py,接收并显示推理过程 - 修改 useChat.ts,添加对推理过程事件的支持
This commit is contained in:
@@ -258,6 +258,34 @@ class AIAgentService:
|
||||
info(f"🔄 处理updates chunk")
|
||||
updates_data = chunk["data"]
|
||||
serialized_data = self._serialize_value(updates_data)
|
||||
|
||||
# 检查是否有最新的推理内容(来自 react_reason_node)
|
||||
if isinstance(serialized_data, dict):
|
||||
# 遍历所有节点的数据
|
||||
for node_name, node_data in serialized_data.items():
|
||||
if isinstance(node_data, dict) and "debug_info" in node_data:
|
||||
debug_info = node_data["debug_info"]
|
||||
latest_reasoning = debug_info.get("latest_reasoning")
|
||||
if latest_reasoning and not latest_reasoning.get("sent"):
|
||||
# 发送推理过程到前端
|
||||
step = latest_reasoning.get("step", 1)
|
||||
action = latest_reasoning.get("action", "unknown")
|
||||
confidence = latest_reasoning.get("confidence", 0)
|
||||
reasoning = latest_reasoning.get("reasoning", "")
|
||||
|
||||
info(f"[Agent Service] 发送推理过程 #{step}: {action}")
|
||||
|
||||
# 发送推理事件
|
||||
yield {
|
||||
"type": "react_reasoning",
|
||||
"step": step,
|
||||
"action": action,
|
||||
"confidence": confidence,
|
||||
"reasoning": reasoning
|
||||
}
|
||||
|
||||
# 标记为已发送(避免重复发送)
|
||||
latest_reasoning["sent"] = True
|
||||
|
||||
# 检查是否有人工审核请求
|
||||
if "review_pending" in serialized_data and serialized_data["review_pending"]:
|
||||
|
||||
Reference in New Issue
Block a user