From 0565788a3945d1fc2a8954cee59781550ced0960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 5 Jun 2026 12:37:47 +0000 Subject: [PATCH] Add src/graph.py --- src/graph.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/graph.py diff --git a/src/graph.py b/src/graph.py new file mode 100644 index 0000000..860e756 --- /dev/null +++ b/src/graph.py @@ -0,0 +1,46 @@ +""" +LangGraph implementation for the research brief generator. + +The graph orchestrates the following nodes (defined in ``brief.py``): + +* ``outline`` – generates a 4–5 point outline. +* ``research_step`` – performs a web search for the current outline point and creates a short note. +* ``synthesize`` – combines all notes into a coherent brief. + +The graph loops over ``research_step`` until all outline points are processed. +""" + +from langgraph import StateGraph, END +from .brief import BriefState, outline_node, research_step_node, synthesize_node + +def build_graph() -> StateGraph: + """Build and return the LangGraph graph. + + The graph starts at ``outline``. After generating the outline it + proceeds to ``research_step``. ``research_step`` is repeated until + ``step_index`` reaches the length of the outline, then the graph + moves to ``synthesize`` and ends. + """ + graph = StateGraph(BriefState) + + # Add nodes + graph.add_node("outline", outline_node) + graph.add_node("research_step", research_step_node) + graph.add_node("synthesize", synthesize_node) + + # Entry point + graph.set_entry_point("outline") + + # After outline, always go to research_step + graph.add_edge("outline", "research_step") + + # Conditional loop: if more steps remain, stay in research_step + def research_cond(state: BriefState): + return "research_step" if state["step_index"] < len(state["outline"]) else "synthesize" + + graph.add_conditional_edges("research_step", research_cond) + + # End after synthesis + graph.add_edge("synthesize", END) + + return graph \ No newline at end of file