-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
69 lines (54 loc) · 2.28 KB
/
graph.py
File metadata and controls
69 lines (54 loc) · 2.28 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
64
65
66
67
68
69
from langgraph.graph import StateGraph, START, END
from state import AgentState
from nodes import clarity_agent, research_agent, validator_agent, synthesis_agent
# Routing Functions
def route_clarity(state: AgentState):
if state["clarity_status"] == "needs_clarification":
return END # End run, will display the clarification question to user
return "research_agent"
def route_validator(state: AgentState):
# Logic: If insufficient AND attempts < 3 -> Retry Research
# Else -> Synthesis
if state["validation_result"] == "insufficient" and state.get("attempt_count", 0) < 3:
return "research_agent"
return "synthesis_agent"
def route_research(state: AgentState):
# Research always goes to Validator
# But we can check confidence here if we wanted to skip Validator as per requirements?
# Req: "ROUTES TO: Validator Agent (if confidence < 6) OR Synthesis Agent (if confidence >= 6)"
# Wait, requirements say:
# "ROUTES TO: Validator Agent (if confidence < 6) OR Synthesis Agent (if confidence >= 6)"
# Correction: The requirements actually describe a specific flow.
# Let's align exactly with requirements text.
# Requirement 1b says:
# ROUTES TO: Validator Agent (if confidence < 6) OR Synthesis Agent (if confidence >= 6)
score = state.get("confidence_score", 0)
if score >= 6.0:
return "synthesis_agent"
return "validator_agent"
# Build Graph
builder = StateGraph(AgentState)
# Add Nodes
builder.add_node("clarity_agent", clarity_agent)
builder.add_node("research_agent", research_agent)
builder.add_node("validator_agent", validator_agent)
builder.add_node("synthesis_agent", synthesis_agent)
# Add Edges
builder.add_edge(START, "clarity_agent")
builder.add_conditional_edges(
"clarity_agent",
route_clarity,
{END: END, "research_agent": "research_agent"}
)
builder.add_conditional_edges(
"research_agent",
route_research,
{"validator_agent": "validator_agent", "synthesis_agent": "synthesis_agent"}
)
builder.add_conditional_edges(
"validator_agent",
route_validator,
{"research_agent": "research_agent", "synthesis_agent": "synthesis_agent"}
)
builder.add_edge("synthesis_agent", END)
graph = builder.compile()