智能体记忆
点击查看代码
from langgraph.graph import START, StateGraph
from langgraph.prebuilt import tools_condition, ToolNode
builder = StateGraph(MessagesState)
# 定义节点和边
builder.add_node("assistant", assistant)
builder.add_node("tools", ToolNode(tools))
builder.add_edge(START, "assistant")
builder.add_conditional_edges("assistant", tools_condition)
builder.add_edge("tools", "assistant")
# 编译图
react_graph = builder.compile()