修复:调整事件格式匹配前端期望
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m30s

This commit is contained in:
2026-05-07 03:15:47 +08:00
parent 19bccc1941
commit a155b6e5ea

View File

@@ -93,8 +93,8 @@ def create_agent_node(llm_with_tools, llm):
# 告诉前端:新的一轮开始(如果流式) # 告诉前端:新的一轮开始(如果流式)
if is_streaming: if is_streaming:
await queue.put({ await queue.put({
"type": "turn_start", "type": "node_start",
"turn": turn, "node": "agent",
}) })
# 选择 LLM # 选择 LLM
@@ -119,8 +119,7 @@ def create_agent_node(llm_with_tools, llm):
full_content += chunk.content full_content += chunk.content
await queue.put({ await queue.put({
"type": "llm_token", "type": "llm_token",
"turn": turn, "node": "agent",
"phase": "answering",
"token": chunk.content, "token": chunk.content,
"reasoning_token": "" "reasoning_token": ""
}) })
@@ -132,8 +131,7 @@ def create_agent_node(llm_with_tools, llm):
full_reasoning_content += reasoning_content full_reasoning_content += reasoning_content
await queue.put({ await queue.put({
"type": "llm_token", "type": "llm_token",
"turn": turn, "node": "agent",
"phase": "reasoning",
"token": "", "token": "",
"reasoning_token": reasoning_content "reasoning_token": reasoning_content
}) })
@@ -202,11 +200,13 @@ def create_agent_node(llm_with_tools, llm):
# 发送工具开始事件(如果流式) # 发送工具开始事件(如果流式)
if is_streaming: if is_streaming:
await queue.put({ await queue.put({
"type": "custom",
"data": {
"type": "tool_start", "type": "tool_start",
"turn": turn,
"tool": tool_name, "tool": tool_name,
"args": tool_args, "args": tool_args,
"id": tool_id "id": tool_id
}
}) })
# 找到并执行对应工具 # 找到并执行对应工具
@@ -228,11 +228,13 @@ def create_agent_node(llm_with_tools, llm):
# 发送工具结束事件(如果流式) # 发送工具结束事件(如果流式)
if is_streaming: if is_streaming:
await queue.put({ await queue.put({
"type": "custom",
"data": {
"type": "tool_end", "type": "tool_end",
"turn": turn,
"tool": tool_name, "tool": tool_name,
"id": tool_id, "id": tool_id,
"result": str(tool_result) "result": str(tool_result)
}
}) })
# 构造 ToolMessage # 构造 ToolMessage
@@ -248,14 +250,8 @@ def create_agent_node(llm_with_tools, llm):
continue continue
else: else:
# 没有工具调用,最终输出 # 没有工具调用,最终输出(不需要发 final_answer因为 llm_token 已经发了)
info(f"[Agent] 第 {turn} 轮:完成,无工具调用") info(f"[Agent] 第 {turn} 轮:完成,无工具调用")
if is_streaming:
await queue.put({
"type": "final_answer",
"turn": turn,
"content": full_content
})
break break
# 构建完整的 AIMessage 用于状态更新 # 构建完整的 AIMessage 用于状态更新