DEV Community

Hemant Choudhary
Hemant Choudhary

Posted on

Captain Cool AI โ€” Building a Multi-Agent IPL Tactical Engine with FastAPI, Next.js & Gemini AI ๐Ÿš€๐Ÿ

Introduction

What if an AI could think like an IPL captain during a high-pressure chase?

That idea led me to build Captain Cool AI โ€” a multi-agent cricket strategy engine inspired by the calm tactical mindset of legendary IPL captains.

The system analyzes match situations, debates strategies internally using multiple AI agents, and finally generates tactical recommendations in real-time.

This project combines:

FastAPI backend
Next.js frontend
Gemini AI
Multi-agent architecture
Cricket analytics
Tactical reasoning
The Idea ๐Ÿ’ก

During a T20 chase, captains constantly make decisions like:

Should we attack or rotate strike?
Which bowler should be targeted?
How does dew affect spin?
Should we preserve wickets?

Instead of using a single AI response, I designed a multi-agent workflow where different agents think independently before making a final decision.

Multi-Agent Architecture ๐Ÿง 

The system contains 5 specialized AI agents:

  1. Stats Analyst

Analyzes:

Required run rate
Batter matchups
Pitch behavior
Historical trends
Dew factor

  1. Strategist

Creates the tactical plan:

Batting intent
Over-by-over approach
Bowler targeting strategy

  1. Devilโ€™s Advocate

Challenges the proposed strategy:

Risks
Weaknesses
Failure possibilities
Alternate viewpoints

  1. Decision Maker (Captain Cool)

Acts like the final captain:

Evaluates all viewpoints
Makes final tactical call
Assigns confidence score
Suggests backup plan

  1. Match Commentator

Explains the decision in a commentator-style narrative.

Tech Stack โš™๏ธ
Frontend
Next.js
React
Tailwind CSS
Axios
Backend
FastAPI
Python
Pydantic
AI
Gemini AI API
Backend Architecture ๐Ÿ”ฅ

The FastAPI backend exposes 3 main routes:

POST /analyze
POST /debate
POST /decision
/analyze
Generates statistical analysis
Produces strategic proposal
/debate
Devilโ€™s Advocate critiques strategy
/decision
Final tactical decision
Confidence score
Backup strategy
Commentary generation
Cricket Intelligence Layer ๐Ÿ

I created custom cricket insight tools such as:

lookup_venue_average_score()
get_batter_vs_bowler_matchup()
analyze_phase_economy()

These simulate:

Venue behavior
Batter matchups
Dew impact
Pitch conditions
Frontend UI ๐ŸŽจ

The UI was designed to feel like:

An IPL tactical dashboard
A captainโ€™s strategy room
Real-time match intelligence panel

Features include:

Match context input
Tactical strategy generation
Multi-agent output display
Confidence indicators
Commentary section
Biggest Challenges ๐Ÿ˜…

  1. Python Import Errors

Initially faced:

ModuleNotFoundError

Solved using:

Proper project structure
init.py
Correct uvicorn execution path

  1. API Connection Issues

Frontend was unable to connect to backend because of:

Wrong API URLs
CORS configuration
Incorrect localhost routing

Solved by:

CORSMiddleware

and proper API base configuration.

  1. Gemini API Quota Limits

The Gemini free tier rate limits caused:

429 RESOURCE_EXHAUSTED

To handle this:

Added fallback strategies
Optimized prompts
Used lighter models for faster responses
What Makes This Project Unique? ๐Ÿš€

Unlike basic AI chat apps, this system:

Simulates collaborative AI reasoning
Uses debate-driven decision making
Mimics real IPL tactical analysis
Produces explainable strategies

Itโ€™s closer to a real AI coaching engine than a chatbot.

Future Improvements ๐Ÿ”ฎ

Planned upgrades:

Real-time IPL API integration
Ball-by-ball live prediction
Win probability engine
Voice commentary
Captain personality modes
Agent memory system
Final Thoughts โค๏ธ

Building this project taught me:

Multi-agent system design
Backend/frontend integration
AI orchestration
Prompt engineering
FastAPI architecture
Real-world debugging under pressure ๐Ÿ˜„

This was one of the most exciting AI projects Iโ€™ve built so far.

GitHub Repository
https://github.com/HemantXCode/captain-cool-ai
Conclusion

AI is no longer just about generating text.

The future is collaborative AI systems where multiple agents reason together to solve complex problems.

And cricket strategy turned out to be a perfect playground for experimenting with that idea.

๐Ÿ๐Ÿ”ฅ @gdgcloudpune , @antrixsh_gupta , @pratik_kale #gdgcloudpune

Top comments (0)