-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathgraph.py
More file actions
20 lines (14 loc) · 719 Bytes
/
Copy pathgraph.py
File metadata and controls
20 lines (14 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.constants import END, START
from langgraph.graph.state import CompiledStateGraph, StateGraph
from langgraph.prebuilt.tool_node import tools_condition
from examples.ex008.nodes import call_llm, tool_node
from examples.ex008.state import State
def build_graph() -> CompiledStateGraph[State, None, State, State]:
builder = StateGraph(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=InMemorySaver())