DEV Community

ARAV BHUTE
ARAV BHUTE

Posted on

Captain Cool": A Real-Time Multi-Agent AI for T20 Cricket Strategy

Building "Captain Cool": A Real-Time Multi-Agent AI for T20 Cricket Strategy
During a high-stakes T20 cricket match, captains have mere seconds to make game-altering decisions regarding field placements, bowler rotations, and impact players.

For my latest hackathon project, I asked a question: What if an AI could act as a virtual dugout committee?

Instead of relying on a single Large Language Model (LLM) prompt, I built Captain Cool—an autonomous, multi-agent artificial intelligence pipeline that ingests live T20 cricket data and orchestrates a strategic debate to generate dynamic, broadcast-ready match decisions.

Here is a breakdown of the architecture, the tech stack, and the ultimate "boss fight" I had to win against API rate limits to get this live.

🧠 The Multi-Agent Architecture
The core philosophy of Captain Cool is Adversarial AI Debate. If you want good strategy, AI shouldn't just agree with itself; it needs to be stress-tested.

I engineered a sequential pipeline using four distinct agent personas, orchestrated in pure Python using Google's gemini-2.5-flash model:

The Stats Analyst: This agent wields a custom web-scraping tool (built with requests and BeautifulSoup4). It dynamically reads live Cricbuzz/ESPN scorecards, bypassing hardcoded states to feed real-time match data into the system.

The Strategist (Phase 1): Acts as the head coach. It evaluates the Analyst's live report and proposes a concrete tactical move (e.g., "Bring in Arshdeep Singh, bowl wide yorkers").

The Devil’s Advocate: This is the secret weapon. A specialized agent explicitly prompted to be ruthless. It tears apart the Strategist's plan, pointing out missed historical matchups, pitch conditions, or predicting where the batsman will counter-attack.

The Strategist (Phase 2): Forced to ingest the critique, the Strategist must either defend its original plan or revise it (e.g., pulling a fielder into Short Third Man to cover the ramp shot).

The Commentator: Synthesizes the entire internal debate into a high-energy, Harsha Bhogle-style broadcast summary for the end user.

🛠️ The Tech Stack
I intentionally avoided heavy agentic frameworks (like AutoGen or LangChain) to maintain absolute control over the execution loop and minimize latency.

LLM Engine: Google Gemini 2.5 Flash

SDK: Native Google GenAI Python SDK

Orchestration: Pure Python (Zero-dependency pipeline)

Live DOM Parsing: requests & BeautifulSoup4

🧗‍♂️ The Boss Fight: Beating API Rate Limits
Building a multi-agent system looks great on a whiteboard, but deploying it on a free-tier API key is a trial by fire.

Because my pipeline utilizes "Function Calling" (the Analyst executing the web scraper tool), it burns double the API quota—one call to ask Gemini which tool to use, and a second to feed the scraped HTML back into the brain. Because the script ran so efficiently, the four agents fired in rapid succession, instantly slamming into Google's 429 RESOURCE_EXHAUSTED limit.

The Solution: The Pacing Gateway
Instead of abandoning the live web scraper for a hardcoded offline mock, I engineered a Rate-Limit Pacing Gateway.

I wrapped the multi-agent orchestrator loop in an asynchronous execution layer with mandatory time.sleep() cool-downs between agent turns. This distributed the complex multi-turn debate evenly across a rolling 60-second window.

The Result? The agents successfully debated the live match in real-time, completely bypassing the token lockout window without a single dropped exception.

💡 What I Learned
Building Captain Cool taught me that AI is exponentially more powerful when you force it to argue with itself. The most impressive moments during testing weren't when the AI generated a plan—it was when the Devil's Advocate successfully bullied the Strategist into changing its field placements based on live pitch data.

If you are building LLM applications, stop relying on single prompts. Build a committee.

🔗 Links & Resources
Check out the code on GitHub: https://github.com/Arav-Bhute/APL---captain-cool-agent/tree/main

Have you experimented with adversarial AI agents? Drop your thoughts in the comments below!

Author: Arav Bhute

Top comments (0)