DEV Community

Vaishnavi Bardapure
Vaishnavi Bardapure

Posted on

🏏 Building "Captain Cool": A Multi-Agent IPL Strategist with Google Gemini

Cricket is a captain's game. The margin between an IPL trophy and crashing out in the playoffs is often a single, split-second tactical decision: who bowls the 19th over? Do you bring in the spinner against the left-hander? What happens when the dew sets in?

For the APL GDG Hackathon, I wanted to simulate the high-pressure environment of an IPL dugout. I built Captain Cool β€” a Multi-Agent AI System powered entirely by the Google Gemini stack that debates and makes real-time tactical cricket decisions.

Here is how I built it.


πŸ—οΈ The Architecture (The Coaching Staff)

To make this truly agentic, one LLM call wasn't going to cut it. A real captain doesn't operate in a vacuumβ€”they rely on data analysts and vice-captains.

Using Google GenAI SDK and the blazing fast gemini-2.5-flash model, I orchestrated a 3-agent debate loop:

  1. πŸ“Š The Stats Analyst: This agent doesn't guess. It uses Gemini Function Calling to hit my custom Python tools (get_player_stats, get_venue_stats) to pull raw numbers on strike rates, matchups, and pitch conditions based on the live match state.
  2. 🧠 The Strategist (The Captain): Takes the raw match state and the Analyst's data to propose the next tactical move.
  3. βš–οΈ The Devil's Advocate (The Vice-Captain): This is where the magic happens. The Vice-Captain is explicitly prompted to find flaws in the Captain's plan, highlight contrarian angles (like dew factor), and prevent groupthink.

The Captain then takes the critique, revises or defends the plan, and makes the Final Call.

graph TD
    M[Live Match State] --> A(Stats Analyst)
    A -->|Function Calling| D[(Cricket Stats API)]
    D -->|Stats| A
    A -->|Stats Summary| S(Strategist - Captain)
    M --> S
    S -->|Initial Proposal| V(Devil's Advocate)
    V -->|Critique & Risks| S
    S -->|Final Decision| O[Final Output UI]
Enter fullscreen mode Exit fullscreen mode

πŸ—£οΈ The System Prompts

The secret sauce to getting authentic cricket commentary rather than generic ML jargon was in the System Prompts.

The Captain's Prompt:

"You are 'Captain Cool', an elite IPL match strategist (think MS Dhoni or Rohit Sharma). You will receive the current match state and a data summary from your Stats Analyst. Your task is to make the next tactical decision: e.g., who should bowl the next over, field placement, bringing in the Impact Player, etc. Explain your reasoning in authentic cricket terminology. Be decisive and clear in your proposal."

The Vice-Captain's Prompt:

"You are the Devil's Advocate (Vice-Captain) of an IPL team. Your job is to listen to the Captain's tactical proposal and find the flaws in it. Look for contrarian angles: what if the pitch is behaving differently? What if the matchups are misleading? What about dew? Suggest a smart alternative or highlight the primary risk of the Captain's plan. Speak in sharp, analytical cricket terms."


🏏 Walkthrough: An End-to-End Match Scenario

Let's look at how the agents handle a classic death-overs scenario:

The Setup:

  • Innings: 2nd Innings (Run Chase)
  • Score: 145/4 (Over 17.5) | Target: 175
  • Matchup: RCB (Batting) vs MI (Bowling)
  • At the Crease: Virat Kohli (55 off 38) & Dinesh Karthik (12 off 8)
  • Bowling Options: Hardik Pandya is finishing his spell. Jasprit Bumrah has 1 over left.
  • Conditions: Wankhede Stadium. Heavy dew is setting in.

(Insert a screenshot of the Streamlit UI Match Config here!)

The Debate Unfolds:

  1. πŸ“Š Stats Analyst: Pulls data via tools. Highlights that Kohli is vulnerable to left-arm pace outside off, but dominates spin. Bumrah has a 7.8 death overs economy and a massive 82.3% yorker accuracy, having dismissed Kohli 4 times. Wankhede has a heavy dew factor which makes gripping the ball difficult.
  2. 🧠 Captain (Initial Plan): Suggests bringing Bumrah in immediately for the 18th over to get Kohli out before he can launch in the 19th and 20th. Keep Pandya out of the attack.
  3. βš–οΈ Vice-Captain (Critique): "Hold on skip. With the heavy dew, the ball is going to resemble a bar of soap. If Bumrah bowls the 18th, who bowls the 19th and 20th? We risk saving our weaker bowlers for the final overs when the dew is at its absolute worst. We need Bumrah for the 19th."
  4. πŸ† Final Call: The Captain agrees with the critique. "Fair point. The dew is a massive factor. We bowl Akash Madhwal for the 18th over, stack the off-side to force Kohli to hit against the spin of the wet ball, and save Bumrah's yorkers for the crucial 19th over."

(Insert a screenshot of the Chat UI showing the final decision here!)


πŸ› οΈ The Tech Stack & Google Integration

  • Model: gemini-2.5-flash for lightning-fast, multi-turn reasoning.
  • SDK: Google GenAI Python SDK (google-genai).
  • Tool Use: Native Gemini Function Calling hooked into a custom Python dictionary of IPL stats.
  • IDE: Vibe-coded entirely inside Google Antigravity (Google's agentic IDE).
  • UI & Hosting: Built with Streamlit and deployed live on Streamlit Community Cloud.

πŸ† Conclusion

By breaking the problem down into a multi-agent system, the AI was forced to self-correct and consider environmental factors (like dew and bowler workload) that a single zero-shot prompt usually misses.

Check out the live app here: (Insert your Streamlit Cloud URL here!)
Check out the code on GitHub: github.com/VaishnaviBardapure/CaptainCool

Built for the APL GDG Hackathon.

GDGCLOUDPUNE

Top comments (0)