DEV Community

Angel Macwan
Angel Macwan

Posted on

Captain Cool: A Multi-Agent AI That Thinks Like an IPL Captain

Captain Cool: A Multi-Agent AI That Thinks Like an IPL Captain

What happens when you give six AI agents a live cricket match and ask them to argue about it?


Cricket is decided in moments. A bowling change at the wrong over, a misjudged pitch, a batsman promoted too early — the margins are razor thin and the decisions are made in seconds. Yet even the sharpest captains have one brain working against twenty variables at once.

Captain Cool is a multi-agent AI system built to change that. Feed it a live IPL match state and it deliberates — with real dissent, real data, and real cricket language — producing a confident tactical recommendation before the next ball is bowled.

It does this via two distinct agentic architectures:

  1. The Tactical War Room: A structured LangGraph pipeline of specialist agents.
  2. OASIS Social Simulation: An emergent social simulation where dynamically synthesized personas debate across multiple rounds.

The Technology Stack

To achieve real-time, grounded reasoning, we built on a pure Google Gemini stack:

  • Gemini 2.5 Flash — The backbone for all agents, chosen for its low latency and high reasoning capability.
  • Google Search Grounding — Live web search injected into agent context to fetch real-time player form and match-ups.
  • LangGraph — Orchestrates the agents as an explicit state machine with typed state.
  • FastAPI + SSE — Streams agent output character-by-character to the frontend for a "live debate" experience.
  • Next.js — A responsive dashboard for match input and visualization.

Mode 1: The Tactical War Room (LangGraph)

The War Room is modeled as a directed graph where state flows through specialist nodes. Unlike a simple chain, each node has a specific role, system instruction, and tool access.

The Architecture

graph TD
    Start((Start)) --> StatsGuru[Stats Guru]
    StatsGuru --> PitchSpec[Pitch Specialist]
    PitchSpec --> LeadStrat[Lead Strategist]
    LeadStrat --> DevilsAdvocate[Devil's Advocate]
    DevilsAdvocate --> Refiner[Lead Strategist - Refine]
    Refiner --> Commentator[Match Commentator]
    Commentator --> Synthesizer[Report Synthesizer]
    Synthesizer --> End((End))
Enter fullscreen mode Exit fullscreen mode

The "War Room" State

We use a TypedDict to manage the evolving match context. Every agent can read the previous reasoning and append its own analysis.

class WarRoomState(TypedDict):
    match_state: dict
    stats_analysis: str
    pitch_report: str
    strategy_proposal: str
    devils_challenge: str
    strategy_revised: str
    commentary: str
    debate_log: List[Message]
    final_decision: str
    confidence_score: int
Enter fullscreen mode Exit fullscreen mode

Specialized Prompts

Each agent is driven by a high-fidelity system prompt. For example, the Devil's Advocate is explicitly instructed to be relentless:

System Prompt: "You are the 'Devil's Advocate'. Your sole purpose is to find the flaw in the Lead Strategist's plan. You MUST challenge the proposal. Even if it seems sound, find the risk. Angles: 'What if the dew worsens faster?', 'Are we burning our best death bowler two overs too early?'"

And the Stats Guru handles the data grounding:

System Prompt: "You deliver cold, hard cricket analytics. If the striker name is provided, ALWAYS search Google for their recent IPL stats and match-ups. Cite every number you use (e.g., 'SR 145 vs leg-spin in last 5 seasons')."

Physics-Based Win Probability Tool

Before the LLM reasoning begins, we invoke a custom tool to ground the agents in mathematical reality. This prevents "hallucinated optimism."

def calculate_win_probability(innings, over, score, wickets, target, dew):
    # Physics-informed calculation
    projected = current_score + current_rr * overs_remaining
    diff = projected - par_score
    base_prob = 50 + (diff * 0.5)
    wicket_penalty = (10 - wickets_remaining) * 2.5
    return max(5, min(95, base_prob - wicket_penalty))
Enter fullscreen mode Exit fullscreen mode


Mode 2: OASIS Social Simulation

While the War Room is hierarchical, the OASIS mode is emergent. It simulates the social dynamics of a coaching staff.

Stage 1: Dynamic Persona Synthesis

Instead of static roles, we use Gemini to synthesize 3 personas grounded in the specific match context. Chasing a high score in Bangalore? It might generate:

  • Coach Baz: Aggressive, high-risk, "Bazball" philosophy.
  • Data Dravid: Analytical, conservative, focuses on historical averages.
  • Old-School Rao: Spin-wary, respects the "V" and conditions.

Stage 2: The Multi-Round Debate

The simulation runs for 3 rounds. In each turn, the persona reads the entire transcript of the debate so far. This allows for opinion evolution: Data Dravid might concede a point to Coach Baz if the search results show a specific match-up advantage.

Round 1: Initial recommendations.
Round 2: Personas challenge each other's reasoning.
Round 3: Final attempts at consensus or principled dissent.
Enter fullscreen mode Exit fullscreen mode


Walkthrough: The Death Over Dilemma

Let's look at a real scenario: GT vs RR, 17th Over, chasing 190. Rashid Khan on strike.

  1. Stats Guru calls Google Search. Finds Rashid's SR against pace in the last 2 years is 190, but drops to 110 against high-quality leg-spin.
  2. Pitch Specialist notes the dew factor is 8/10. The ball is like a bar of soap.
  3. Lead Strategist proposes bringing on the lead pacer (Bumrah) to "blow him away" with yorkers.
  4. Devil's Advocate intervenes: "Wait! If we burn Bumrah now, who bowls the 20th? Rashid loves pace on the ball. If the pacer misses the yorker by an inch, it's over the ropes. Use the leggie — Rashid's ego will make him hit against the spin into the wind."
  5. Refiner pivots: The Lead Strategist agrees with the risk of "pace on" and decides to hold the pacer back, opting for the spinner with a deep mid-wicket trap.

Result: A decision that factors in player psychology, environmental constraints (dew), and resource management (overs remaining).


Innovation: Why Multi-Agent?

Most cricket AI gives you a number. Captain Cool gives you an argument.

By decomposing the problem into specialist roles (Pitch vs. Stats vs. Strategy) and then pressure-testing it with a Devil's Advocate, we mimic the real-world high-pressure deliberation of a dugout. The use of Google Search Grounding ensures the agents are talking about this version of the player, not their career average from 2018.


Explore the Project

  • Prompt Gallery: View our Agent Prompts in AI Studio (Simulated Link - Prompts are in the repo)
  • Architecture Source: Check out war_room.py and simulation_loop.py for the LangGraph and OASIS implementations.


Built at Build with AI Hackathon, May 2026. Powered by Gemini 2.5 Flash, LangGraph, and a genuine love for IPL cricket.

Top comments (0)