- AI Engineering
- Posts
- [Hands-On] Build a Multi-Agent Debate System
[Hands-On] Build a Multi-Agent Debate System
... PLUS: Apify MCP Connectors: Connect Your Actors to the Tools You Already Use
In today’s newsletter:
Apify MCP Connectors: Connect Your Actors to the Tools You Already Use
[Hands-On] Build a Multi-Agent Debate System
Reading time: 5 minutes.
Apify Actors solve web scraping and browser automation. They can extract data, monitor websites, and automate repetitive workflows across the web.
But the moment an Actor needs to interact with your internal tools, things get complicated. Updating a Notion database, creating a GitHub issue, reading from Slack, or accessing any authenticated application usually requires custom integrations and credential management.
MCP Connectors solve that.
How It Works
You authorize a service once and attach it to an Actor. When the Actor needs to interact with that service, Apify's MCP Proxy handles authentication and forwards the request on your behalf. The Actor never directly manages credentials.
What This Enables
Update Notion pages: Push scraped data directly into your workspace after each run.
Create GitHub issues: Trigger issue creation automatically from monitoring workflows.
Send Slack alerts: Route results or notifications to any channel without credential exposure.
Connect to internal tools: Link Actors to any MCP-compatible business application.
Apify Actors already automate the web. MCP Connectors let them work inside the tools where your team actually gets work done.
Ask an LLM to evaluate an idea, and it will lock onto its first answer and defend it. Researchers call this the Degeneration-of-Thought problem, where self-reflection becomes less effective once the model gains confidence in its initial position.
Multi-agent debate fixes this. Instead of relying on a single model's reasoning, separate agents are assigned opposing viewpoints. Each agent sees only the other's arguments and must respond with counterarguments.
A third independent agent evaluates every exchange. It scores arguments based on logic, evidence, and persuasiveness before determining the winner.
This project implements that workflow. Two AI agents debate a topic across configurable rounds, while a judge evaluates each round and produces a final verdict.
Tech Stack:
LangGraph for agent orchestration
A lightweight model router to switch between Gemini, Mistral, and Kimi
How the System Works
Two agents debate opposing sides of a topic. A judge then scores each argument on logic, evidence, and persuasiveness before producing a final JSON verdict.

Now that we understand the debate workflow, let's build it in LangGraph
Step 1: Define the Shared State
Every node reads from and writes to a single DebateState object. This is how LangGraph passes context between agents without global variables.

Step 2: Route All Models Through a Unified Interface
Instead of managing separate API keys and client libraries for Gemini, Mistral, and Kimi, all three agents call the same router endpoint. You change the model string to switch models.

Step 3: Build the Debater Nodes
Each debater node reads the full transcript, builds a system prompt locked to its position, and appends its argument to the transcript.

Step 4: Build the Judge Node
The judge receives the full transcript and returns structured JSON with per-argument scores, totals, a winner, and a verdict. The parser recomputes totals from raw scores rather than trusting the LLM's arithmetic.

The judge scores each argument on three criteria (logic, evidence, persuasiveness, 1-10 each). The debater with the higher total wins.
Step 5: Assemble the Graph
After Debater B finishes speaking, the system checks whether the debate has reached the maximum number of rounds. If not, another round begins. Otherwise, the debate is sent to the judge for evaluation.

Run It
Execute the debate and iterate through the graph state as each step completes. During execution, you can inspect agent responses in real time and display the final verdict once the judge finishes scoring the debate.

Multi-agent debate is not the right architecture for every task. It costs more tokens and takes longer than a single-agent call. But when the cost of a wrong answer is high, the additional scrutiny is often worth it.
Common use cases include:
Business decisions: Evaluate investments, product bets, and strategic directions from multiple perspectives.
LLM evaluation: Surface disagreements and biases that a single-model judge might miss.
Legal and compliance review: Create an auditable record of arguments before concluding.
Stress-testing ideas: Expose the strongest counterarguments before committing to a decision.
Fact-checking and moderation: Improve accuracy by having agents challenge each other's claims.
The pattern works best when the task is open-ended, the stakes are high, and you need transparent reasoning rather than just an answer.
That’s all for today. Thank you for reading today’s edition. See you in the next issue with more AI Engineering insights.
PS: We curate this AI Engineering content for free, and your support means everything. If you find value in what you read, consider sharing it with a friend or two.
Your feedback is valuable: If there’s a topic you’re stuck on or curious about, reply to this email. We’re building this for you, and your feedback helps shape what we send.
WORK WITH US
Looking to promote your company, product, or service to 200K+ AI developers? Get in touch today by replying to this email.

