""" 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) # Add agent nodes workflow.add_node("chef", chef_node) workflow.add_node("nutrition", nutrition_node) workflow.add_node("eco", eco_node) workflow.add_node("moderator", moderator_node) # Set the entry point workflow.set_entry_point("chef") # Linear flow within each round workflow.add_edge("chef", "nutrition") workflow.add_edge("nutrition", "eco") workflow.add_edge("eco", "moderator") # Conditional edge after moderator: continue or end workflow.add_conditional_edges( "moderator", should_continue, { "continue": "chef", "end": END, }, ) return workflow.compile()