langgraph自定义输入输出状态
定义状态
class InputState(TypedDict):
question : str
class OutputState(TypedDict):
answer : str
class OverallState(TypedDict):
question : str
answer : str
notes : str
节点
def thinking_node(state : InputState):
return {"answer":"你好","notes":"他是张三"}
def answer_node(state : OverallState) -> OutputState:
return {"answer":"再见"}
定义图
#通过input和output参数设置进入流程和结束流程的状态类型
graph = StateGraph(OverallState,input=InputState,output=OutputState)
graph.add_node("thinking_node",thinking_node)
graph.add_node("answer_node",answer_node)
graph.add_edge(START,"thinking_node")
graph.add_edge("thinking_node","answer_node")
graph.add_edge("answer_node",END)
g = graph.compile()
测试
s = g.invoke({"question":"hello"})
print(s)