<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shreyas Nalawade</title>
    <description>The latest articles on DEV Community by Shreyas Nalawade (@shreyasn01).</description>
    <link>https://dev.to/shreyasn01</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3936291%2F026b1b37-971a-4bae-a904-e8073bc3a2b4.jpeg</url>
      <title>DEV Community: Shreyas Nalawade</title>
      <link>https://dev.to/shreyasn01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shreyasn01"/>
    <language>en</language>
    <item>
      <title># 🏏 Captain Cool: How I Built a Multi-Agent IPL Strategist on Gemini in 3 Hours</title>
      <dc:creator>Shreyas Nalawade</dc:creator>
      <pubDate>Sun, 17 May 2026 13:16:08 +0000</pubDate>
      <link>https://dev.to/shreyasn01/-captain-cool-how-i-built-a-multi-agent-ipl-strategist-on-gemini-in-3-hours-2i3n</link>
      <guid>https://dev.to/shreyasn01/-captain-cool-how-i-built-a-multi-agent-ipl-strategist-on-gemini-in-3-hours-2i3n</guid>
      <description>&lt;h1&gt;
  
  
  🏏 Captain Cool: How I Built a Multi-Agent IPL Strategist on Gemini in 3 Hours
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  &lt;em&gt;"Cricket is not just a sport. It's a chess match at 140 km/h."&lt;/em&gt; — and now, it has an AI captain.
&lt;/h2&gt;

&lt;p&gt;title: "🏏 Building \"Captain Cool\": A Multi-Agent IPL Cricket Strategist Powered by Google Gemini &amp;amp; FastAPI"&lt;br&gt;
published: true&lt;br&gt;
tags: python, gemini, ai, webdev&lt;br&gt;
canonical_url: &lt;a href="https://dev.to/shreyasn01/building-captain-cool-a-multi-agent-ipl-cricket-strategist-powered-by-google-gemini-fastapi-3ad1"&gt;https://dev.to/shreyasn01/building-captain-cool-a-multi-agent-ipl-cricket-strategist-powered-by-google-gemini-fastapi-3ad1&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  cover_image: &lt;a href="https://raw.githubusercontent.com/ShreyasN01/Captain-Cool-Agent/main/readme_banner.png" rel="noopener noreferrer"&gt;https://raw.githubusercontent.com/ShreyasN01/Captain-Cool-Agent/main/readme_banner.png&lt;/a&gt;
&lt;/h2&gt;
&lt;h2&gt;
  
  
  The Problem: Cricket Decisions Happen in Seconds
&lt;/h2&gt;
&lt;h1&gt;
  
  
  🏏 Building "Captain Cool": A Multi-Agent IPL Cricket Strategist Powered by Google Gemini &amp;amp; FastAPI
&lt;/h1&gt;

&lt;p&gt;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.&lt;br&gt;
What if you had a virtual IPL cricket captain sitting in your dugout, making real-time tactical decisions like &lt;strong&gt;MS Dhoni, Rohit Sharma, or Hardik Pandya&lt;/strong&gt;? &lt;br&gt;
I wanted to build something that could replicate that cognitive pressure — not just with a chatbot wrapper, but with &lt;strong&gt;genuine agent debate, tool use, and cricket-grade explainability&lt;/strong&gt;.&lt;br&gt;
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.&lt;br&gt;
The result: &lt;strong&gt;Captain Cool&lt;/strong&gt; — a multi-agent IPL strategist built entirely on Google Gemini. Here's how it works, and how I built it in 3 hours.&lt;/p&gt;
&lt;h2&gt;
  
  
  To replicate this, I built &lt;strong&gt;Captain Cool&lt;/strong&gt; — an agentic AI system that orchestrates a &lt;strong&gt;5-turn debate&lt;/strong&gt; between four specialized AI agents to deliver real-time, context-aware tactical decisions during a live IPL match.
&lt;/h2&gt;

&lt;p&gt;Here is a deep dive into how I built it using the &lt;strong&gt;Google Gemini 2.5 Flash&lt;/strong&gt;, &lt;strong&gt;FastAPI (Server-Sent Events)&lt;/strong&gt;, and a &lt;strong&gt;mobile-first stadium-themed UI&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Architecture Overview
&lt;/h2&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────────┐
│                        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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Four named agents. One real tool call. A genuine back-and-forth debate. Let me walk through each.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  The Four Agents
&lt;/h2&gt;

&lt;h2&gt;
  
  
  🏗️ The Multi-Agent Architecture
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Stats Analyst 📊
&lt;/h3&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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          │
└──────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tool used:&lt;/strong&gt; &lt;code&gt;get_player_stats&lt;/code&gt; — a Gemini function-calling tool that fetches recent form, economy rates, and head-to-head matchup stats from a cricket stats API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here are the 4 named agents and their roles:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. 📊 The Stats Analyst (The Tool Caller)
&lt;/h3&gt;

&lt;p&gt;The Analyst has no opinions. It is completely data-driven. Using &lt;strong&gt;Gemini's Native Function Calling (Tools)&lt;/strong&gt;, it automatically fetches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Live Weather Data&lt;/strong&gt;: Real-time relative humidity, dew spread, and temperature using the &lt;strong&gt;Open-Meteo API&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IPL Player Stats&lt;/strong&gt;: Granular batting/bowling statistics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Match-up Data&lt;/strong&gt;: Head-to-head records (e.g., batsman vs. bowler).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Win Probability&lt;/strong&gt;: Computed using a run-rate sigmoid model.
### 2. Strategist 🧠
&lt;strong&gt;Role:&lt;/strong&gt; 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:&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dhoni Style 🧊&lt;/strong&gt;: Ice-cool, calculated, defensive risk management.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rohit Style ⚡&lt;/strong&gt;: Aggressive, matchup-focused, chasing wickets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hardik Style 🔥&lt;/strong&gt;: Bold, instinctual, backing high-risk impact plays.
&lt;strong&gt;System Prompt:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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 (%)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. 😈 The Devil's Advocate (The Challenger)
&lt;/h3&gt;

&lt;p&gt;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.&lt;br&gt;
The Strategist receives the enriched match state and outputs a clear, cricket-literate proposal — e.g., &lt;em&gt;"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."&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  4. 🎙️ The Commentator (The Synthesizer)
&lt;/h3&gt;
&lt;h2&gt;
  
  
  Takes the entire debate, synthesizes it, and delivers a final verdict in pure, colorful cricket language along with an overall tactical &lt;strong&gt;Confidence Score (%)&lt;/strong&gt;.
&lt;/h2&gt;
&lt;h3&gt;
  
  
  3. Devil's Advocate 😈
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Role:&lt;/strong&gt; Challenges the Strategist's call. Argues for the alternative.&lt;/p&gt;
&lt;h2&gt;
  
  
  🛠️ The Tech Stack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;System Prompt:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AI Engine&lt;/strong&gt;: &lt;code&gt;gemini-2.5-flash&lt;/code&gt; using the new official &lt;code&gt;google-genai&lt;/code&gt; Python SDK.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend&lt;/strong&gt;: &lt;strong&gt;FastAPI&lt;/strong&gt; serving SSE (Server-Sent Events) to stream the debate in real-time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: Vanilla HTML5/JS styled with &lt;strong&gt;Tailwind CSS&lt;/strong&gt; 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: &lt;em&gt;"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."&lt;/em&gt;
---
### 4. Match Commentator 🎙️
&lt;strong&gt;Role:&lt;/strong&gt; Translates the final decision into broadcast-quality cricket commentary.
## 💡 Code Highlights
&lt;strong&gt;System Prompt:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ⚡ Dynamic Tool Wrapper (Capturing Gemini Function Calls)
&lt;/h3&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;tool_calls_log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="c1"&gt;## The Multi-Turn Reasoning Loop
# Intercept tool calls dynamically to record them for the UI
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;wrap_tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;tool_calls_log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tool&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;args&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;kwargs&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;kwargs&lt;/span&gt; &lt;span class="nf"&gt;else &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;
    &lt;span class="n"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__doc__&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__doc__&lt;/span&gt;
    &lt;span class="n"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__annotations__&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__annotations__&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;wrapper&lt;/span&gt;
&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;part&lt;/span&gt; &lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;m most proud of. The debate isn&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;cosmetic&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;actually&lt;/span&gt; &lt;span class="n"&gt;changes&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Here&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s the flow in code terms:
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
javascript&lt;br&gt;
// Round 1: Strategist proposes&lt;br&gt;
const proposal = await strategistAgent.generate(matchState + analystContext);&lt;br&gt;
// Round 2: Devil's Advocate challenges&lt;br&gt;
const challenge = await advocateAgent.generate(matchState + proposal);&lt;br&gt;
// Round 3: Strategist revises or defends&lt;br&gt;
const finalCall = await strategistAgent.generate(&lt;br&gt;
  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."&lt;br&gt;
);&lt;br&gt;
// Round 4: Commentator wraps it up&lt;br&gt;
const commentary = await commentatorAgent.generate(finalCall + challenge);&lt;br&gt;
wrapped_tools = [wrap_tool(t) for t in tools]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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:**
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
python&lt;br&gt;
async def run_debate(match_state: dict):&lt;br&gt;
    # Turn 1: Stats Analyst&lt;br&gt;
    yield sse_event("agent_start", {"turn": 1, "agent": "Stats Analyst", "emoji": "📊", "message": "Analyzing pitch &amp;amp; weather..."})&lt;br&gt;
    stats_report = await stats_analyst(match_state)&lt;br&gt;
    yield sse_event("agent_done", {&lt;br&gt;
        "turn": 1,&lt;br&gt;
        "agent": "Stats Analyst",&lt;br&gt;
        "emoji": "📊",&lt;br&gt;
        "content": stats_report["report"],&lt;br&gt;
        "tool_calls": stats_report["tool_calls"]&lt;br&gt;
    })&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ... successive turns (Strategist, Devil's Advocate, Commentator) ...

yield sse_event("complete", {"status": "done"})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  markdown
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Stats Analyst output:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;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%.&lt;/p&gt;
&lt;h2&gt;
  
  
  🎨 Premium Mobile-First UI
&lt;/h2&gt;



&lt;p&gt;The UI is built with a dark &lt;strong&gt;dugout-themed aesthetic&lt;/strong&gt; (Deep Obsidian &lt;code&gt;#131313&lt;/code&gt; with vibrant Orange &lt;code&gt;#ff8a00&lt;/code&gt; accents). &lt;br&gt;
&lt;strong&gt;Strategist proposes:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;BOWL BOULT NOW.&lt;/strong&gt; 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%.&lt;br&gt;
It is divided into two distinct screens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Command Center&lt;/strong&gt;: The tactical input dashboard to configure the live match situation (innings, score, wickets, batsman, available bowlers, venue, and pitch properties).&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  2. &lt;strong&gt;War Room&lt;/strong&gt;: The multi-agent debate view with a real-time progress bar, typing indicators, and beautiful cards displaying each agent's contribution.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Screen 1: Command Center (Inputs)&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FShreyasN01%2FCaptain-Cool-Agent%2Fmain%2Fscreenshot_command.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FShreyasN01%2FCaptain-Cool-Agent%2Fmain%2Fscreenshot_command.png" alt="Command Center"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Devil's Advocate challenges:&lt;/strong&gt;&lt;br&gt;
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.&lt;br&gt;
&lt;em&gt;Screen 2: War Room (The Live Agent Debate)&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FShreyasN01%2FCaptain-Cool-Agent%2Fmain%2Fscreenshot_warroom.png" alt="War Room"&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Strategist defends/revises:&lt;/strong&gt;&lt;br&gt;
The Devil's Advocate raises a legitimate point about dew neutralizing Boult's swing. REVISED CALL: &lt;strong&gt;Bring Bumrah on now.&lt;/strong&gt; 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.&lt;/p&gt;
&lt;h2&gt;
  
  
  🚀 Try It Yourself!
&lt;/h2&gt;



&lt;p&gt;The code is open-source and ready to run locally!&lt;br&gt;
&lt;strong&gt;Match Commentator:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;"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."&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Clone the repository
&lt;/h3&gt;


&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/ShreyasN01/Captain-Cool-Agent.git
&lt;span class="nb"&gt;cd &lt;/span&gt;Captain-Cool-Agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Configure environment
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in the root directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GEMINI_API_KEY=your_free_api_key_from_google_ai_studio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3. Run with virtual environment
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; backend/requirements.txt
&lt;span class="nb"&gt;cd &lt;/span&gt;backend
python main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;What I Used&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;LLM&lt;/td&gt;
&lt;td&gt;Gemini 2.5 Pro (Strategist) + Gemini 2.5 Flash (others)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Agent Framework&lt;/td&gt;
&lt;td&gt;Google ADK (Agent Development Kit)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool Calling&lt;/td&gt;
&lt;td&gt;Gemini function calling → cricket stats REST API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Prompt Prototyping&lt;/td&gt;
&lt;td&gt;Google AI Studio&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IDE&lt;/td&gt;
&lt;td&gt;Google Antigravity (vibe-coded the whole session)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frontend&lt;/td&gt;
&lt;td&gt;Minimal web form + JSON output panel&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Open &lt;strong&gt;&lt;code&gt;http://localhost:8000&lt;/code&gt;&lt;/strong&gt; in your browser and start making calls like Dhoni!
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What I Learned in 3 Hours
&lt;/h2&gt;

&lt;h2&gt;
  
  
  🧠 Key Learnings
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Turn Reasoning Beats One-Shot&lt;/strong&gt;: Letting LLM agents challenge their own plans (e.g. Strategist vs Devil's Advocate) results in much safer, highly nuanced decisions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synchronous Tool Isolation&lt;/strong&gt;: When using LLM function calling in async environments, keeping external tool lookups synchronous isolates API networks and avoids complex thread clashes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UX is Everything for Agentic Apps&lt;/strong&gt;: 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.
&lt;strong&gt;1. Agent roles need hard constraints, not soft ones.&lt;/strong&gt;
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.
&lt;em&gt;If you liked this project, don't forget to star the repository on *&lt;/em&gt;&lt;a href="https://github.com/ShreyasN01/Captain-Cool-Agent" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;strong&gt;! Let me know in the comments: which captain persona is your favorite?* 🏏
**2. Passing full conversation history is expensive but necessary.&lt;/strong&gt;
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.
&lt;strong&gt;3. The Commentator agent is the secret weapon.&lt;/strong&gt;
Users don't want to read JSON. They want to &lt;em&gt;feel&lt;/em&gt; the decision. The Commentator agent transforms a structured output into something fans actually want to read — and it costs almost nothing to add.
&lt;strong&gt;4. Cricket language is a quality signal.&lt;/strong&gt;
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 &lt;em&gt;"explain in cricket language a real captain would use"&lt;/em&gt; was doing a lot of heavy lifting.
---
## What's Next&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-time mode&lt;/strong&gt;: Paste a Cricbuzz URL, let Gemini's URL context tool scrape the live state&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Voice interface&lt;/strong&gt;: Web Speech API + Gemini Live for an actual talking captain&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confidence + counterfactuals&lt;/strong&gt;: "If you'd bowled X instead, win prob drops 8%"&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  - &lt;strong&gt;Memory across overs&lt;/strong&gt;: Gemini context caching so the agent remembers its own decisions from over 1
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Try It / Read the Code
&lt;/h2&gt;

&lt;p&gt;🔗 &lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/ShreyasN01/Captain-Cool-Agent" rel="noopener noreferrer"&gt;github.com/ShreyasN01/Captain-Cool-Agent&lt;/a&gt;&lt;br&gt;
The repo includes:&lt;/p&gt;

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

&lt;h2&gt;
  
  
  - A sample match scenario you can run end-to-end
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Built in 3 hours. Fueled by chai and the memory of Dhoni's 2011 World Cup final six.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;If you're into cricket + AI, drop a comment or connect — would love to talk shop.&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tags:&lt;/strong&gt; &lt;code&gt;#gemini&lt;/code&gt; &lt;code&gt;#googleai&lt;/code&gt; &lt;code&gt;#multiagent&lt;/code&gt; &lt;code&gt;#cricket&lt;/code&gt; &lt;code&gt;#ipl&lt;/code&gt; &lt;code&gt;#hackathon&lt;/code&gt; &lt;code&gt;#adk&lt;/code&gt; &lt;code&gt;#javascript&lt;/code&gt;&lt;/p&gt;

</description>
      <category>agents</category>
      <category>gemini</category>
      <category>python</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
