-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
63 lines (54 loc) · 1.92 KB
/
graph.py
File metadata and controls
63 lines (54 loc) · 1.92 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# graph.py
from langgraph.graph import StateGraph, END
from state import AgentState
from nodes import (
researcher_node,
research_quality_node,
summarizer_node,
teacher_node,
guide_quality_node,
quiz_node,
error_node
)
from edges import route_research, route_guide
def build_graph():
"""
Assemble the complete learning agent graph.
Every node, edge and condition defined here.
"""
graph = StateGraph(AgentState)
# ── Register all nodes ─────────────────────
graph.add_node("researcher", researcher_node)
graph.add_node("research_quality", research_quality_node)
graph.add_node("summarizer", summarizer_node)
graph.add_node("teacher", teacher_node)
graph.add_node("guide_quality", guide_quality_node)
graph.add_node("quiz", quiz_node)
graph.add_node("error", error_node)
# ── Simple edges ───────────────────────────
graph.add_edge("researcher", "research_quality")
graph.add_edge("summarizer", "teacher")
graph.add_edge("teacher", "guide_quality")
graph.add_edge("quiz", END)
graph.add_edge("error", END)
# ── Conditional edges ──────────────────────
graph.add_conditional_edges(
"research_quality",
route_research,
{
"researcher": "researcher",
"summarizer": "summarizer",
"error": "error"
}
)
graph.add_conditional_edges(
"guide_quality",
route_guide,
{
"teacher": "teacher",
"quiz": "quiz"
}
)
# ── Entry point ────────────────────────────
graph.set_entry_point("researcher")
return graph.compile()