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