DEV Community

Gaurav Shinde
Gaurav Shinde

Posted on

Captain Cool: Building an Enterprise Multi-Agent IPL Match Strategist with Google Gemini πŸπŸ†

🌟 Introduction: The High-Stakes World of T20 Cricket
In the ultra-competitive arena of the Indian Premier League (IPL), matches are won and lost in the margins. A single tactical miscalculationβ€”bowling a spinner in the death overs against a power-hitter, misplacing a fielder at cow corner, or misjudging the heavy dew factorβ€”can alter the fate of a championship.

While modern IPL franchises employ armies of data analysts, real-time tactical decision-making in the dugout remains incredibly stressful. Captains must synthesize vast amounts of historical data, pitch conditions, and gut instinct in seconds.

To solve this, we built Captain Coolβ€”an enterprise-grade, virtual IPL captain powered by a multi-agent Google Gemini AI think-tank. Designed for the Google Build with AI Hackathon (#gdgcloudpune), Captain Cool simulates an elite dugout debate in real-time to deliver the ultimate tactical call.

🧠 The Core Innovation: Multi-Agent Debate Loop
Single-prompt LLMs often suffer from "sycophancy"β€”they agree with whatever parameters the user inputs without challenging underlying assumptions. In cricket strategy, blind agreement is a recipe for disaster.

To build a robust tactical engine, Captain Cool implements an advanced Multi-Agent Debate Architecture using four autonomous Gemini 3.1 Flash Lite agents orchestrated via a sequential LangChain-style debate loop:

[ Live Cricbuzz Scraper / Form Input ]
β”‚
β–Ό
πŸ“Š Agent 1: Stats Analyst (Tool Calling)
β”‚
β–Ό
🎯 Agent 2: Strategist (Initial Call)
β”‚
β–Ό
βš”οΈ Agent 3: Devil's Advocate (Dissent & Challenge)
β”‚
β–Ό
πŸ’ͺ Agent 2: Strategist (Revised Defense)
β”‚
β–Ό
πŸŽ™οΈ Agent 4: Match Commentator (Final Verdict & Confidence %)

  1. πŸ“Š The Stats Analyst (Tool-Calling Head) Acting as the head of data intelligence, this agent is equipped with custom JavaScript tools to fetch real-time match context:

getWinProbability(): Calculates dynamic win percentages based on target, balls remaining, and wickets.
getPlayerProfile(): Pulls elite batting/bowling stats (strike rates, death over economy, weakness against spin/pace).
getPitchAssessment(): Evaluates venue history (Wankhede dew, Chepauk turn) and current phase dynamics.

  1. 🎯 The Strategist (Tactical Captain)
    Taking the data report from the Stats Analyst, the Strategist formulates the initial over-by-over plan, selecting the ideal bowler, field placements, and bowling lines.

  2. βš”οΈ The Devil’s Advocate (Opposition Analyst)
    This is where the magic happens. The Devil's Advocate is strictly instructed to act as the opposition head coach. It inspects the Strategist's plan, identifies glaring tactical blind spots (e.g., "You're bowling Bumrah now, but who bowls the 20th over?" or "Kohli loves stepping out to spin, your mid-off is too deep"), and aggressively challenges the captain.

  3. πŸŽ™οΈ The Match Commentator (Broadcast Verdict)
    Finally, the Commentator observes the debate, synthesizes the opposing viewpoints, and delivers an official broadcast-quality verdict complete with a calculated Tactical Confidence Percentage.

πŸš€ Key Technical Features
πŸ”΄ 1. Automated Live Cricbuzz Web Scraper
To ensure the AI operates on absolute real-time data, we built a native Node.js web scraper directly into the Stats Analyst agent.

How it works: When a user pastes a live Cricbuzz match URL, the backend instantly fetches the live HTML, strips out all DOM overhead, extracts the pure live scorecard and commentary text (up to 15KB), and injects it into Gemini's context window.
Absolute Truth: The AI is instructed to treat this scraped live Cricbuzz data as the primary source of truth, overriding any conflicting manual form inputs.
πŸ“ 2. Interactive 2D/3D Fielding Oval
Field placements are critical to T20 bowling plans. We implemented a custom, interactive top-down cricket ground UI directly in the command console.

Users can click anywhere on the grass to place up to 9 fielders.
Using advanced polar coordinate math, the frontend instantly calculates the exact cricket position clicked (e.g., Deep Point, Slips / Gully, Cow Corner, Short Fine Leg).
This exact fielding list is fed into the AI prompts, allowing the agents to analyze physical field gaps and suggest bowling lines to match!
🌌 3. Cinematic 3D Enterprise UI (Vercel/Apple Inspired)
We elevated the application from a standard dashboard into an immersive, executive-grade sports broadcast platform:

Photorealistic Championship Trophy: Replaced cartoon emojis with a hyper-realistic 3D golden championship trophy cup rendered with professional studio lighting.
3D Mouse Parallax: As users move their cursor across the screen, background glassmorphism stat cards (⚑ REQ RATE: 12.5 RPO, 🎯 MATCHUP INTEL) and geometric rings shift at varying speeds, creating a stunning illusion of multi-layered depth.
Auto-Scroll Choreography: Clicking Analyze & Decide ignites a glowing neon progress bar and smoothly auto-scrolls down into the Live Debate Arena, spotlighting each agent card as it slides up with 3D tilt effects.
πŸ› οΈ Tech Stack & Architecture
AI Engine: Google Gemini 3.1 Flash Lite (via @google/genai SDK)
Backend: Node.js, Express.js, native fetch HTML scraping
Frontend: HTML5, Vanilla JavaScript, CSS3 (Glassmorphism, 3D Perspective Transforms, CSS Grid/Flexbox)
Version Control: Git & GitHub
πŸ† Conclusion & Hackathon Journey
Building Captain Cool for the Google Build with AI Hackathon (#gdgcloudpune) was an incredible journey in exploring the power of agentic workflows. By combining tool-calling, multi-agent debate, live web scraping, and premium 3D UI design, we demonstrated how Gemini can transform complex sports analytics into an engaging, real-time decision-making platform.

πŸ”— Check out the Project:
GitHub Repository: https://github.com/gauravshinde2162006-hash/Captain-cool
We would love to hear your thoughts, feedback, and tactical ideas in the comments below! πŸ‘‡

Built with ❀️ for #gdgcloudpune

Top comments (0)