DEV Community

Cover image for Captain Cool:The Multi-Agent IPL Match Strategist
Prajwal Tupe
Prajwal Tupe

Posted on

Captain Cool:The Multi-Agent IPL Match Strategist

Building "Captain Cool": An AI-Powered IPL Match Strategist

Cricket, particularly the high-octane IPL T20 format, is a game of fine margins. A single tactical decision—who bowls the 19th over, when to deploy the Impact Player, or how to counter a left-handed power hitter on a turning track—can change the course of a match. Behind these decisions is a captain who thinks two overs ahead, absorbing data and intuition in real-time.

But what if we could replicate this decision-making process using Generative AI?

Enter Captain Cool, a multi-agent orchestration pipeline built with the Google Gemini model and the official Google GenAI SDK.

In this post, we’ll dive into how we built an AI system that acts as an elite IPL strategist, debating tactical moves in a simulated "coaching staff" environment before making the final call.


The Architecture: A Three-Agent Coaching Staff

To mimic the intense debate in a cricket dugout, we designed a three-agent architecture where AI agents communicate sequentially to form a final strategy.

1. The Stats Analyst 📊

Data is the backbone of modern T20 cricket. The Stats Analyst agent is responsible for consuming the real-time match state (e.g., "16th over, 145/3, heavy dew") and utilizing Tool Calling.

We equipped the Analyst with Python functions (fetch_historical_stats and fetch_live_match_data). When prompted, the Gemini model automatically knows when to invoke these tools, fetching mock data like MS Dhoni’s strike rate or the current win probability. It then synthesizes a purely data-driven report without making any actual strategic calls.

2. The Strategist (Captain Cool) 🧠

Armed with the Analyst's data, the Strategist takes the stage. Prompted to embody the calm, calculated persona of legendary IPL captains like MS Dhoni or Rohit Sharma, this agent proposes a single tactical move.

Crucially, we employed strict prompt engineering here: the agent is instructed to use authentic cricket terminology ("bowling into the pitch", "matchups", "taking the game deep") and explicitly forbidden from using generic AI jargon.

3. The Devil’s Advocate 👿

No strategy is foolproof. To ensure robustness, we introduced the Devil’s Advocate. This agent acts as a highly critical assistant coach whose sole job is to aggressively challenge the Strategist's proposal. It looks for counter-matchups, momentum risks, and potential pitfalls in the plan.

The Final Call 🏆

Finally, the loop returns to the Strategist, who evaluates the Devil’s Advocate’s critique. Like a true captain, it decides whether to stick to its guns or pivot, providing the final cricket logic behind the move.


Handling the Chaos: Resiliency and UX

Building AI pipelines comes with challenges, notably API rate limits and network instability. To counter this, we integrated the tenacity library, wrapping our API calls in robust exponential backoff retries. If the Gemini API hits a rate limit, the system gracefully pauses and retries, ensuring the pipeline doesn't crash mid-debate.

On the user experience front, we utilized the rich Python library. Instead of a boring wall of text, users interact with a beautifully formatted CLI. Colored panels represent each agent's turn, and spinner animations keep the user engaged while the AI "crunches the numbers."

Why Gemini 2.5 Pro / Flash?

For an interactive application like this, speed is just as important as intelligence. We chose Gemini because it offers the perfect balance: it's fast enough to keep the CLI feeling responsive in real-time while possessing the deep reasoning capabilities required for complex tool calling and contextual multi-agent debate.

The Result

The end result is an incredibly fun, dynamic tool that genuinely feels like you are sitting in an IPL dugout in 2026. You feed it a stressful match scenario, and it gives you a data-backed, heavily debated, and authentically phrased tactical masterplan.

Developed for GDG APL Pune 🚀

This project was built and showcased as part of the GDG APL Pune event. A huge shoutout to the @gdgcloudpune community for organizing such an incredible platform for developers to push the boundaries of Generative AI and share real-world implementations.

If you were at the event, let’s connect in the comments and discuss how you’re leveraging multi-agent systems!

Top comments (0)