veriscite / app /graph /build.py
minoola's picture
Upload 51 files
5db2259 verified
Raw
History Blame Contribute Delete
1.6 kB
"""Assembles the VeriScite LangGraph state machine."""
from langgraph.graph import StateGraph, END
from app.graph.state import GraphState
from app.graph import nodes
def build_graph():
graph = StateGraph(GraphState)
graph.add_node("extract_claims", nodes.extract_claims)
graph.add_node("fetch_citation", nodes.fetch_citation)
graph.add_node("verify_dual", nodes.verify_dual)
graph.add_node("handle_unresolved_citation", nodes.handle_unresolved_citation)
graph.add_node("escalate", nodes.escalate)
graph.add_node("explain", nodes.explain)
graph.add_node("next_claim", nodes.next_claim)
graph.add_node("build_report", nodes.build_report)
graph.set_entry_point("extract_claims")
graph.add_edge("extract_claims", "fetch_citation")
graph.add_conditional_edges(
"fetch_citation",
nodes.route_after_fetch,
{"verify": "verify_dual", "unresolved": "handle_unresolved_citation"},
)
graph.add_conditional_edges(
"verify_dual",
nodes.route_after_verify,
{"escalate": "escalate", "explain": "explain"},
)
graph.add_edge("escalate", "explain")
graph.add_conditional_edges(
"explain",
nodes.advance_or_report,
{"next_claim": "next_claim", "report": "build_report"},
)
graph.add_conditional_edges(
"handle_unresolved_citation",
nodes.advance_or_report,
{"next_claim": "next_claim", "report": "build_report"},
)
graph.add_edge("next_claim", "fetch_citation")
graph.add_edge("build_report", END)
return graph.compile()