<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sanket Maldhure</title>
    <description>The latest articles on DEV Community by Sanket Maldhure (@sanket_maldhure_517e5eb88).</description>
    <link>https://dev.to/sanket_maldhure_517e5eb88</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3936302%2F50b4c708-bc57-49c0-ae8c-289cb2f3894e.png</url>
      <title>DEV Community: Sanket Maldhure</title>
      <link>https://dev.to/sanket_maldhure_517e5eb88</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanket_maldhure_517e5eb88"/>
    <language>en</language>
    <item>
      <title>Building Captain Cool AI: A Multi-Agent IPL Cricket Strategist Powered by Gemini 2.5</title>
      <dc:creator>Sanket Maldhure</dc:creator>
      <pubDate>Sun, 17 May 2026 13:04:33 +0000</pubDate>
      <link>https://dev.to/sanket_maldhure_517e5eb88/building-captain-cool-ai-a-multi-agent-ipl-cricket-strategist-powered-by-gemini-25-5egk</link>
      <guid>https://dev.to/sanket_maldhure_517e5eb88/building-captain-cool-ai-a-multi-agent-ipl-cricket-strategist-powered-by-gemini-25-5egk</guid>
      <description>&lt;h1&gt;
  
  
  🏏 Building "Captain Cool AI": A Multi-Agent IPL Cricket Strategist
&lt;/h1&gt;

&lt;p&gt;Have you ever watched an intense Indian Premier League (IPL) match, seen a team fail to defend 20 runs in the final two overs, and screamed at the TV: &lt;em&gt;"Why on earth did the captain bowl a spinner there?!"&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Cricket is a sport governed by numbers, but won on &lt;strong&gt;tactical psychology, match-ups, and gut feeling&lt;/strong&gt;. In a high-stakes death over, a captain's dressing room is a pressure cooker. &lt;/p&gt;

&lt;p&gt;To recreate this tactical brilliance, I built &lt;strong&gt;Captain Cool AI&lt;/strong&gt; — a high-fidelity, multi-agent strategist system that simulates an intense debate between data analysts, tactical masterminds, contrarians, and legendary commentators to make the ultimate decision in real-time. &lt;/p&gt;

&lt;p&gt;Here is how I built it using &lt;strong&gt;React, FastAPI, and the power of Gemini 2.5 Flash&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 The Multi-Agent Dressing Room (Architecture)
&lt;/h2&gt;

&lt;p&gt;Rather than asking a single LLM to make a decision, &lt;strong&gt;Captain Cool AI&lt;/strong&gt; divides the cognitive load among four specialized agents, each with a custom persona and system instruction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;graph TD
    A[Live Match URL / Offline Scenario] --&amp;gt; B[StatsMaster AI]
    B --&amp;gt;|Calculates Probabilities &amp;amp; Bowler Stats| C[The Strategist - MS Dhoni AI]
    C --&amp;gt;|Proposes 18th Over Bowling Change| D[The Contrarian - Devil's Advocate]
    D --&amp;gt;|Challenges Risks &amp;amp; Offers Alternative| E[Harsha Bhogle AI - Commentator]
    E --&amp;gt;|Synthesizes Debate &amp;amp; Explains Final Decision| F[Premium React Dashboard UI]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. 📊 Agent 1: StatsMaster AI (The Analyst)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Role:&lt;/strong&gt; Objectively crunches the numbers. It calculates required run rates, wickets remaining, and pressure scores.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tools:&lt;/strong&gt; Equipped with Python function tools like &lt;code&gt;calculate_win_probability&lt;/code&gt; and &lt;code&gt;get_bowler_recommendation&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tone:&lt;/strong&gt; Clinical, precise, and completely emotionless.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. 🎯 Agent 2: The Strategist (The Captain)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Role:&lt;/strong&gt; Formulates the actual decision, modeled after &lt;strong&gt;MS Dhoni's&lt;/strong&gt; tactical genius.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Input:&lt;/strong&gt; Analyzes the current match state + StatsMaster's analytical data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tone:&lt;/strong&gt; Decisive, leadership-oriented, and focused on psychology and match-ups.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. 😈 Agent 3: The Contrarian (The Devil's Advocate)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Role:&lt;/strong&gt; Challenges the Strategist’s decision. If the Captain wants to bowl a fast bowler, the Contrarian instantly asks, &lt;em&gt;"But what if the batsman targets the short boundary?"&lt;/em&gt; or &lt;em&gt;"Are you burning your best death bowler too early?"&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tone:&lt;/strong&gt; Skeptical, analytical, and constructive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. 🎤 Agent 4: Harsha Bhogle AI (The Commentator)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Role:&lt;/strong&gt; Acts as the bridge to the audience. It synthesizes the intense dressing-room debate, highlights the tactical trade-offs, and explains the final captain's call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tone:&lt;/strong&gt; Energetic, dramatic, and filled with classic cricket metaphors.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🛠️ The Tech Stack
&lt;/h2&gt;

&lt;p&gt;To provide a premium and production-ready experience, I migrated the original prototype to a modern decoupled stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; &lt;strong&gt;React (Vite)&lt;/strong&gt; styled with a customized glassmorphic dark-mode CSS theme, featuring micro-animations, progress trackers, and beautiful layout grids.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend:&lt;/strong&gt; &lt;strong&gt;FastAPI (Python)&lt;/strong&gt;, utilizing asynchronous routing for high performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI Core:&lt;/strong&gt; &lt;strong&gt;Gemini 2.5 Flash&lt;/strong&gt; using the brand new &lt;code&gt;google-genai&lt;/code&gt; SDK.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🛡️ Building for Production: Resiliency &amp;amp; Quota Fallbacks
&lt;/h2&gt;

&lt;p&gt;One of the coolest technical challenges of this project was handling API rate limits. During heavy testing on the &lt;strong&gt;Gemini Free Tier&lt;/strong&gt;, it’s common to hit the &lt;code&gt;429 Resource Exhausted&lt;/code&gt; quota limit. &lt;/p&gt;

&lt;p&gt;To prevent the web application from crashing or throwing generic errors, I engineered a &lt;strong&gt;dual-layered premium fallback system&lt;/strong&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Smart URL Slug Parser Fallback
&lt;/h3&gt;

&lt;p&gt;If the live match scraping fails because the Gemini API is rate-limited, the backend automatically intercepts the exception, parses the team names out of the URL slug (e.g. &lt;code&gt;kolkata-knight-riders-vs-sunrisers-hyderabad&lt;/code&gt;), and maps them to a database of popular IPL franchises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Extracting teams from Cricinfo/Cricbuzz slugs
&lt;/span&gt;&lt;span class="n"&gt;slug_match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/([^/]+-vs-[^/]+)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url_lower&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;slug_match&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;parts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-vs-|vs&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;slug_match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="c1"&gt;# ... resolves to 'KKR' and 'SRH'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Dynamic Mock Debate Generator
&lt;/h3&gt;

&lt;p&gt;Instead of returning a static, hardcoded fallback response (like a fixed RCB vs CSK text), the system takes the parsed teams, batsmen, and bowlers, and &lt;strong&gt;dynamically injects them&lt;/strong&gt; into a templated debate script. &lt;/p&gt;

&lt;p&gt;If the API key is exhausted and you paste a &lt;code&gt;Mumbai Indians vs Delhi Capitals&lt;/code&gt; match, &lt;strong&gt;the entire simulated debate will dynamically re-render to feature MI and DC players&lt;/strong&gt;, delivering a seamless experience with zero downtime!&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 See It in Action
&lt;/h2&gt;

&lt;p&gt;The user interface was built to give the ultimate first impression. Vibrant dark gradients, interactive toggles to switch between &lt;strong&gt;Offline Simulation&lt;/strong&gt; and &lt;strong&gt;Live URL Scrape Mode&lt;/strong&gt;, and an animated progress bar that lets fans track each agent's thoughts in real-time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1508098682722-e99c43a406b2%3Fauto%3Dformat%26fit%3Dcrop%26w%3D1200%26q%3D80" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1508098682722-e99c43a406b2%3Fauto%3Dformat%26fit%3Dcrop%26w%3D1200%26q%3D80" alt="Captain Cool AI Dashboard Layout" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The live React dashboard showing StatsMaster, The Strategist, The Contrarian, and Harsha Bhogle AI in perfect harmony.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📂 Source Code &amp;amp; Contribution
&lt;/h2&gt;

&lt;p&gt;The complete source code is fully open-source and version-controlled:&lt;/p&gt;

&lt;p&gt;⭐ &lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/sanketmaldhure/ipl-captain-ai-gemini-sanket" rel="noopener noreferrer"&gt;sanketmaldhure/ipl-captain-ai-gemini-sanket&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What are your thoughts on using multi-agent debates for complex decision-making in sports? Let me know in the comments below! 🏏&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>multiagent</category>
      <category>react</category>
      <category>python</category>
    </item>
  </channel>
</rss>
