-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathgraph.py
More file actions
26 lines (20 loc) · 882 Bytes
/
graph.py
File metadata and controls
26 lines (20 loc) · 882 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
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.ex009.context import Context
from examples.ex009.nodes import call_llm, tool_node
from examples.ex009.state import State
def build_graph() -> 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=InMemorySaver())