| """ |
| LangGraph workflow β the main debate orchestration graph. |
| |
| Flow: |
| START β chef β nutrition β eco β moderator β should_continue? |
| βββ decision_reached=True β END |
| βββ round >= 4 β END |
| βββ else β chef (next round) |
| """ |
|
|
| from langgraph.graph import END, StateGraph |
|
|
| from graph.nodes import chef_node, eco_node, moderator_node, nutrition_node |
| from graph.state import DebateState |
|
|
|
|
| def should_continue(state: DebateState) -> str: |
| """ |
| Conditional edge: decide whether to continue the debate or end it. |
| |
| Returns: |
| 'end' if decision reached or max rounds exceeded, 'continue' otherwise. |
| """ |
| if state.get("decision_reached", False): |
| return "end" |
|
|
| if state.get("current_round", 1) >= 2: |
| return "end" |
|
|
| return "continue" |
|
|
|
|
| def build_graph() -> StateGraph: |
| """ |
| Build and compile the multi-agent debate graph. |
| |
| Returns: |
| A compiled LangGraph StateGraph ready for invocation. |
| """ |
| workflow = StateGraph(DebateState) |
|
|
| |
| workflow.add_node("chef", chef_node) |
| workflow.add_node("nutrition", nutrition_node) |
| workflow.add_node("eco", eco_node) |
| workflow.add_node("moderator", moderator_node) |
|
|
| |
| workflow.set_entry_point("chef") |
|
|
| |
| workflow.add_edge("chef", "nutrition") |
| workflow.add_edge("nutrition", "eco") |
| workflow.add_edge("eco", "moderator") |
|
|
| |
| workflow.add_conditional_edges( |
| "moderator", |
| should_continue, |
| { |
| "continue": "chef", |
| "end": END, |
| }, |
| ) |
|
|
| return workflow.compile() |
|
|