<?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: Abhishek Swami</title>
    <description>The latest articles on DEV Community by Abhishek Swami (@abhishek_swami_7b02ecfd7c).</description>
    <link>https://dev.to/abhishek_swami_7b02ecfd7c</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%2F3712032%2F13ec6b53-ca33-48d1-96e0-15dea6ed4f35.png</url>
      <title>DEV Community: Abhishek Swami</title>
      <link>https://dev.to/abhishek_swami_7b02ecfd7c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhishek_swami_7b02ecfd7c"/>
    <language>en</language>
    <item>
      <title>Captain Cool: A Gemini Multi-Agent IPL Match Strategist</title>
      <dc:creator>Abhishek Swami</dc:creator>
      <pubDate>Sun, 17 May 2026 12:50:42 +0000</pubDate>
      <link>https://dev.to/abhishek_swami_7b02ecfd7c/captain-cool-a-gemini-multi-agent-ipl-match-strategist-4ai2</link>
      <guid>https://dev.to/abhishek_swami_7b02ecfd7c/captain-cool-a-gemini-multi-agent-ipl-match-strategist-4ai2</guid>
      <description>&lt;p&gt;Cricket captaincy is not just "pick the best bowler." It is matchups, dew, field dimensions, batter psychology, bowler workload, Impact Player timing, and the courage to make a call before the obvious moment arrives.&lt;/p&gt;

&lt;p&gt;Captain Cool is my attempt to turn that into an agentic AI system: a virtual IPL captain that reads the match state, runs an internal dugout debate, and returns the next tactical decision in cricket language.&lt;/p&gt;

&lt;p&gt;The stack is intentionally Google-first:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next.js frontend and API routes&lt;/li&gt;
&lt;li&gt;Gemini via &lt;code&gt;@google/genai&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Model: &lt;code&gt;gemini-2.5-flash&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Gemini function calling for tools&lt;/li&gt;
&lt;li&gt;CricAPI / CricketData live score integration&lt;/li&gt;
&lt;li&gt;Free no-key Cricbuzz-backed fallback endpoint&lt;/li&gt;
&lt;li&gt;Custom multi-agent orchestration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The multi-agent loop is custom TypeScript orchestration, but the tool use is real Gemini function calling.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Captain Cool Does
&lt;/h2&gt;

&lt;p&gt;The user enters or fetches the current match state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;innings, over, ball&lt;/li&gt;
&lt;li&gt;score and wickets&lt;/li&gt;
&lt;li&gt;striker and non-striker&lt;/li&gt;
&lt;li&gt;bowling resources&lt;/li&gt;
&lt;li&gt;pitch condition&lt;/li&gt;
&lt;li&gt;dew factor&lt;/li&gt;
&lt;li&gt;venue&lt;/li&gt;
&lt;li&gt;target / required rate&lt;/li&gt;
&lt;li&gt;Impact Player availability&lt;/li&gt;
&lt;li&gt;optional live match ID or URL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Captain Cool replies with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the next captaincy decision&lt;/li&gt;
&lt;li&gt;cricket-language reasoning&lt;/li&gt;
&lt;li&gt;visible dissent from the Devil's Advocate agent&lt;/li&gt;
&lt;li&gt;confidence score&lt;/li&gt;
&lt;li&gt;counterfactual&lt;/li&gt;
&lt;li&gt;full debate transcript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Captain's Call:
BOWL PATHIRANA - OVER 16

Why:
The wet ball has taken Jadeja's grip away. Pathirana's skiddy angle
is harder for Tilak to get underneath, and the field protects the
midwicket release shot.

Dissent:
The risk is burning Pathirana before the 18th. If this over leaks 14,
the death plan gets thin.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────────┐
│                         Next.js UI                           │
│  Premium cricket broadcast dashboard                         │
│  Manual match state + live match fetch + agent debate view    │
└──────────────────────────────┬──────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────┐
│                    Next.js API Routes                        │
│                                                             │
│  /api/strategy                                               │
│  /api/cricket/current                                        │
│  /api/cricket/match?id=...                                   │
│  /api/cricket/free-score?match=...                           │
│  /api/live-matches                                           │
│  /api/live-strategy                                          │
└──────────────────────────────┬──────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────┐
│                 Gemini Agent Orchestrator                    │
│                                                             │
│  1. Stats Analyst                                            │
│     ├─ fetchLiveMatchData tool, when match ID is present      │
│     └─ calculateMatchPressure tool                           │
│                                                             │
│  2. Tactical Strategist                                      │
│     └─ proposes first captaincy call                         │
│                                                             │
│  3. Devil's Advocate                                         │
│     └─ challenges the plan                                   │
│                                                             │
│  4. Tactical Strategist                                      │
│     └─ defends or revises                                    │
│                                                             │
│  5. Match Commentator                                        │
│     └─ formats fan-friendly final answer                     │
└──────────────────────────────┬──────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────┐
│                         UI Result                            │
│  Captain's Call + Why + Dissent + Confidence + Debate         │
└─────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Agent Design
&lt;/h2&gt;

&lt;p&gt;The system uses four named Gemini-powered agents. Each agent is a separate Gemini call with its own system prompt and role.&lt;/p&gt;

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

&lt;p&gt;The Stats Analyst does not make tactical decisions. It reads numbers, phase, pressure, match conditions, and live data.&lt;/p&gt;

&lt;p&gt;Prompt excerpt:&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 world-class cricket statistician — think of ESPNcricinfo's
StatsGuru merged with a baseball sabermetrician.

YOUR IDENTITY:
- You speak in numbers, trends, and matchups ONLY
- You NEVER suggest a decision or give an opinion
- You respond to queries with structured statistical evidence
- Every claim must include a number: average, strike rate, economy,
  sample size, historical trend
- If a CricAPI live match ID is present in the match state, your FIRST
  action must be calling fetchLiveMatchData before any analysis.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;STATISTICAL BRIEF:
• Matchup
• Venue Trend
• Phase Analysis
• Condition Factor
• Historical Parallel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Tactical Strategist
&lt;/h3&gt;

&lt;p&gt;The Strategist is the captaincy brain. It makes the first call: who bowls, how the field is set, whether to use the Impact Player, when to take the timeout, and what the contingency is.&lt;/p&gt;

&lt;p&gt;Prompt excerpt:&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 the tactical brain of an IPL captaincy team. Think MS Dhoni's
instinct + Rohit Sharma's bowling changes + Hardik Pandya's aggression.

YOUR IDENTITY:
- You make BOLD, specific tactical decisions
- You think 2-3 overs ahead, not just the next ball
- You understand cricket psychology, momentum, and pressure
- You're not afraid to use unorthodox options
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TACTICAL DECISION:
• Next Bowler
• Field Setup
• Batting Move
• Impact Player
• Strategic Timeout
• Contingency

TACTICAL LOGIC:
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Devil's Advocate
&lt;/h3&gt;

&lt;p&gt;This agent exists to disagree. It challenges the Strategist's first plan with the kind of objection an assistant coach would raise in a real dugout.&lt;/p&gt;

&lt;p&gt;Prompt excerpt:&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 the cautious inner voice of a cricket captain — the part
that asks "what if this goes horribly wrong?" before every decision.

YOUR IDENTITY:
- Your job is to FIND FLAWS in every tactical proposal
- You think about WORST-CASE SCENARIOS
- You remember cricket history where similar decisions backfired
- You are NOT negative — you are rigorous.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Critique framework:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Matchup counter
2. Resource mismanagement
3. Condition misread
4. Psychological backfire
5. Historical precedent
6. Opportunity cost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Match Commentator
&lt;/h3&gt;

&lt;p&gt;The Commentator turns the internal debate into something a non-technical fan can enjoy.&lt;/p&gt;

&lt;p&gt;Prompt excerpt:&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 the voice of cricket — imagine Harsha Bhogle's storytelling
meets Ravi Shastri's energy meets Ian Bishop's gravitas.

YOUR IDENTITY:
- You translate complex tactical decisions into ELECTRIC commentary
- You make cricket strategy accessible to a 12-year-old fan
- You capture the DRAMA, the tension, the "what if"
- You speak like you're on live television
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CAPTAIN COOL'S CALL
THE COMMENTARY
THE DUGOUT DEBATE
CONFIDENCE METER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Gemini Function Calling
&lt;/h2&gt;

&lt;p&gt;Captain Cool uses Gemini function calling for real tool use. The two important tools are:&lt;/p&gt;

&lt;h3&gt;
  
  
  Tool 1: &lt;code&gt;fetchLiveMatchData&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This tool fetches live match information before analysis when a live match ID or URL is available.&lt;/p&gt;

&lt;p&gt;Schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fetchLiveMatchDataTool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FunctionDeclaration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fetchLiveMatchData&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Fetch live match score, status, teams, venue, scorecard, and innings details. Prefer CricAPI match IDs; also accepts a Cricbuzz URL or numeric match ID through a free no-key fallback.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;parameters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OBJECT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;matchId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;STRING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A CricAPI match ID, Cricbuzz match ID, or Cricbuzz live match URL.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;matchId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleFetchLiveMatchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;matchId&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matchId&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Missing live match ID or URL.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="sr"&gt;/^https&lt;/span&gt;&lt;span class="se"&gt;?&lt;/span&gt;&lt;span class="sr"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\/\/&lt;/span&gt;&lt;span class="sr"&gt;/i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matchId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;CRICAPI_KEY&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getLiveCricketMatchDetails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matchId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Fall through to the free no-key provider.&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getFreeLiveCricketScore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;matchId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tool 2: &lt;code&gt;calculateMatchPressure&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This local tool converts match state into tactical context.&lt;/p&gt;

&lt;p&gt;It calculates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;current over&lt;/li&gt;
&lt;li&gt;balls remaining&lt;/li&gt;
&lt;li&gt;innings phase&lt;/li&gt;
&lt;li&gt;current run rate&lt;/li&gt;
&lt;li&gt;required run rate&lt;/li&gt;
&lt;li&gt;runs needed&lt;/li&gt;
&lt;li&gt;pressure score&lt;/li&gt;
&lt;li&gt;pressure label&lt;/li&gt;
&lt;li&gt;bowler overs remaining&lt;/li&gt;
&lt;li&gt;tactical flags&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"phase"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"death"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"currentRunRate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;9.16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"requiredRunRate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;9.78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"pressureScore"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;72&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"pressureLabel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"high"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tacticalFlags"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"Death-over specialists and boundary protection take priority."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"Dew reduces grip, so yorkers, hard lengths, and pace-off cutters become safer than big spin."&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Orchestration Flow
&lt;/h2&gt;

&lt;p&gt;The orchestration is intentionally multi-turn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step 1:
Stats Analyst checks if liveMatchId exists.
If yes, Gemini calls fetchLiveMatchData.

Step 2:
Stats Analyst calls calculateMatchPressure.

Step 3:
Stats Analyst summarizes tactical context.

Step 4:
Tactical Strategist proposes the first plan.

Step 5:
Devil's Advocate challenges the plan.

Step 6:
Tactical Strategist defends or revises.

Step 7:
Match Commentator converts the whole debate into final fan-facing JSON.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important bit: this is not one Gemini call pretending to be multiple agents. Each role is a separate Gemini request with its own prompt and context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-Time Data
&lt;/h2&gt;

&lt;p&gt;Captain Cool supports three live-data paths:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. CricAPI / CricketData
&lt;/h3&gt;

&lt;p&gt;Used for current match lists and detailed scorecards.&lt;/p&gt;

&lt;p&gt;Routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/cricket/current
GET /api/cricket/match?id=&amp;lt;match-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Environment variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;CRICAPI_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Free No-Key Fallback
&lt;/h3&gt;

&lt;p&gt;For quick demos without a key, the app can fetch from a Cricbuzz-backed JSON endpoint.&lt;/p&gt;

&lt;p&gt;Route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/cricket/free-score?match=&amp;lt;id-or-url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This accepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cricbuzz numeric match ID&lt;/li&gt;
&lt;li&gt;Cricbuzz live match URL&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. SportMonks
&lt;/h3&gt;

&lt;p&gt;SportMonks is available as a richer live source when a token is present.&lt;/p&gt;

&lt;p&gt;Routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /api/live-matches
POST /api/live-strategy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Environment variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;SPORTMONKS_API_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  UI Design
&lt;/h2&gt;

&lt;p&gt;I wanted the interface to feel like a premium cricket broadcast truck, not a generic chatbot.&lt;/p&gt;

&lt;p&gt;The dashboard includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dark navy broadcast-studio theme&lt;/li&gt;
&lt;li&gt;pitch green and gold accents&lt;/li&gt;
&lt;li&gt;scoreboard-style match state&lt;/li&gt;
&lt;li&gt;live match ticker&lt;/li&gt;
&lt;li&gt;pitch visualization&lt;/li&gt;
&lt;li&gt;field placement diagram&lt;/li&gt;
&lt;li&gt;agent debate bubbles&lt;/li&gt;
&lt;li&gt;confidence gauge&lt;/li&gt;
&lt;li&gt;live metrics sparklines&lt;/li&gt;
&lt;li&gt;"Ask Captain" action button&lt;/li&gt;
&lt;li&gt;"Free Fetch" live-score fallback&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The UI sections are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Top Bar:
THE DUGOUT, AI status, match clock, ticker

Left Panel:
Match state, scoreboard, pitch, batters, bowlers

Center Panel:
Live score fetcher, Captain's Call, controls

Right Panel:
Agent debate and confidence meter

Bottom:
Live metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  End-to-End Walkthrough
&lt;/h2&gt;

&lt;p&gt;Scenario:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Match: CSK vs MI at Chepauk
Innings: 2
Score: 142/4
Overs: 15.3
Target: 186
Striker: Tilak Varma, 47* off 31
Non-striker: Hardik Pandya, 12* off 8
Pitch: turning
Dew: setting in
Impact Player: available
Strategic Timeout: available
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 1: Fetch Live Data
&lt;/h3&gt;

&lt;p&gt;The user can either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;click "Fetch Current" with a CricAPI key&lt;/li&gt;
&lt;li&gt;paste a Cricbuzz match ID or URL and click "Free Fetch"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The dashboard renders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MI 142/4
15.3 overs
Target 186
Required rate around 9.8
Status: Live
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Ask Captain
&lt;/h3&gt;

&lt;p&gt;The user clicks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ASK CAPTAIN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The four-agent spinner starts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Stats Analyst
Strategist
Devil's Advocate
Commentator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Stats Analyst Tool Calls
&lt;/h3&gt;

&lt;p&gt;If a live match ID is present:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetchLiveMatchData(matchId)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;calculateMatchPressure(matchState)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Stats Analyst returns something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;• Phase Analysis: Over 15.3 means the match is entering the death phase.
• Required Rate: MI need 44 from 27 balls, about 9.78 RPO.
• Condition Factor: Dew reduces grip, so spin is less reliable.
• Resource View: Pathirana has one high-leverage over available.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Strategist Makes the First Call
&lt;/h3&gt;

&lt;p&gt;The Strategist proposes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bowl Pathirana for over 16.
Set deep midwicket, long-on, long-off, deep square.
Keep fine leg up and protect the hard-length release shot.
Hold the Impact Player unless a wicket falls.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Devil's Advocate Pushes Back
&lt;/h3&gt;

&lt;p&gt;The Devil's Advocate challenges:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If Pathirana leaks 12-14 now, CSK lose their death-over cushion.
Jadeja has completed his quota, so the fallback death plan becomes thin.
The wet ball could turn yorkers into low full tosses.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Strategist Revises or Defends
&lt;/h3&gt;

&lt;p&gt;The Strategist responds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Proceed with Pathirana, but bowl over the wicket to Tilak.
If the first two balls go for boundaries, switch the plan next over:
hard-length pace-off into the pitch, not spin.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 7: Commentator Finalizes
&lt;/h3&gt;

&lt;p&gt;The final answer becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CAPTAIN'S CALL:
BOWL PATHIRANA - OVER 16

WHY:
The dew has made spin risky. Pathirana's skiddy angle is the better
weapon against a set left-hander. The field protects Tilak's strongest
release shot and asks him to hit to the bigger, weaker zone.

DISSENT:
The dugout worry is resource burn. If this over goes badly, the 18th
and 20th over plan gets uncomfortable.

CONFIDENCE:
78%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  AI Studio Prompt Link
&lt;/h2&gt;

&lt;p&gt;I prototyped prompts locally in code during the build. I have not published a Google AI Studio prompt link yet.&lt;/p&gt;

&lt;p&gt;Before publishing the final dev.to post, add it here:&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;A massive shoutout to ** @gdgcloudpune &lt;em&gt;, especially *&lt;a class="mentioned-user" href="https://dev.to/antrixsh_gupta"&gt;@antrixsh_gupta&lt;/a&gt; *, *&lt;a class="mentioned-user" href="https://dev.to/pratik_kale"&gt;@pratik_kale&lt;/a&gt; *&lt;/em&gt;, and the entire organizing team. The problem statement was brilliant, the vibe was electric, and events like this push the developer community to level up in incredible ways.&lt;/p&gt;

&lt;p&gt;👇 Check out the code and try it yourself:&lt;/p&gt;

&lt;p&gt;GitHub Repository: &lt;a href="https://github.com/swamiabhishek45/captain-cool" rel="noopener noreferrer"&gt;https://github.com/swamiabhishek45/captain-cool&lt;/a&gt;&lt;br&gt;
Live Link : &lt;a href="https://captain-cool-dusl.vercel.app/" rel="noopener noreferrer"&gt;https://captain-cool-dusl.vercel.app/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
