The goal: multi-agent debate with guardrails

You've built single-agent bots. Now you'll build a system where multiple agents with opposing viewpoints argue about a stock ticker. The debate is adversarial β€” each agent is forced to argue their side and cite real data β€” but orchestrated: a moderator synthesizes both sides and the system enforces that no agent makes claims without evidence.

Here's what it looks like when three agents debate HDFCBANK.NS:

DEBATE: HDFCBANK.NS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Turn 1 β€” Bull argues:
"HDFC's NIM has expanded 12 bps in Q1, driven by rising deposit rates.
This is bullish. Source: Q1 earnings call."

Turn 1 β€” Bear counters:
"But loan growth slowed to 8% YoY vs 12% last year. Rising rates hit
retail borrowers. Source: Q1 briefing data."

Turn 2 β€” Bull replies:
"Strong liability franchise β€” CASA ratio improved to 42%. Sticky deposits
fuel resilience. Source: balance sheet analysis."

...

MODERATOR SUMMARY:
Bull's strongest point: NIM expansion + deposit stability
Bear's strongest point: Loan growth deceleration signals market slowdown
Verdict: Mixed signals. Monitor next quarter's growth numbers.

This is multi-agent orchestration. Each agent reasoned separately, cited evidence, and the moderator made a call. Over the next 30 minutes, you'll build the full system.

Architecture: 3 agents + turn structure + guardrails

The system has three components: two debating agents, one moderator, plus a critic that enforces rules.

1. BullAgent argues up
β†’
2. BearAgent argues down
β†’
3. Moderator synthesizes
πŸ“Š
Real scenario
Arjun's investment research bot (Hyderabad)

Arjun is building an investment research tool for retail traders in Hyderabad. Every morning, his bot debates 5 stocks (RELIANCE.NS, HDFCBANK.NS, TCS.NS, etc.) automatically. Each stock gets a 3-turn debate. Instead of reading conflicting newsletters, Arjun sees a structured debate where both sides cite data. He decides based on who won the argument.

Step 1: Define the debate turn with Pydantic

Each agent's argument is a structured "DebateTurn". It must include the claim, evidence from yfinance, and a citation.

debate_model.py Pydantic types for debate turns
Why structure the turns?
Because we can validate that each turn has a claim AND a citation. If the agent tries to argue without evidence, Pydantic will reject it.

Step 2: Fetch ticker data and recent metrics

Before agents debate, fetch real price data and calculate key metrics. Agents will cite these in their arguments.

fetch_debate_data.py Fetch ticker + compute debate-relevant metrics

Step 3: System prompts that enforce debate rules

Each agent gets a system prompt that forces them to argue their side AND cite a metric from the data. No hand-waving allowed.

debate_prompts.py System prompts for Bull, Bear, and Moderator
System prompt trick:
Force JSON output and require a citation field. When you parse the JSON, if the citation field is missing or references a metric you didn't provide, you reject it. No naked claims.

Step 4: Orchestrator that runs 3 turns of debate

The orchestrator fetches data, calls each agent 3 times, collects turns, validates them with Pydantic, and passes to the moderator.

debate_orchestrator.py Run a full debate session with guardrails

Step 5: Guardrailsβ€”enforce debate rules with a critic

A critic agent checks each turn for valid citations and rules violations. If an agent tries to argue without evidence, the critic rejects it.

Rule enforcement:
After each turn is generated, the Pydantic model validates it. If citation is missing or references a metric not in the data, parsing fails and we retry or skip. No naked claims get through.
Common guardrails:
No personal attacks ("Bull is stupid"), no off-topic claims ("The CEO is tall"), no made-up numbers. Each claim must reference a metric from the ticker data.

Full worked example: HDFCBANK.NS debate

Here's what a real 3-round debate output looks like, with the moderator's synthesis:

DEBATE SESSION: HDFCBANK.NS
Timestamp: 2026-04-16

ROUND 1:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Bull: "HDFC's net interest margin (NIM) expanded 12 bps in Q1 2026,
beating consensus. This shows pricing power in a rising rate environment."
  Evidence: NIM up 12 bps YoY
  Citation: Q1 earnings release

Bear: "But loan growth slowed to 8% YoY, down from 12% last year.
In a declining rate cycle, this slowdown signals demand weakness."
  Evidence: Loan growth 8% vs 12% prior year
  Citation: Management guidance

ROUND 2:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Bull: "CASA ratio improved to 42%, meaning deposits are sticky.
In rising rate regimes, stable deposits are goldβ€”they fund growth without
chasing rate-sensitive corporates."
  Evidence: CASA 42% (up from 39% last year)
  Citation: Balance sheet analysis

Bear: "Deposit betas are rising. RBI's tightening cycle is now over.
When rates peak and reverse, HDFC's NIM will compress.
All the expansion we saw this quarter will reverse."
  Evidence: Volatility 14.5% indicates uncertainty
  Citation: Market regime shift (RBI guidance)

ROUND 3:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Bull: "Stock is trading near 52-week lows (β‚Ή1,650 vs β‚Ή1,900 high).
Valuations have compressed. At 1.8x book, the bank is cheap vs 2.1x
historical average."
  Evidence: P/E near 10-year low
  Citation: Market data

Bear: "Cheap for a reason. Credit growth stalling, NIM expansion was one-time,
and the bank's exposure to real estate is risingβ€”rate cuts will hurt demand.
Wait for better entry."
  Evidence: Volatility 14.5%, recent price decline -8% month
  Citation: Sector analysis

MODERATOR SYNTHESIS:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Bull's strongest point: "NIM expansion + CASA stability show pricing
power and resilience in the current rate environment."

Bear's strongest point: "Loan growth deceleration suggests the broad
economy is slowing, limiting upside regardless of NIM."

Key disagreement: Whether NIM expansion is sustainable through a rate
cycle reversal.

Neutral takeaway: HDFC has near-term strength (margins, deposits) but
medium-term headwinds (loan growth). Buy for value, but monitor credit
growth closely. Fair price: β‚Ή1,750–₹1,900 depending on Q2 guidance.

Stretch: add a skeptic agent

Some teams add a third agentβ€”a "Skeptic" who pokes holes in BOTH sides. This agent doesn't argue for bull or bear; it finds flaws in the logic, missing data, or risky assumptions. If you build this, you now have a 4-agent system: Bull + Bear + Moderator + Skeptic.

Exercise idea:
Write a SKEPTIC_SYSTEM_PROMPT that tells the agent to find one logical fallacy or missing piece of data from the debate. Have the skeptic respond after the 3 rounds close.

How multi-agent systems work in production

This debate system is a toy, but the pattern is industry-standard. Real financial firms use multi-agent systems to debate portfolio decisions (why buy now vs wait?), cybersecurity teams use multiple agents to think through attack vectors, and medical teams use agent debate to diagnose tricky cases. The key insight: a single agent can be smart, but two agents with opposite biases arguing in front of a referee make better decisions. You've just built that referee.

Multi-agent orchestration Structured debate Adversarial reasoning Pydantic validation Guardrails
🎯 Mini Challenge: Add sentiment scoring

Task: Modify the DebateTurn model to include a sentiment_score: float field (range -1.0 to +1.0, where -1 is very bearish, +1 is very bullish). After each agent's turn, estimate their sentiment (e.g., the bull agent's turn with "stock is cheap" = +0.8, the bear agent's "growth stalling" = -0.7).

Then compute an overall debate sentiment as the average of all 6 turns. If it's positive, the debate is bullish; if negative, bearish.

Hint: Add sentiment_score: float to DebateTurn, then in the system prompt, ask each agent to assign a sentiment to their own claim (e.g., "On a scale of -1 to +1, how bullish/bearish is your argument?"). Parse it from the JSON. At the end, average all 6 scores to get debate_sentiment. If > 0, print "Overall debate is BULLISH"; if < 0, "BEARISH".

Test your knowledge

Question 1 of 5
What is the purpose of the DebateTurn Pydantic model?
Question 2 of 5
How does the orchestrator prevent agents from making naked claims without evidence?
Question 3 of 5
In the debate, what data comes from yfinance?
Question 4 of 5
What does the Moderator agent do?
Question 5 of 5
How would you extend this system to compare two stocks (HDFC vs RELIANCE) in a single debate?
0
/5
Excellent! You've mastered multi-agent orchestration.
Africa & India's Best AI Academy
πŸ€– AI-first πŸŽ“ Placement Assistance

You've built a multi-agent system.
Now build ones that scale to production.

Join the Best AI Program: The AI-Era Agentic Engineer β€” 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Agentic Engineer β†’