DEV Community

Cover image for 🏏 Captain Cool: The Multi-Agent IPL Match Strategist Built on Google Gemini
GitPhantom700
GitPhantom700

Posted on

🏏 Captain Cool: The Multi-Agent IPL Match Strategist Built on Google Gemini

🏏 "Captain Cool" β€” The Multi-Agent IPL Match Strategist Built on Google Gemini

This is a submission for the Google Gemini Multi-Agent Hackathon! Powered by Google Antigravity and built entirely on the next-generation Google Gemini Stack.


πŸš€ The Vision

In cricket-crazy nations, fans don't just watch the gameβ€”they play the role of "armchair captains," constantly arguing about who should bowl the 19th over, when the strategic timeout should be taken, or how the field should be set.

"Captain Cool" brings this tactical war room to life! It acts as an autonomous virtual IPL Captain, leveraging multiple collaborative Gemini-powered agents to debate the next tactical move in a live match, the way MSD, Rohit, or Gambhir would.

It takes real-time variablesβ€”innings, overs, wickets, pitch type, venue, and dew factorβ€”and outputs a calculated strategy backed by numbers, tested through internal debate, and narrated in poetic cricket language.


πŸ›οΈ Architecture & Multi-Agent Design

A single prompt wearing four hats is not a true multi-agent system. "Captain Cool" runs a stateful, sequential multi-turn debate between four distinct, named Gemini agents powered by gemini-2.5-flash via the official @google/genai SDK:

πŸ›οΈ The Sequential Reasoning Chain

Instead of a single prompt trying to do everything, "Captain Cool" runs a structured, stateful debate loop across four collaborative stages:

  1. πŸ“₯ User Input (Match State): You enter parameters like wickets, score, overs remaining, venue, and pitch images.
  2. πŸ“Š Stats Shastri (The Analyst): Processes the data, triggers the dynamic weather API to assess local Dew Factor, and evaluates historic matchup metrics.
  3. 🧠 Thala Dhoni (The Strategist): Takes Shastri's empirical report and proposes the initial tactical game plan (e.g., bowling Bumrah straight).
  4. πŸ”₯ Gautam Gambhir (Devil's Advocate): Scrutinizes the proposal for high-risk tactical blind spots (e.g., spin slipping on wet dew grass) and issues an intense critique.
  5. 🧠 Thala Dhoni (Rebuttal & Resolution): Dhoni reviews the challenge, adapts or defends his strategy, and locks in the optimal final plan.
  6. πŸŽ™οΈ Harsha Bhogle (Poetic Commentator): Translates the final complex captaincy decision into highly engaging cricket storytelling and vocal commentary.

πŸ› οΈ The Hard Requirements (How We Checked Every Box)

1. Three or More Collaborative Agents

  • πŸ“Š Stats Shastri (The Analyst): The numbers engine. Strictly clinical and quantitative.
  • 🧠 Thala Dhoni (The Strategist): Calm, game-aware mastermind. Proposes simple, impactful strategies.
  • πŸ”₯ Gautam Gambhir (The Devil's Advocate): High-intensity critic. Aggressively challenges Dhoni’s plans to uncover blind spots.
  • πŸŽ™οΈ Harsha Bhogle (The Commentator): The final narrator, turning tactical jargon into beautiful cricket poetry.

2. Live Tool Use (Function Calling)

We implemented three real-world grounding tools that run on our Next.js API server to provide empirical data to the agents:

  • fetch_weather_and_dew_factor: Dynamically calls the Open-Meteo API using coordinates of the target IPL stadium to fetch humidity, temperature, and predict dew factor in real-time.
  • calculate_match_win_probability: A custom mathematical model assessing runs required, wickets remaining, balls remaining, and pitch difficulty.
  • fetch_head_to_head_stats: Performs direct player-vs-player matching on a database of legendary IPL matchups.

3. Multi-Turn Reasoning Loop (The Internal Debate)

When you submit a match state, the server launches the sequential debate. Dhoni proposes, Gambhir dissents, Dhoni addresses the critique in a rebuttal phase, and the consolidated layout is resolved before the commentator ever speaks.

4. Explainability for Casual Fans

The final output is translated by Harsha Bhogle into highly engaging commentary, explicitly detailing the "Why This, Not That" (e.g. why we prioritized Bumrah's length control over Narine's spin mystery under heavy dew).


🌟 5/5 Stretch Goals Achieved!

We didn't just stop at the requirements. We hit all five optional stretch goals:

  1. Real-time mode: A built-in web scraper extracts live match states directly from Cricbuzz URLs using Gemini 2.5 JSON mode.
  2. Voice in/out: The "Listen to Harsha" button uses the browser's Web Speech API to broadcast the final commentary out loud.
  3. Confidence Score & Counterfactuals: Animated circular dials display exact win-probabilities, and Gambhir's critiques provide counterfactual modeling.
  4. Memory Across Overs: The system maintains an internal memory log of previous overs, passing context back into the prompt to ensure a cohesive 20-over strategy.
  5. Multimodal Pitch Image: Users can upload a screenshot of the pitch, which is encoded and passed to Gemini Vision. Stats Shastri literally "looks" at the pitch cracks and grass to adjust his metrics!

πŸ’» Tech Stack

  • Core: Next.js (App Router, Tailwind CSS, TypeScript).
  • AI Engine: Official @google/genai TypeScript SDK.
  • Models: gemini-2.5-flash via Google AI Studio.
  • UI/UX: Glassmorphism dashboard with an interactive SVG Stadium Field mapping and dynamic circular probability gauges.
  • Voice: Web Speech API for TTS synthesis of Harsha's commentary.

πŸŽ™οΈ Deep Dive: The Agent Prompts

πŸ“Š Stats Shastri Prompt

You are "Stats Shastri", a highly clinical, numbers-driven cricket analyst who talks in percentages, head-to-head records, pitch characteristics, boundary sizes, and climate dew risks. Analyze the match situation and give a structured, logical summary of the current numbers. Avoid metaphors.

🧠 Thala Dhoni Prompt

You are "Thala Dhoni", a legendary IPL Captain known as "Captain Cool". You possess ultimate match awareness, cool-headed composure, and deep tactical mastermind capabilities. Propose the single best tactical next step based on match situation and Stats Shastri report. Explain your reasoning in calm, authoritative, captain's language.

πŸ”₯ Gautam Gambhir Prompt

You are "Gautam Gambhir", a fiercely intense, brutally honest, and aggressive cricket mind. You serve as the Devil's Advocate. Your job is to aggressively challenge Thala Dhoni's proposed tactical decision. Point out what Dhoni missed! speak with edge, passion, and tactical grit.

πŸŽ™οΈ Harsha Bhogle Prompt

You are "Harsha Bhogle", the iconic, poetic, and beloved voice of Indian cricket commentary. Translate this intense internal captaincy debate into highly engaging, classic cricket storytelling. Explain the final decision in commentary-style English and details the "Why This, Not That" in an educational way.

πŸ”— AI Studio Prompt Link

Check out our Harsha Bhogle agent prompt directly in Google AI Studio:
View Harsha Bhogle Prompt on Google AI Studio


πŸ“Έ Dashboard Walkthrough (The Wow Factor)

Captain Cool Dashboard Mockup

Live Demo Scenario: CSK vs GT (IPL 2023 Final)

  • Scenario: 10 runs needed off 2 balls, Ravindra Jadeja on strike, Mohit Sharma bowling, Ahmedabad.
  • Stadium Visualizer: Renders short boundaries, pitch strip coloring, and live player strike arrangements.
  • Stats Shastri shows that Jadeja strikes at 129% against Mohit Sharma but has been dismissed twice.
  • Thala Dhoni wants to target the straight boundary.
  • Gautam Gambhir aggressively argues that Mohit will bowl outside off-stump to avoid the leg-side swing, recommending a deep third-man cover.
  • Harsha Bhogle synthesizes this into an epic commentary package!

πŸŽ₯ Watch it in Action!

Here is a recording of our browser session simulating the agent debate:

Captain Cool Agent Debate Demo


πŸš€ How to Run Locally

  1. Clone the Repo:

    git clone https://github.com/GitPhantom700/captian-cool.git
    cd captian-cool
    
  2. Install dependencies:

    npm install
    
  3. Setup your environment:
    Create a .env.local file and add your Google Gemini API key:

    GEMINI_API_KEY=your_gemini_api_key_here
    

    (Security Note: NEVER commit your actual API key to GitHub. The .env.local file is hidden by default. The blog post should only show the placeholder text your_gemini_api_key_here!)

  4. Launch:

    npm run dev
    

    Open http://localhost:3000 on your browser!


Thank you to Google Antigravity and the Gemini Developer team for hosting this exceptional event! Let us know your thoughts on Captain Cool in the comments!

Top comments (0)