For the past two years, "AI Agent" development has been dominated by Loop Engineering. We’ve all written the code: while (!success) { try(); retry(); }. It works, but it’s brittle, stateless, and burns through tokens with blind retries.
The industry is shifting. The next paradigm is Graph Engineering.
Today, I’m open-sourcing Rashomon, a multi-agent debate simulator built in a single weekend to demonstrate exactly why graphs are the future of agentic workflows.
The Architecture: Parallel, Conditional, Stateful
Rashomon doesn’t just ask an LLM to "debate itself." It uses @langchain/langgraph to construct a deterministic, multi-stage workflow:
- Parallel Fan-out: When a topic is submitted, all 4 personas (Optimist, Cynic, Pedant, Chaos) are invoked simultaneously via
Promise.all. No sequential waiting. - Conditional Routing: The graph evaluates the accumulated "chaos level." If it’s high, it routes to a
Debatenode. If low, it skips straight toSynthesis. - Stateful Accumulation: A shared
DebateStateobject tracks which agents have spoken, preventing infinite feedback loops between the same two personas. - Real-time Streaming: Using Server-Sent Events (SSE), the frontend visualizes the graph building itself node-by-node via React Flow.
The Code: A Glimpse Under the Hood
Here’s how trivial it is to define conditional routing in LangGraph.js compared to writing nested if/else retry loops:
// Define the graph
const workflow = new StateGraph<DebateState>({ channels: { /* state schema */ } });
// Add specialized nodes
workflow.addNode('initial', initialResponsesNode);
workflow.addNode('debate', debateNode);
workflow.addNode('synthesis', synthesisNode);
// Conditional routing based on state
workflow.addConditionalEdges('initial', (state) => {
return state.chaosLevel >= 2 ? 'debate' : 'synthesis';
});
// Compile and stream
const app = workflow.compile();
const stream = await app.astream(initialState);
Why This Matters
Loops are reactive. Graphs are architectural. By explicitly defining nodes (agents), edges (routing logic), and state (memory), we get:
- Observability: You can see exactly which node failed and why.
- Efficiency: Parallel execution cuts latency by 60-70%.
- Control: You dictate the flow, not the LLM’s hallucinated retry logic.
The full source code, complete with a real-time React Flow visualization and support for OpenRouter/Ollama, is available on GitHub.
Check out the repo, fork it, and let’s build the next generation of agents together: https://www.dailybuild.xyz/project/199-rashomon-debate
Top comments (0)