DEV Community

Suswagata Chakraborty
Suswagata Chakraborty

Posted on

Building an AI-Powered Multi-Agent IPL Match Strategist with Streamlit and Gemini

@gdgcloudpune

Cricket, especially the fast-paced T20 format of the IPL, is a game of quick decisions, intense pressure, and strategic gambles. What if you could bring the analytical power of a professional dugout right to your screen?

In this post, we’ll dive into The Multi-Agent IPL Match Strategist, an MVP built using Python, Streamlit, and Google Gemini, to simulate real-time cricket tactics through multi-agent debate.


🏗️ Architecture Overview

The application utilizes a lightweight, serverless architecture centered around Streamlit and Google's Gemini LLM. Instead of spinning up multiple different LLM calls for each "Agent," we use a single, highly structured prompt to generate a simulated debate in one pass, drastically reducing latency.

flowchart TD
    User([🏏 User Input: Match Context]) --> Streamlit[Streamlit Frontend]
    Streamlit --> Backend[Python Backend logic]

    Backend -->|Compiles Context & Prompt| Gemini[Google Gemini API <br> gemini-2.5-flash]

    Gemini -->|Generates JSON Response| Parser[JSON Parser]

    Parser -->|Agent 1| Strategist[🧠 Core Strategist]
    Parser -->|Agent 2| Advocate[😈 Devil's Advocate]
    Parser -->|Agent 3| Captain[👨‍✈️ Captain Final Call]
    Parser -->|Metric| WinProb[📈 Win Probability]

    Strategist --> StreamlitUI[Streamlit Interactive Dashboard]
    Advocate --> StreamlitUI
    Captain --> StreamlitUI
    WinProb --> StreamlitUI
Enter fullscreen mode Exit fullscreen mode

📝 The Multi-Agent Prompt

To make the AI simulate a "virtual dugout," we instruct the model to adopt multiple personas simultaneously and output the debate as a structured JSON object.

Here is the exact master prompt that orchestrates our agents:

You are simulating an IPL tactical dugout consisting of multiple AI agents analyzing the following match situation:
- Batting Team: {batting_team}
- Bowling Team: {bowling_team}
- Score: {score} in {overs} overs
- Target/Runs Needed: {runs_needed} from {balls_left} balls (Wickets left: {wickets_left})
- Batters at Crease: {striker} (Striker) & {non_striker} (Non-Striker)
- Pitch: {pitch_type}
- Dew Factor: {dew_factor}
- Captain Personality for Final Decision: {captain_personality}

Generate a short, tactical, and realistic response in JSON format. The JSON must contain exactly these keys:
"win_probability": (A percentage string representing the bowling team's chance, e.g. "62%")
"win_prob_float": (A float between 0.0 and 1.0 representing the bowling team's chance)
"strategist": (1-2 sentences of tactical advice from the Core Strategist, focusing on bowling/fielding changes)
"advocate": (1-2 sentences from the Devil's Advocate countering the strategist's idea)
"decision": (1-2 sentences from the Captain, reflecting the selected {captain_personality} personality, making the final call)

Respond ONLY with valid JSON. Do not include markdown formatting like ```

json.


Enter fullscreen mode Exit fullscreen mode

Try it out in Google AI Studio!

You can easily adapt and test this exact prompt directly in Google AI Studio to experiment with different agent personalities and match contexts before writing any code.

🏏 Walkthrough: A Live Match Scenario

Let's put the app to the test with a classic IPL nail-biter.

The Situation:

  • Batting: MI
  • Bowling: CSK
  • Score: 154/4 in 16.2 overs
  • Equation: MI needs 36 runs from 22 balls.
  • Required Run Rate (RRR): 9.82
  • Crease: Suryakumar Yadav (Striker) and Tim David (Non-Striker)
  • Conditions: Turning pitch, but Dew is present.
  • Captain Personality selected: Dhoni

The App's Output:

  1. 📈 Win Probability: 45% (Advantage tilts slightly to MI because SKY is on strike and dew makes gripping the ball harder)
  2. 🧠 Core Strategist: "Bring in your best spinner to exploit the turning pitch against Tim David if he gets on strike, but keep the pacers bowling wide yorkers to Suryakumar Yadav to deny him his sweep shots."
  3. 😈 Devil's Advocate: "With heavy dew on the field, gripping the ball for spin is incredibly risky. A wet ball might result in full tosses which SKY will easily lap over fine leg. Stick to pace off the ball."
  4. 👨‍✈️ Final Decision (Dhoni Mode): "We will trust the spinner for one over but pack the leg-side boundary deep. If the ball slips, we immediately shift to defensive wide pace. Keep it simple, don't panic."

🚀 The Tech Stack & Features

To build this quickly and beautifully, we used:

  • Streamlit: For the frontend. It allowed us to build a responsive, interactive UI entirely in Python. We utilized Streamlit's layout columns and custom CSS to create a sleek, dark-themed "cricket scoreboard" aesthetic.
  • Google Gemini API (gemini-2.5-flash): The brain of the operation. We chose Gemini 2.5 Flash for its blazing-fast response times.
  • Dynamic UI:
    • Smart dropdowns ensure you can't select the same player as both Striker and Non-Striker.
    • Required Run Rate (RRR) calculates instantly as you type in runs and balls left.

Whether you're an AI enthusiast looking to explore prompt engineering or a cricket fan wanting to second-guess your favorite captain, this project demonstrates the incredible potential of LLMs in building interactive, simulation-based applications.

Top comments (0)