ๆƒฏๆ€ง่šๅˆ ้ซ˜ๆ•ˆ่ฟฝ่ธชๅ’Œ้˜…่ฏปไฝ ๆ„Ÿๅ…ด่ถฃ็š„ๅšๅฎขใ€ๆ–ฐ้—ปใ€็ง‘ๆŠ€่ต„่ฎฏ
้˜…่ฏปๅŽŸๆ–‡ ๅœจๆƒฏๆ€ง่šๅˆไธญๆ‰“ๅผ€

ๆŽจ่่ฎข้˜…ๆบ

N
Netflix TechBlog - Medium
็ฝ—
็ฝ—็ฃŠ็š„็‹ฌ็ซ‹ๅšๅฎข
H
Help Net Security
I
Intezer
G
Google Developers Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Troy Hunt's Blog
่ฎฉๅฐไบงๅ“็š„็‹ฌ็ซ‹ๅ˜็Žฐๆ›ด็ฎ€ๅ• - ezindie.com
่ฎฉๅฐไบงๅ“็š„็‹ฌ็ซ‹ๅ˜็Žฐๆ›ด็ฎ€ๅ• - ezindie.com
U
Unit 42
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
้’›ๅช’ไฝ“๏ผšๅผ•้ข†ๆœชๆฅๅ•†ไธšไธŽ็”Ÿๆดปๆ–ฐ็Ÿฅ
้’›ๅช’ไฝ“๏ผšๅผ•้ข†ๆœชๆฅๅ•†ไธšไธŽ็”Ÿๆดปๆ–ฐ็Ÿฅ
N
News and Events Feed by Topic
J
Java Code Geeks
S
Security Affairs
T
The Blog of Author Tim Ferriss
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
The GitHub Blog
The GitHub Blog
F
Full Disclosure
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs
่…พ
่…พ่ฎฏCDC
ไบบไบบ้ƒฝๆ˜ฏไบงๅ“็ป็†
ไบบไบบ้ƒฝๆ˜ฏไบงๅ“็ป็†
M
MIT News - Artificial intelligence
Blog โ€” PlanetScale
Blog โ€” PlanetScale
T
Threatpost
D
DataBreaches.Net
Recent Announcements
Recent Announcements
ๅš
ๅšๅฎขๅ›ญ - ไธ‰็”Ÿ็ŸณไธŠ(FineUIๆŽงไปถ)
MongoDB | Blog
MongoDB | Blog
ๅš
ๅšๅฎขๅ›ญ - ใ€ๅฝ“่€็‰นใ€‘
L
LINUX DO - ๆœ€ๆ–ฐ่ฏ้ข˜
Google Online Security Blog
Google Online Security Blog
S
Schneier on Security
S
Securelist
ๅฅ‡ๅฎขSolidotโ€“ไผ ้€’ๆœ€ๆ–ฐ็ง‘ๆŠ€ๆƒ…ๆŠฅ
ๅฅ‡ๅฎขSolidotโ€“ไผ ้€’ๆœ€ๆ–ฐ็ง‘ๆŠ€ๆƒ…ๆŠฅ
Help Net Security
Help Net Security
P
Proofpoint News Feed
Project Zero
Project Zero
S
SegmentFault ๆœ€ๆ–ฐ็š„้—ฎ้ข˜
H
Hackread โ€“ Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
ๅฎ็މ็š„ๅˆ†ไบซ
ๅฎ็މ็š„ๅˆ†ไบซ
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
ๅš
ๅšๅฎขๅ›ญ - ๅถๅฐ้’—

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Donโ€™t Fail โ€” They Drift Spilling beans for how i learn for exam๐Ÿ˜"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" โ€” What Actually Happened Comfy Cloudโ€™s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions โ€” here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components โ€” Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cรณmo construรญ un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 ๐Ÿš€ I Built an Ethical Hacking Scanner Tool โ€“ Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points โ€” Here's What I Found About How Markets Really Move EcoTrack AI โ€” Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead โ€” I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve โ€” no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like Youโ€™re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace โ€” how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025โ€“62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D โ€” A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent โ€” It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly โ€” 2026/04/10โ€“04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI ้€ฑๅ ฑ โ€” 2026/04/10โ€“2026/04/17 ๆจกๅž‹ๅฐ้Ž–ๆฝฎไพ†ไบ†๏ผŒไฝ†ๅทฅๅ…ท้ˆๆ‰ๆ˜ฏ็œŸๆˆฐๅ ด Maybe this is how Open-Source apps are born... ๐Ÿš€ Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge โ€” $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase โ€” Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train โ€” Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extraรงรฃo de Vรญdeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life โ€” Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 โ€” Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows โ€” Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTrackingๅฎ‰่ฃ…ๅ’ŒiPhone้ขๆ•้…็ฝฎๆ•™็จ‹๏ผŒๆœ‰bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
# ๐Ÿ Captain Cool: How I Built a Multi-Agent IPL Strategist on Gemini in 3 Hours
Shreyas Nala ยท 2026-05-17 ยท via DEV Community

๐Ÿ Captain Cool: How I Built a Multi-Agent IPL Strategist on Gemini in 3 Hours

"Cricket is not just a sport. It's a chess match at 140 km/h." โ€” and now, it has an AI captain.

title: "๐Ÿ Building \"Captain Cool\": A Multi-Agent IPL Cricket Strategist Powered by Google Gemini & FastAPI"
published: true
tags: python, gemini, ai, webdev
canonical_url: https://dev.to/shreyasn01/building-captain-cool-a-multi-agent-ipl-cricket-strategist-powered-by-google-gemini-fastapi-3ad1

cover_image: https://raw.githubusercontent.com/ShreyasN01/Captain-Cool-Agent/main/readme_banner.png

The Problem: Cricket Decisions Happen in Seconds

๐Ÿ Building "Captain Cool": A Multi-Agent IPL Cricket Strategist Powered by Google Gemini & FastAPI

A T20 captain makes 10โ€“15 high-stakes tactical calls every match โ€” who bowls the death over, when to bring in the Impact Player, whether to attack or defend against a left-hander on a dew-soaked pitch. These decisions carry the weight of a franchise's season, and they have to be made in under 30 seconds.
What if you had a virtual IPL cricket captain sitting in your dugout, making real-time tactical decisions like MS Dhoni, Rohit Sharma, or Hardik Pandya?
I wanted to build something that could replicate that cognitive pressure โ€” not just with a chatbot wrapper, but with genuine agent debate, tool use, and cricket-grade explainability.
In cricket, the best captains don't just rely on gut feeling or raw stats alone. They look at the weather, analyze head-to-head match-ups, calculate win probabilities, and debate tactics with their coaching staff before making a call.
The result: Captain Cool โ€” a multi-agent IPL strategist built entirely on Google Gemini. Here's how it works, and how I built it in 3 hours.

To replicate this, I built Captain Cool โ€” an agentic AI system that orchestrates a 5-turn debate between four specialized AI agents to deliver real-time, context-aware tactical decisions during a live IPL match.

Here is a deep dive into how I built it using the Google Gemini 2.5 Flash, FastAPI (Server-Sent Events), and a mobile-first stadium-themed UI.

Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        USER INPUT                           โ”‚
โ”‚   (innings, over, score, wickets, pitch, bowlers, etc.)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                        โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚    STATS ANALYST        โ”‚  โ† Tool call: live cricket API
          โ”‚  (Gemini 2.5 Flash)     โ”‚     / win-probability model
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ enriched context
                      โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚      STRATEGIST         โ”‚  โ† Proposes the next decision
          โ”‚  (Gemini 2.5 Pro)       โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ initial proposal
                      โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚   DEVIL'S ADVOCATE      โ”‚  โ† Challenges with counter-strategy
          โ”‚  (Gemini 2.5 Flash)     โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ pushback
                      โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚      STRATEGIST         โ”‚  โ† Defends or revises
          โ”‚   (multi-turn loop)     โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚ final call
                      โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚   MATCH COMMENTATOR     โ”‚  โ† Translates to fan-friendly language
          โ”‚  (Gemini 2.5 Flash)     โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
             ๐ŸŽ™๏ธ FINAL OUTPUT
     Decision + Reasoning + Dissent

Enter fullscreen mode Exit fullscreen mode

Four named agents. One real tool call. A genuine back-and-forth debate. Let me walk through each.

The Four Agents

๐Ÿ—๏ธ The Multi-Agent Architecture

1. Stats Analyst ๐Ÿ“Š

Role: Enrich the raw match state with historical and real-time context.
Rather than asking a single LLM to make a decision, Captain Cool uses a cooperative multi-agent debate loop where agents challenge and refine each other's ideas:
System Prompt:

You are a professional cricket data analyst. Given a match state, your job is to:
1. Call the get_player_stats tool to fetch relevant bowler/batter matchup data.
2. Estimate the current win probability based on run rate, wickets, and overs remaining.
3. Identify any pitch or weather factors that statistically affect outcomes.
Return structured JSON with enriched context for the Strategist.
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               Captain Cool โ€” 5-Turn Debate               โ”‚
โ”‚                                                          โ”‚
โ”‚  ๐Ÿ“Š Stats Analyst  โ†’  Real function calling              โ”‚
โ”‚     โ†“ Stats Report (live weather + player stats)         โ”‚
โ”‚  ๐Ÿง  Strategist v1  โ†’  Proposes tactical call             โ”‚
โ”‚     โ†“                                                    โ”‚
โ”‚  ๐Ÿ˜ˆ Devil's Advocate โ†’ Challenges the call               โ”‚
โ”‚     โ†“                                                    โ”‚
โ”‚  ๐Ÿง  Strategist v2  โ†’  Revises or defends                 โ”‚
โ”‚     โ†“                                                    โ”‚
โ”‚  ๐ŸŽ™๏ธ Commentator    โ†’  Fan-friendly final verdict          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Enter fullscreen mode Exit fullscreen mode

Tool used: get_player_stats โ€” a Gemini function-calling tool that fetches recent form, economy rates, and head-to-head matchup stats from a cricket stats API.

Here are the 4 named agents and their roles:

1. ๐Ÿ“Š The Stats Analyst (The Tool Caller)

The Analyst has no opinions. It is completely data-driven. Using Gemini's Native Function Calling (Tools), it automatically fetches:

  • Live Weather Data: Real-time relative humidity, dew spread, and temperature using the Open-Meteo API.
  • IPL Player Stats: Granular batting/bowling statistics.
  • Match-up Data: Head-to-head records (e.g., batsman vs. bowler).
  • Win Probability: Computed using a run-rate sigmoid model. ### 2. Strategist ๐Ÿง  Role: The captain's brain. Proposes the next tactical move. ### 2. ๐Ÿง  The Strategist (The Captain's Brain) Runs twice in the debate. Its system prompt changes dynamically depending on your selected captain persona:
  • Dhoni Style ๐ŸงŠ: Ice-cool, calculated, defensive risk management.
  • Rohit Style โšก: Aggressive, matchup-focused, chasing wickets.
  • Hardik Style ๐Ÿ”ฅ: Bold, instinctual, backing high-risk impact plays. System Prompt:
You are an IPL captain with the strategic instincts of Dhoni, the aggression awareness of Rohit, 
and the situational reading of Hardik Pandya. Given the match state and analyst context, 
propose ONE specific tactical decision for the next over. 
Explain your reasoning in cricket language โ€” not data science jargon.
Format: DECISION | REASONING | CONFIDENCE (%)

Enter fullscreen mode Exit fullscreen mode

3. ๐Ÿ˜ˆ The Devil's Advocate (The Challenger)

This agent's sole job is to tear the Strategist's plan apart. It looks for weaknesses, critiques bowling choices, and warns of dew factors or batting depth.
The Strategist receives the enriched match state and outputs a clear, cricket-literate proposal โ€” e.g., "Bring Bumrah back for the 18th. Powerplay's over, pitch has slowed, and their 4-down batter has a 42% dot-ball rate against length deliveries outside off."

4. ๐ŸŽ™๏ธ The Commentator (The Synthesizer)

Takes the entire debate, synthesizes it, and delivers a final verdict in pure, colorful cricket language along with an overall tactical Confidence Score (%).

3. Devil's Advocate ๐Ÿ˜ˆ

Role: Challenges the Strategist's call. Argues for the alternative.

๐Ÿ› ๏ธ The Tech Stack

System Prompt:

You are a contrarian cricket analyst. Your ONLY job is to find the strongest possible 
argument AGAINST the Strategist's proposed decision. You must:
- Propose a specific alternative
- Give cricket-language reasoning for why it's better
- Call out any risks the Strategist may have overlooked
Be sharp, specific, and grounded in the match state. Not for the sake of argument โ€” 
for the sake of winning the match.

Enter fullscreen mode Exit fullscreen mode

  • AI Engine: gemini-2.5-flash using the new official google-genai Python SDK.
  • Backend: FastAPI serving SSE (Server-Sent Events) to stream the debate in real-time.
  • Frontend: Vanilla HTML5/JS styled with Tailwind CSS and custom CSS (Intensity Design System: HSL orange/gold gradients, obsidian surfaces, and Sora typography). This is where it gets interesting. The Devil's Advocate doesn't just poke holes โ€” it proposes a concrete alternative. If the Strategist says "bowl Bumrah", the Devil's Advocate might say: "Bumrah's already bowled 3 overs on this pitch. He's shown his hand. Bring in the leggie โ€” they haven't faced him yet, and he gets more turn at this end." --- ### 4. Match Commentator ๐ŸŽ™๏ธ Role: Translates the final decision into broadcast-quality cricket commentary. ## ๐Ÿ’ก Code Highlights System Prompt:
You are a seasoned IPL commentator. You've just heard the captain's final tactical decision 
and the internal debate that led to it. Your job:
1. Announce the decision like you're on Star Sports.
2. Explain the reasoning in a way a casual fan understands.
3. Mention what the dissenting view was โ€” and why the captain overruled it.
Keep it punchy, warm, and cricket-smart. No ML terms. No percentages in the output.

Enter fullscreen mode Exit fullscreen mode

โšก Dynamic Tool Wrapper (Capturing Gemini Function Calls)

When using Gemini's automatic_function_calling=True, the intermediate tool execution logs are handled under the hood. To report exactly which tools were called back to our frontend UI, I implemented a dynamic Python decorator that intercepts and logs tool executions on the fly:

tool_calls_log = []
## The Multi-Turn Reasoning Loop
# Intercept tool calls dynamically to record them for the UI
def wrap_tool(fn):
    def wrapper(*args, **kwargs):
        tool_calls_log.append({
            "tool": fn.__name__,
            "args": kwargs if kwargs else (args[0] if args else {})
        })
        return fn(*args, **kwargs)
    wrapper.__name__ = fn.__name__
    wrapper.__doc__ = fn.__doc__
    wrapper.__annotations__ = fn.__annotations__
    return wrapper
This is the part I'm most proud of. The debate isn't cosmetic โ€” it actually changes the output.
Here's the flow in code terms:

Enter fullscreen mode Exit fullscreen mode


javascript
// Round 1: Strategist proposes
const proposal = await strategistAgent.generate(matchState + analystContext);
// Round 2: Devil's Advocate challenges
const challenge = await advocateAgent.generate(matchState + proposal);
// Round 3: Strategist revises or defends
const finalCall = await strategistAgent.generate(
matchState + proposal + challenge + "Now make your final call. If the Devil's Advocate raised a valid point, revise. Otherwise, defend your decision with more conviction."
);
// Round 4: Commentator wraps it up
const commentary = await commentatorAgent.generate(finalCall + challenge);
wrapped_tools = [wrap_tool(t) for t in tools]

The conversation history is passed explicitly at each step โ€” no memory tricks, just clean multi-turn context management.
### ๐Ÿ“ก Real-Time SSE Debate Streaming
To make the application feel alive, the FastAPI backend streams the debate agent-by-agent as they speak using **Server-Sent Events (SSE)**. Here is how the orchestrator yields events:
---
## A Real Example: CSK vs MI, Over 17
**Match Input:**

Enter fullscreen mode Exit fullscreen mode


python
async def run_debate(match_state: dict):
# Turn 1: Stats Analyst
yield sse_event("agent_start", {"turn": 1, "agent": "Stats Analyst", "emoji": "๐Ÿ“Š", "message": "Analyzing pitch & weather..."})
stats_report = await stats_analyst(match_state)
yield sse_event("agent_done", {
"turn": 1,
"agent": "Stats Analyst",
"emoji": "๐Ÿ“Š",
"content": stats_report["report"],
"tool_calls": stats_report["tool_calls"]
})

# ... successive turns (Strategist, Devil's Advocate, Commentator) ...

yield sse_event("complete", {"status": "done"})

Enter fullscreen mode Exit fullscreen mode

Innings: 2 | Over: 17 | Score: 142/4 | Target: 178
Strike: Hardik Pandya (34 off 22) | Non-striker: Tim David (11 off 8)
Bowlers left: Bumrah (2 overs), Boult (1 over), Pollard (1 over)
Pitch: Wankhede, flat with dew. Powerplay done.

Enter fullscreen mode Exit fullscreen mode

markdown

Stats Analyst output:

Hardik vs Bumrah: 14 balls, 18 runs, 1 dismissal. Hardik attacks short-pitch deliveries (SR 210 on back-of-length). Tim David vs left-arm pace: 8 balls, 22 runs. Wankhede dew factor: 8/10. Win probability for batting side: 61%.

๐ŸŽจ Premium Mobile-First UI


The UI is built with a dark dugout-themed aesthetic (Deep Obsidian #131313 with vibrant Orange #ff8a00 accents).
Strategist proposes:
BOWL BOULT NOW. Save Bumrah for 19th and 20th. With dew, Boult will struggle to swing it โ€” but his yorker accuracy is high, and Tim David has historically struggled vs left-arm seam in the first 3โ€“4 balls of a new bowler. Use Boult to tie down Tim David this over, set up Bumrah for the kill in 19. CONFIDENCE: 72%.
It is divided into two distinct screens:

  1. Command Center: The tactical input dashboard to configure the live match situation (innings, score, wickets, batsman, available bowlers, venue, and pitch properties).

2. War Room: The multi-agent debate view with a real-time progress bar, typing indicators, and beautiful cards displaying each agent's contribution.

Screen 1: Command Center (Inputs)
Command Center
Devil's Advocate challenges:
Wrong. Dew means Boult loses his biggest weapon โ€” swing. He becomes a full-price medium pacer at Wankhede tonight, and Tim David eats medium pace for breakfast. Worse: Hardik is on 34, not yet in the 40s. He's calculating, not yet in destruction mode. Bowl Bumrah NOW. Catch him before he accelerates. Save Boult for over 19 โ€” he can bowl tight yorkers even without swing. The upside of getting Hardik out in over 17 is worth burning Bumrah early.
Screen 2: War Room (The Live Agent Debate)

War Room

Strategist defends/revises:
The Devil's Advocate raises a legitimate point about dew neutralizing Boult's swing. REVISED CALL: Bring Bumrah on now. Target Hardik with back-of-length deliveries outside off โ€” his data shows he mistimes those. Set a 5-3 off-side field. Use Boult for 19, Pollard as floater in 18 for a change of pace.

๐Ÿš€ Try It Yourself!


The code is open-source and ready to run locally!
Match Commentator:
"And the captain makes the move โ€” Bumrah is back! The thinking here is simple: Hardik is dangerous but hasn't exploded yet. Get him now before it's too late. The alternative was to hold Bumrah back, but with the dew taking the shine off Boult's swing, the captain decided attack is the best form of defense. If Bumrah can get Hardik in the next six balls, this chase is very much alive. Big over coming up."

1. Clone the repository

git clone https://github.com/ShreyasN01/Captain-Cool-Agent.git
cd Captain-Cool-Agent

Enter fullscreen mode Exit fullscreen mode


2. Configure environment

Create a .env file in the root directory:

GEMINI_API_KEY=your_free_api_key_from_google_ai_studio

Enter fullscreen mode Exit fullscreen mode

Tech Stack

3. Run with virtual environment

python3 -m venv venv
source venv/bin/activate
pip install -r backend/requirements.txt
cd backend
python main.py

Enter fullscreen mode Exit fullscreen mode

Component What I Used
LLM Gemini 2.5 Pro (Strategist) + Gemini 2.5 Flash (others)
Agent Framework Google ADK (Agent Development Kit)
Tool Calling Gemini function calling โ†’ cricket stats REST API
Prompt Prototyping Google AI Studio
IDE Google Antigravity (vibe-coded the whole session)
Frontend Minimal web form + JSON output panel

Open http://localhost:8000 in your browser and start making calls like Dhoni!

What I Learned in 3 Hours

๐Ÿง  Key Learnings

  1. Multi-Turn Reasoning Beats One-Shot: Letting LLM agents challenge their own plans (e.g. Strategist vs Devil's Advocate) results in much safer, highly nuanced decisions.
  2. Synchronous Tool Isolation: When using LLM function calling in async environments, keeping external tool lookups synchronous isolates API networks and avoids complex thread clashes.
  3. UX is Everything for Agentic Apps: Streaming agents in real-time makes the AI's internal reasoning process completely transparent, turning a slow API call into a highly engaging user experience. 1. Agent roles need hard constraints, not soft ones. My first version had all agents "collaborate openly." That produced mush. Once I gave each agent a clear prohibition ("your ONLY job is to challenge"), the outputs sharpened dramatically. If you liked this project, don't forget to star the repository on *GitHub! Let me know in the comments: which captain persona is your favorite?* ๐Ÿ **2. Passing full conversation history is expensive but necessary. The multi-turn loop works because each agent sees exactly what the others said. This costs tokens. For production, Gemini context caching would be the fix. 3. The Commentator agent is the secret weapon. Users don't want to read JSON. They want to feel the decision. The Commentator agent transforms a structured output into something fans actually want to read โ€” and it costs almost nothing to add. 4. Cricket language is a quality signal. I specifically tested whether the output used cricket terminology ("leggie," "back-of-length," "death overs," "pinch-hitter") vs generic language ("the bowler," "the strategy"). The system prompt phrase "explain in cricket language a real captain would use" was doing a lot of heavy lifting. --- ## What's Next
  4. Real-time mode: Paste a Cricbuzz URL, let Gemini's URL context tool scrape the live state
  5. Voice interface: Web Speech API + Gemini Live for an actual talking captain
  6. Confidence + counterfactuals: "If you'd bowled X instead, win prob drops 8%"

- Memory across overs: Gemini context caching so the agent remembers its own decisions from over 1

Try It / Read the Code

๐Ÿ”— GitHub: github.com/ShreyasN01/Captain-Cool-Agent
The repo includes:

  • All four agent system prompts
  • The multi-turn orchestration loop
  • The Gemini function-calling tool definition for cricket stats
  • Google Antigravity traces (.antigravity/ folder) from the build session

- A sample match scenario you can run end-to-end

Built in 3 hours. Fueled by chai and the memory of Dhoni's 2011 World Cup final six.

If you're into cricket + AI, drop a comment or connect โ€” would love to talk shop.

Tags: #gemini #googleai #multiagent #cricket #ipl #hackathon #adk #javascript