DEV Community

Uddhav Bhople
Uddhav Bhople

Posted on

I built a multi-agent IPL captain cool AI on Gemini

Cricket is a captain's game. And for 3 hours at a Google AI hackathon, I became one — by building Captain Cool, a multi-agent IPL strategist powered entirely by Google Gemini. Not a chatbot. Not a form with a Gemini call. A real debate between AI agents — the way a captain's brain actually works.

The problem

Every IPL captain faces split-second decisions — who bowls the death over, when to bring in the Impact Player, how to set the field against a left-hander in dew. These calls win or lose matches.

I wanted to build an AI that doesn't just answer "who should bowl?" but actually debates it, shows its reasoning, and tells you what happens if you make the wrong call.


Architecture

Instead of one Gemini call wearing 4 hats, I built 4 named agents with distinct roles that talk to each other:

User Input (Cricbuzz URL or manual match state)
                ↓
         Orchestrator
┌─────────────────────────────────────┐
│ Agent 1: Stats Analyst              │ ← Google Search tool call
│ Agent 2: Strategist (persona-based) │ ← Proposes the call
│ Agent 3: Devil's Advocate           │ ← Challenges it hard
│ Agent 4: Commentator                │ ← Final output + counterfactual
└─────────────────────────────────────┘
                ↓
    Decision + Debate UI + Voice Output
Enter fullscreen mode Exit fullscreen mode

The 4 agents

Agent 1 — Stats Analyst

Uses Gemini's built-in Google Search tool to fetch live player form and head-to-head stats. Not hardcoded JSON — real tool use.

System prompt:

You are an IPL stats analyst. Analyze pitch conditions, dew factor,
bowler economy rates, and batter weaknesses. Use Google Search to
fetch current player form. Output structured JSON with: key_stats,
batter_weakness, bowler_recommendation, win_probability (%).
Enter fullscreen mode Exit fullscreen mode

Agent 2 — Strategist (Persona-driven)

The user picks a captain persona — and the entire system prompt personality changes:

🧊 Dhoni mode:

You are MS Dhoni. Ice in your veins. You back your bowlers,
never panic, always think 2 overs ahead. Make ONE decisive call. No hedging.
Enter fullscreen mode Exit fullscreen mode

💥 Rohit mode:

You are Rohit Sharma. Bold and aggressive. Back your instincts
and your big hitters. Make the attacking call others won't.
Enter fullscreen mode Exit fullscreen mode

🔥 Hardik mode:

You are Hardik Pandya. Unconventional and fearless.
Make the call that surprises everyone but works.
Enter fullscreen mode Exit fullscreen mode

Agent 3 — Devil's Advocate

You are a sharp rival captain. Challenge the Strategist's decision hard.
Find the flaw. Propose a specific alternative.
Format: CHALLENGE: [what's wrong] | ALTERNATIVE: [what you'd do instead]
Enter fullscreen mode Exit fullscreen mode

Agent 4 — Commentator

You are Harsha Bhogle. Explain the final call in vivid cricket language
a passionate fan would love. Include: why this decision, why NOT the
alternative, a counterfactual ("if they'd bowled X, win prob drops ~Y%"),
and a confidence score out of 10.
Enter fullscreen mode Exit fullscreen mode

Orchestrator flow

  1. Extract match state from Cricbuzz URL using Gemini's URL context tool
  2. Stats Analyst runs Google Search → structured JSON with win probability
  3. Strategist (selected persona) proposes tactical decision
  4. Devil's Advocate challenges with a specific alternative
  5. Strategist defends or revises → final call
  6. Commentator delivers cricket-language output + counterfactual + confidence score + voice via Web Speech API

One full match scenario

Match state:

  • MI vs CSK · 2nd innings · Over 16 · CSK need 34 off 24 · 4 wickets down
  • Rohit Sharma on strike (67*) · Jadeja non-striker (12*)
  • Bumrah has 2 overs left · Chahal has 1 · Flat pitch · Heavy dew · Wankhede

Stats Analyst: Win prob MI 58% / CSK 42%. Dew negating seam movement. Jadeja vulnerable to pace outside off.

Strategist (Dhoni mode): Bowl Bumrah now — back him to nail yorkers despite the dew.

Devil's Advocate: Dew renders Bumrah's seam movement useless tonight. Save him for over 19. Bowl Chahal now while Jadeja is on strike — he's the weak link against leg spin.

Strategist (final call): Point conceded. Chahal to bowl over 17. Bumrah held for over 19.

Commentator: "In dew-heavy Wankhede, Bumrah's famous seam is rendered ineffective. Rohit holds him back for the 19th — calm, calculated captaincy. If they'd bowled Bumrah here, win probability drops to 51%. Confidence: 8/10." 🎙️


What made us stand out

At the hackathon, 100+ developers were building the same thing — a form that calls Gemini and returns formatted text. Here's what we did differently:

  • Real agent debate visible in the UI — shown as chat bubbles, not hidden or summarized
  • Captain persona selector — same agents, completely different personality per captain
  • Live Cricbuzz scraping — paste a URL, Gemini extracts the match state automatically
  • Counterfactual — we don't just tell you what to do, we tell you what happens if you don't
  • Voice output — the commentator speaks the final call aloud via Web Speech API

Tech stack

Layer Technology
Frontend TypeScript + Vite + CSS
AI model Google Gemini 2.5 Flash
SDK @google/genai
Tool use Gemini built-in Google Search
Voice output Web Speech API
Build environment Google AI Studio

Links


Built by Uddhav Bhople — Associate Microsoft Learn Student Ambassador · Google Student Ambassador · B.Tech Computer Engineering Student @ D.Y. Patil University Pune

googleai #gemini #cricket #apl #hackathon #multiagent #typescript #gdgcloudpune #gdgcloudpune2026

Top comments (0)