<?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: Vishal Gunjal</title>
    <description>The latest articles on DEV Community by Vishal Gunjal (@vishalgunjalswe).</description>
    <link>https://dev.to/vishalgunjalswe</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%2F2134378%2Fce6b2ac2-46aa-49a5-9ffd-60263b9087d4.jpg</url>
      <title>DEV Community: Vishal Gunjal</title>
      <link>https://dev.to/vishalgunjalswe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vishalgunjalswe"/>
    <language>en</language>
    <item>
      <title>Building "Captain Cool": A Deterministic, Multi-Agent AI Orchestration Engine</title>
      <dc:creator>Vishal Gunjal</dc:creator>
      <pubDate>Sun, 17 May 2026 12:31:41 +0000</pubDate>
      <link>https://dev.to/vishalgunjalswe/building-captain-cool-a-deterministic-multi-agent-ai-orchestration-engine-2o8g</link>
      <guid>https://dev.to/vishalgunjalswe/building-captain-cool-a-deterministic-multi-agent-ai-orchestration-engine-2o8g</guid>
      <description>&lt;p&gt;Most Generative AI applications built at hackathons share the same fatal flaw: they are stateless, brittle chatbots wrapped in a nice UI. They hallucinate under pressure, fail ungracefully when external APIs drop, and offer zero visibility into execution costs.&lt;/p&gt;

&lt;p&gt;For the &lt;strong&gt;Agentic Premier League 2026&lt;/strong&gt; hosted by GDG Cloud Pune, I wanted to build something different.&lt;/p&gt;

&lt;p&gt;Instead of a generic prompt wrapper, I engineered Captain Cool—a production-grade, distributed multi-agent AI system that acts as a real-time IPL match strategist. We treated AI agents not as conversationalists, but as highly specialized microservices communicating via a deterministic state machine.Here is a deep dive into the architecture, the SRE-grade observability, and how we built a "Bloomberg Terminal for Cricket."&lt;/p&gt;

&lt;p&gt;🔗 : &lt;a href="https://github.com/vishalgunjalSWE/captain-cool-agent" rel="noopener noreferrer"&gt;https://github.com/vishalgunjalSWE/captain-cool-agent&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🏗️ The Multi-Agent Architecture (DAG)&lt;/p&gt;

&lt;p&gt;To satisfy the requirement of complex, multi-turn reasoning, I decoupled the LLM into four distinct, highly constrained agents powered by Gemini 2.5 Flash via the @google/genai SDK.&lt;/p&gt;

&lt;p&gt;Instead of one prompt trying to do everything, data flows sequentially through this Directed Acyclic Graph (DAG):&lt;/p&gt;

&lt;p&gt;The Analyst (Data Ingestion &amp;amp; Tool Call): Parses the raw match state (e.g., target, overs left, batsmen). It executes a real-time Gemini Tool Call to the Open-Meteo API to fetch Pune's temperature and humidity, calculating a "Dew Factor."&lt;/p&gt;

&lt;p&gt;The Strategist (Proposal): Ingests the Analyst's enriched payload and generates a tactical plan. Using strict system instructions and responseMimeType: "application/json", it is forced to output a structured JSON matrix containing the tactic, bowler, win probability, and counterfactual risk.&lt;/p&gt;

&lt;p&gt;The Advocate (Automated Red Teaming): This agent is explicitly prompted to never agree. It intercepts the Strategist's JSON matrix, analyzes it for flaws (e.g., "Bowling an off-spinner to left-handers with heavy dew is a 80% loss probability"), and forces a revision.&lt;/p&gt;

&lt;p&gt;The Commentator (Broadcast Output): Translates the final, stress-tested JSON output into engaging cricket jargon for the user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2scq88xlhvspg9kaell.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2scq88xlhvspg9kaell.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⚙️ SRE &amp;amp; Enterprise Differentiators&lt;/p&gt;

&lt;p&gt;Building for production means building for failure and scale. Here is how we bulletproofed the engine:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Graceful Degradation (The Fallback Protocol)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Network requests fail. To ensure the orchestration loop survives, the Analyst’s weather API tool call is wrapped in an AbortController with a strict 3-second timeout. If the venue Wi-Fi drops or the API rate-limits, the system catches the error, logs a warning, and seamlessly injects mock historical pitch data to keep the pipeline moving.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FinOps &amp;amp; ELK-Style Telemetry&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To prove unit economics, I built a custom trackExecution() higher-order function that wraps every Gemini API call.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;It tracks performance.now() latency (in ms).

It parses the usageMetadata object to extract prompt and completion tokens.

It calculates the exact cost of the pipeline in real-time.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;All of this telemetry is saved to an audit_trace.json file and streamed to the frontend.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Context Persistence (Memory Across Overs)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To prevent the system from acting like an amnesiac, it writes the final strategic decision to a localized match_state.json file. When the user simulates the next over, the Analyst agent reads this history, allowing the AI to naturally reference past mistakes or successes.&lt;/p&gt;

&lt;p&gt;💻 The Observability Console (Next.js + SSE)&lt;/p&gt;

&lt;p&gt;To visualize this complex backend, a standard chat UI wouldn't suffice. I built an "Observability Dashboard" using Next.js (App Router), Tailwind CSS v3.4, and shadcn/ui.&lt;/p&gt;

&lt;p&gt;To achieve a true "Bloomberg Terminal" aesthetic, the backend Node/Express server streams the agent telemetry to the Next.js frontend via Server-Sent Events (SSE).&lt;/p&gt;

&lt;p&gt;As the simulation runs, the UI dynamically updates:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;An animated Framer Motion pipeline graph pulses as each agent activates.

The "FinOps Ticker" updates the live compute cost fraction-by-fraction.

The Counterfactual Matrix renders instantly into a clean, dark-mode data table.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;🚀 Quick Start (One-Click Ignition)&lt;/p&gt;

&lt;p&gt;I utilized concurrently in the root monorepo to ensure a flawless developer experience. You can spin up both the Express AI Engine and the Next.js Dashboard with a single command:&lt;/p&gt;

&lt;h1&gt;
  
  
  Clone the repository
&lt;/h1&gt;

&lt;p&gt;git clone [Your Repo URL]&lt;br&gt;
cd captain-cool-stack&lt;/p&gt;

&lt;h1&gt;
  
  
  Install dependencies
&lt;/h1&gt;

&lt;p&gt;npm install&lt;/p&gt;

&lt;h1&gt;
  
  
  Add your Gemini API Key
&lt;/h1&gt;

&lt;p&gt;echo "GEMINI_API_KEY=your_key_here" &amp;gt; captain-cool-agent/.env&lt;/p&gt;

&lt;h1&gt;
  
  
  Ignite the stack
&lt;/h1&gt;

&lt;p&gt;npm start&lt;/p&gt;

&lt;p&gt;🏆 Conclusion&lt;/p&gt;

&lt;p&gt;The Agentic Premier League challenge proved that the future of AI engineering is Systems Engineering. Prompt engineering is just the syntax; architecture, observability, fault-tolerance, and deterministic orchestration are what make Agentic AI valuable in the real world.&lt;/p&gt;

&lt;p&gt;Massive thanks to GDG Cloud Pune and Google Cloud for an incredible event!&lt;/p&gt;

&lt;p&gt;Stack: Gemini 2.5 Flash, Node.js, Express, Next.js, shadcn/ui, Docker.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>architecture</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
