修复状态兼容性问题: 移除 dict 解包操作
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m35s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m35s
This commit is contained in:
@@ -141,7 +141,7 @@ def create_llm_call_node(llm, tools: list):
|
||||
"has_tool_calls": has_tool_calls
|
||||
}
|
||||
|
||||
log_state_change("llm_call", {**state, **result}, "离开")
|
||||
log_state_change("llm_call", state, "离开")
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -9,7 +9,7 @@ from langchain_core.messages import AIMessage, ToolMessage
|
||||
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.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
|
||||
|
||||
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, "进入")
|
||||
|
||||
last_message = state['messages'][-1]
|
||||
last_message = state.messages[-1]
|
||||
if not isinstance(last_message, AIMessage) or not last_message.tool_calls:
|
||||
log_state_change("tool_node", state, "离开(无工具调用)")
|
||||
return {"messages": []}
|
||||
@@ -75,10 +75,9 @@ def create_tool_call_node(tools_by_name: Dict[str, Any]):
|
||||
else:
|
||||
observation = await loop.run_in_executor(
|
||||
None,
|
||||
lambda args=tool_args: tool_func.invoke(args) # 默认参数捕获当前值
|
||||
lambda args=tool_args: tool_func.invoke(args)
|
||||
)
|
||||
|
||||
# 字符打印
|
||||
result_preview = str(observation).replace("\n", " ")
|
||||
debug(f" └─ ✅ 结果: {result_preview}")
|
||||
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")
|
||||
|
||||
result = {"messages": results}
|
||||
log_state_change("tool_node", {**state, **result}, "离开")
|
||||
log_state_change("tool_node", state, "离开")
|
||||
return result
|
||||
|
||||
return call_tools
|
||||
Reference in New Issue
Block a user