修复状态兼容性问题: 移除 dict 解包操作
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m35s

This commit is contained in:
2026-05-02 00:44:23 +08:00
parent 563dea91d4
commit a3e2a5aea4
2 changed files with 22 additions and 23 deletions

View File

@@ -141,7 +141,7 @@ def create_llm_call_node(llm, tools: list):
"has_tool_calls": has_tool_calls "has_tool_calls": has_tool_calls
} }
log_state_change("llm_call", {**state, **result}, "离开") log_state_change("llm_call", state, "离开")
return result return result
except Exception as e: except Exception as e:

View File

@@ -9,7 +9,7 @@ from langchain_core.messages import AIMessage, ToolMessage
from app.main_graph.config import get_stream_writer from app.main_graph.config import get_stream_writer
# 本地模块 # 本地模块
from app.main_graph.state import MessagesState from app.main_graph.state import MainGraphState
from app.utils.logging import log_state_change from app.utils.logging import log_state_change
from app.logger import debug, info from app.logger import debug, info
@@ -26,7 +26,7 @@ def create_tool_call_node(tools_by_name: Dict[str, Any]):
from langchain_core.runnables.config import RunnableConfig from langchain_core.runnables.config import RunnableConfig
async def call_tools(state: MessagesState, config: RunnableConfig) -> Dict[str, Any]: async def call_tools(state: MainGraphState, config: RunnableConfig) -> Dict[str, Any]:
""" """
工具执行节点(异步方法) 工具执行节点(异步方法)
@@ -39,7 +39,7 @@ def create_tool_call_node(tools_by_name: Dict[str, Any]):
""" """
log_state_change("tool_node", state, "进入") log_state_change("tool_node", state, "进入")
last_message = state['messages'][-1] last_message = state.messages[-1]
if not isinstance(last_message, AIMessage) or not last_message.tool_calls: if not isinstance(last_message, AIMessage) or not last_message.tool_calls:
log_state_change("tool_node", state, "离开(无工具调用)") log_state_change("tool_node", state, "离开(无工具调用)")
return {"messages": []} return {"messages": []}
@@ -75,10 +75,9 @@ def create_tool_call_node(tools_by_name: Dict[str, Any]):
else: else:
observation = await loop.run_in_executor( observation = await loop.run_in_executor(
None, None,
lambda args=tool_args: tool_func.invoke(args) # 默认参数捕获当前值 lambda args=tool_args: tool_func.invoke(args)
) )
# 字符打印
result_preview = str(observation).replace("\n", " ") result_preview = str(observation).replace("\n", " ")
debug(f" └─ ✅ 结果: {result_preview}") debug(f" └─ ✅ 结果: {result_preview}")
results.append(ToolMessage(content=str(observation), tool_call_id=tool_id)) results.append(ToolMessage(content=str(observation), tool_call_id=tool_id))
@@ -95,7 +94,7 @@ def create_tool_call_node(tools_by_name: Dict[str, Any]):
info(f"🛠️ [工具调用] 执行完成,返回 {len(results)} 条 ToolMessage") info(f"🛠️ [工具调用] 执行完成,返回 {len(results)} 条 ToolMessage")
result = {"messages": results} result = {"messages": results}
log_state_change("tool_node", {**state, **result}, "离开") log_state_change("tool_node", state, "离开")
return result return result
return call_tools return call_tools