<?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: Ankit Halder</title>
    <description>The latest articles on DEV Community by Ankit Halder (@ankit_halder_7840b622b962).</description>
    <link>https://dev.to/ankit_halder_7840b622b962</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2812670%2F7a390ac0-b9e8-4950-bfb7-31d10180d2f5.jpg</url>
      <title>DEV Community: Ankit Halder</title>
      <link>https://dev.to/ankit_halder_7840b622b962</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ankit_halder_7840b622b962"/>
    <language>en</language>
    <item>
      <title>Building an Event-Driven Restaurant System with Node.js and Kafka</title>
      <dc:creator>Ankit Halder</dc:creator>
      <pubDate>Sat, 19 Sep 2026 11:56:11 +0000</pubDate>
      <link>https://dev.to/ankit_halder_7840b622b962/building-an-event-driven-restaurant-system-with-nodejs-and-kafka-2oaj</link>
      <guid>https://dev.to/ankit_halder_7840b622b962/building-an-event-driven-restaurant-system-with-nodejs-and-kafka-2oaj</guid>
      <description>&lt;p&gt;&lt;strong&gt;🔗 Source Code:&lt;/strong&gt; &lt;a href="https://github.com/OriginalAnkit/learning/tree/master/restaurant-kafka-cli" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2njmj10pfsrxivjfgxtt.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2njmj10pfsrxivjfgxtt.png" alt="Screenshot of both consumer and producer" width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you ever wondered how food delivery apps handle thousands of orders, notifications, and billing processes simultaneously? The secret lies in &lt;strong&gt;Event-Driven Architecture (EDA)&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;In this article, I'll walk you through a simple yet powerful CLI application that simulates a restaurant's order management system using &lt;strong&gt;Node.js&lt;/strong&gt; and &lt;strong&gt;Apache Kafka&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Kafka for a Restaurant System?
&lt;/h2&gt;

&lt;p&gt;When a customer places an order, multiple things need to happen:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;strong&gt;Billing&lt;/strong&gt; service needs to process the payment.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Notification&lt;/strong&gt; service needs to send updates to the user.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Rider&lt;/strong&gt; service needs to assign a delivery partner once the food is ready.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Instead of having a monolithic app where each component calls the other synchronously (which can lead to bottlenecks), we can use Kafka. The central system simply announces, &lt;em&gt;"Hey, a new order was placed!"&lt;/em&gt; or &lt;em&gt;"The order is ready!"&lt;/em&gt; The respective services listen for these events and act independently. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Architecture Diagram
&lt;/h2&gt;

&lt;p&gt;Here is a visual representation of how our services interact with Kafka topics:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    %% Producer
    P[Restaurant CLI Producer]

    %% Topics (Kafka)
    subgraph Kafka [Kafka Cluster]
        T1[(Topic: new-order)]
        T2[(Topic: order-accepted)]
        T3[(Topic: order-ready)]
    end

    %% Consumers
    C_Billing[Billing Consumer]
    C_Notif[Notification Consumer]
    C_Rider[Rider Consumer]

    %% Producer pushing to Topics
    P -- Publishes --&amp;gt; T1
    P -- Publishes --&amp;gt; T2
    P -- Publishes --&amp;gt; T3

    %% Consumers subscribing from Topics
    T1 -. Subscribes .-&amp;gt; C_Billing
    T1 -. Subscribes .-&amp;gt; C_Notif
    T2 -. Subscribes .-&amp;gt; C_Notif
    T3 -. Subscribes .-&amp;gt; C_Rider
    T3 -. Subscribes .-&amp;gt; C_Notif&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;As shown above:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Billing&lt;/strong&gt; service only cares about the &lt;code&gt;new-order&lt;/code&gt; events.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Rider&lt;/strong&gt; service only springs into action when an &lt;code&gt;order-ready&lt;/code&gt; event occurs.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Notification&lt;/strong&gt; service is the nosy one—it tracks the order at every step (&lt;code&gt;new-order&lt;/code&gt;, &lt;code&gt;order-accepted&lt;/code&gt;, and &lt;code&gt;order-ready&lt;/code&gt;) to keep the customer updated!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Code Explanation
&lt;/h2&gt;

&lt;p&gt;Let's dive into the core of how this is implemented using &lt;code&gt;kafkajs&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Kafka Initialization and Admin Client
&lt;/h3&gt;

&lt;p&gt;Before producing or consuming, we ensure our required topics exist. The &lt;code&gt;init()&lt;/code&gt; function uses the Kafka Admin Client to check for and dynamically create topics (&lt;code&gt;new-order&lt;/code&gt;, &lt;code&gt;order-accepted&lt;/code&gt;, &lt;code&gt;order-ready&lt;/code&gt;) if they don't already exist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;kafka&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;existing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listTopics&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// ... logic to create missing topics ...&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTopics&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;topics&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;events_to_be_created&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. The Producer
&lt;/h3&gt;

&lt;p&gt;The Producer takes interactive input from the user (via Node's &lt;code&gt;readline&lt;/code&gt; module) and produces events based on the user's actions. When a new order is created, or its status changes, we push a message to the relevant Kafka topic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;producer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;kafka&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;producer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;producer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;producer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;messages&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;partition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;partition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We assign events to different partitions dynamically (e.g., &lt;code&gt;orders.length % 2&lt;/code&gt;) to demonstrate distributing the load.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The Consumers (Service Subscriptions)
&lt;/h3&gt;

&lt;p&gt;We define multiple consumers using different &lt;code&gt;groupId&lt;/code&gt;s to simulate independent microservices. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Billing Service:&lt;/strong&gt; Uses &lt;code&gt;groupId: 'billing'&lt;/code&gt; and subscribes strictly to &lt;code&gt;new-order&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rider Service:&lt;/strong&gt; Uses &lt;code&gt;groupId: 'rider'&lt;/code&gt; and subscribes to &lt;code&gt;order-ready&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Notification Service:&lt;/strong&gt; Uses &lt;code&gt;groupId: 'notification'&lt;/code&gt; and subscribes to multiple topics: &lt;code&gt;['new-order', 'order-accepted', 'order-ready']&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;riderConsumer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;kafka&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;consumer&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;groupId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rider&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;riderConsumer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;riderConsumer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;topics&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="s1"&gt;order-ready&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="na"&gt;fromBeginning&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;riderConsumer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;eachMessage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;partition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`[RIDER] Received on &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&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;By assigning distinct Consumer Groups, Kafka guarantees that each microservice independently receives and processes the events it cares about.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Run the Project
&lt;/h2&gt;

&lt;p&gt;Want to try it out yourself? Follow these steps to get the restaurant system running on your local machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt; installed and running.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; installed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Setup Instructions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Clone and navigate to the project directory:&lt;/strong&gt;
Navigate into the &lt;code&gt;restaurant-kafka-cli&lt;/code&gt; folder.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;cd &lt;/span&gt;restaurant-kafka-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start the Kafka Cluster:&lt;/strong&gt;
We have included a &lt;code&gt;docker-compose.yml&lt;/code&gt; file to quickly spin up an Apache Kafka instance.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker-compose up &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install Dependencies:&lt;/strong&gt;
Install the required Node.js packages (primarily &lt;code&gt;kafkajs&lt;/code&gt;).
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run the Application:&lt;/strong&gt;
Since this is a CLI-based application, it is best to open at least &lt;strong&gt;two separate terminal windows&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;In Terminal 1 (The Consumer):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Select option &lt;code&gt;2. Consumer&lt;/code&gt; when prompted. This will start the Rider, Billing, and Notification consumers in the background, listening for events.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In Terminal 2 (The Producer):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   node main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Select option &lt;code&gt;1. Producer&lt;/code&gt; when prompted. This will start the interactive CLI where you can create new orders, accept them, and mark them as ready.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Play around!&lt;/strong&gt;
In the Producer terminal, create an order (e.g., &lt;code&gt;2/101/Pizza/500&lt;/code&gt;). Then watch the magic happen in the Consumer terminal as the different services independently pick up the events and process them!&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;By decoupling our services using Kafka, we've built a highly scalable foundation. If the billing service goes down, the restaurant can still accept orders. If we want to add a new "Analytics" service, we just plug in another consumer to listen to the topics—no changes needed to the existing codebase!&lt;/p&gt;

&lt;p&gt;That's the beauty of Event-Driven Architecture. Happy coding! 🚀&lt;/p&gt;

</description>
      <category>node</category>
      <category>kafka</category>
      <category>architecture</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>Building an MVP Agentic Tool-Use Bot with Node.js and OpenRouter 🌤️🤖</title>
      <dc:creator>Ankit Halder</dc:creator>
      <pubDate>Tue, 08 Sep 2026 05:12:20 +0000</pubDate>
      <link>https://dev.to/ankit_halder_7840b622b962/building-an-mvp-ai-weather-agent-with-nodejs-and-openrouter-49eg</link>
      <guid>https://dev.to/ankit_halder_7840b622b962/building-an-mvp-ai-weather-agent-with-nodejs-and-openrouter-49eg</guid>
      <description>&lt;p&gt;Have you ever wanted to build your own ChatGPT-like interface that can actually &lt;em&gt;do&lt;/em&gt; things? Today, we're going to break down &lt;strong&gt;Mausam AI&lt;/strong&gt;, a chatbot built with Node.js that can check real-time weather, temperature, and humidity for any city.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;⚠️ Disclaimer:&lt;/strong&gt; This project is an MVP (Minimum Viable Product). It is &lt;strong&gt;not a production-ready application&lt;/strong&gt;. Instead, it serves as a conceptual demonstration of an Agentic Tool-Use architecture.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔗 &lt;strong&gt;GitHub Repository:&lt;/strong&gt; [&lt;a href="https://github.com/OriginalAnkit/ai-rag-mausam-ai" rel="noopener noreferrer"&gt;https://github.com/OriginalAnkit/ai-rag-mausam-ai&lt;/a&gt;]&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9mzr4pa1fcfy6xgc14ee.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9mzr4pa1fcfy6xgc14ee.png" alt="Mausam AI" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Screen shot of Mausam AI
&lt;/h4&gt;

&lt;p&gt;Let's dive into how the code works!&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Agentic Tool-Use and Why Do We Need It?
&lt;/h2&gt;

&lt;p&gt;To understand why tool-use is so important, we first need to understand a massive limitation of Large Language Models (LLMs):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trained models don't have real-time data.&lt;/strong&gt; &lt;br&gt;
An LLM's knowledge is frozen in time based on when it was trained. If you ask a standard, isolated model, "What is the weather in Mumbai right now?", it will either hallucinate a random answer or apologize, stating that it cannot browse the live internet. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is where Agentic workflows come in.&lt;/strong&gt;&lt;br&gt;
Instead of relying solely on the LLM's static internal memory, we give the LLM a tool (&lt;code&gt;get_mausam&lt;/code&gt;) that it can call to fetch the live, real-time weather report from an external API (&lt;code&gt;wttr.in&lt;/code&gt;). We then inject that live data straight back into the conversation context so the LLM can generate an accurate, up-to-the-minute response!&lt;/p&gt;


&lt;h2&gt;
  
  
  1. The Brains: System Prompts and Agent Logic
&lt;/h2&gt;

&lt;p&gt;The magic of this bot lives in &lt;code&gt;helper.js&lt;/code&gt;. Instead of just asking the LLM to write text, we force the LLM to think in a structured loop: &lt;code&gt;START&lt;/code&gt; ➡️ &lt;code&gt;PLAN&lt;/code&gt; ➡️ &lt;code&gt;TOOL&lt;/code&gt; ➡️ &lt;code&gt;OUTPUT&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;We achieve this using a strict system prompt and forcing the response format to JSON.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MAIN_SYSTEM_PROMPT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
You are an AI agent that reply only to queries related to weather, temperate and humidity.

STRICT RULES:
- output must a single valid json without any extra space, text. NO markdown , No Text, No output tags.
- MUST run one step at a time. Do not run multiple steps in parallel. Stop after each step
- Strictly follow the Sequence of steps must be START then PLAN then TOOL then OUTPUT
- don't run a step more than once for a single query.

OUTPUT FORMAT:
{
    "step": START|PLAN|TOOL|OUTPUT,
    "context": "string",
    "input": "string",
    "usefull": "boolean",
    "toolname": "string"
}

AVAILABLE TOOL:
- get_mausam -&amp;gt; return temperate, weather and humidity for a given location
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By enforcing this structure, our backend can read the JSON step by step. If the AI decides it needs to use a tool, it outputs &lt;code&gt;{"step": "TOOL", "toolname": "get_mausam", "input": "Mumbai"}&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Executing the Loop Safely
&lt;/h3&gt;

&lt;p&gt;Our backend intercepts this and executes the tool on behalf of the AI. To prevent infinite loops or hallucinations, we wrap it in a strict &lt;code&gt;MAX_ITERATIONS&lt;/code&gt; check with proper error boundaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getConversation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;iterations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MAX_ITERATIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;iterations&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;MAX_ITERATIONS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;iterations&lt;/span&gt;&lt;span class="o"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;completion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;callOpenRouterModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;outputContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;completion&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;choices&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="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="c1"&gt;// ... Parse JSON Output Safely ...&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;step&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;OUTPUT&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="c1"&gt;// The AI has the final answer&lt;/span&gt;
                &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SYSTEM&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;context&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="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;step&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TOOL&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toolname&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;get_mausam&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="c1"&gt;// The AI requested a tool. We fetch the data and feed it back!&lt;/span&gt;
                 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;tool_resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getWeather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                 &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;system&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;`RESPONSE FROM get_mausam: &lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;{tool_resp}&lt;/span&gt;&lt;span class="se"&gt;\`&lt;/span&gt;&lt;span class="s2"&gt; });
            } else {
                 // Intermediate thinking steps (START, PLAN)
                 context.push({ sender: "BOT", message: (output.context || 'Thinking') + '...' });
                 messages.push({ role: "system", content: outputContent });
            }
            await sleep(1000); // 1-second safety delay to prevent spamming
        } catch (error) {
            console.error("Agent loop error:", error.message);
            context.push({ sender: "SYSTEM", message: "An error occurred while processing your request." });
            return;
        }
    }
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. The Tool: Fetching Weather Data
&lt;/h2&gt;

&lt;p&gt;When the AI calls &lt;code&gt;get_mausam&lt;/code&gt;, it triggers a simple JavaScript &lt;code&gt;fetch&lt;/code&gt; to &lt;code&gt;wttr.in&lt;/code&gt;, an amazing console-oriented weather forecasting service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getWeather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;`https://wttr.in/&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;{encodeURIComponent(city)}?format=%c+%C+%t+%h+%T&lt;/span&gt;&lt;span class="se"&gt;\`&lt;/span&gt;&lt;span class="s2"&gt;;

    const response = await fetch(url);
    if (!response.ok) throw new Error(&lt;/span&gt;&lt;span class="se"&gt;\`&lt;/span&gt;&lt;span class="s2"&gt;Request failed&lt;/span&gt;&lt;span class="se"&gt;\`&lt;/span&gt;&lt;span class="s2"&gt;);

    const data = await response.text(); 
    return data.trim(); // Returns e.g., "☀️ Clear +22°C 45%"
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Resilient API Calls
&lt;/h2&gt;

&lt;p&gt;To keep our MVP robust against API key exhaustion, we built a fallback mechanism when calling OpenRouter. We use &lt;code&gt;try/catch&lt;/code&gt; to attempt the primary key, and automatically fail over to a backup client if an error is thrown.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://openrouter.ai/api/v1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&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;API_KEY&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://openrouter.ai/api/v1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&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;OPEN_ROUTER_KEY_2&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;callOpenRouterModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requestPayload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;liquid/lfm-2.5-2.6b:free&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;response_format&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;json_object&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;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;client1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;requestPayload&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="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;Primary key failed, trying fallback...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&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="nx"&gt;client2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;requestPayload&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;h2&gt;
  
  
  4. The Express Backend &amp;amp; Chat UI
&lt;/h2&gt;

&lt;p&gt;We wrap this entire logic inside a simple Express.js server (&lt;code&gt;app.js&lt;/code&gt;). To support multiple users concurrently without race conditions, we store chat states in a &lt;code&gt;sessions&lt;/code&gt; map, indexed by a unique &lt;code&gt;sessionId&lt;/code&gt; generated on the frontend.&lt;/p&gt;

&lt;p&gt;On the frontend (&lt;code&gt;index.ejs&lt;/code&gt;), we have a sleek dark-mode UI that generates the &lt;code&gt;sessionId&lt;/code&gt; via &lt;code&gt;sessionStorage&lt;/code&gt; and polls the &lt;code&gt;GET /messages?sessionId=...&lt;/code&gt; endpoint every second to stream in the AI's thoughts.&lt;/p&gt;

&lt;p&gt;We even styled the intermediate "thinking" steps differently than the final answer so users can peek into the AI's reasoning without it being visually distracting!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building Agentic pipelines doesn't require massive frameworks. By enforcing JSON schemas and writing a simple &lt;code&gt;while&lt;/code&gt; loop, you can give LLMs access to the outside world.&lt;/p&gt;

&lt;p&gt;Feel free to check out the &lt;a href="https://github.com/OriginalAnkit/ai-rag-mausam-ai" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; and tinker with it yourself!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>ai</category>
      <category>node</category>
    </item>
  </channel>
</rss>
