-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathgraph.py
More file actions
28 lines (22 loc) · 919 Bytes
/
graph.py
File metadata and controls
28 lines (22 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from langgraph.constants import END, START
from langgraph.graph.state import CompiledStateGraph, StateGraph
from langgraph.prebuilt.tool_node import tools_condition
from langgraph.pregel.main import BaseCheckpointSaver
from examples.ex010.context import Context
from examples.ex010.nodes import call_llm, tool_node
from examples.ex010.state import State
def build_graph(
checkpointer: BaseCheckpointSaver,
) -> CompiledStateGraph[State, Context, State, State]:
builder = StateGraph(
state_schema=State,
context_schema=Context,
input_schema=State,
output_schema=State,
)
builder.add_node("call_llm", call_llm)
builder.add_node("tools", tool_node)
builder.add_edge(START, "call_llm")
builder.add_conditional_edges("call_llm", tools_condition, ["tools", END])
builder.add_edge("tools", "call_llm")
return builder.compile(checkpointer=checkpointer)