<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sandil Helitha Perera on Medium]]></title>
        <description><![CDATA[Stories by Sandil Helitha Perera on Medium]]></description>
        <link>https://medium.com/@sandilperera2003?source=rss-0afd30a96e02------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0tjNKeiGBj4xAmFl</url>
            <title>Stories by Sandil Helitha Perera on Medium</title>
            <link>https://medium.com/@sandilperera2003?source=rss-0afd30a96e02------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:18:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sandilperera2003/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker]]></title>
            <link>https://medium.com/@sandilperera2003/docker-4c92b1d3e5b4?source=rss-0afd30a96e02------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c92b1d3e5b4</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Sandil Helitha Perera]]></dc:creator>
            <pubDate>Mon, 07 Sep 2026 15:04:48 GMT</pubDate>
            <atom:updated>2026-09-07T15:04:48.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLO_CCswJn1bdZHryP8MZA.jpeg" /></figure><h4><strong>Docker images</strong></h4><p>Docker images are the blueprints or templates used to create Docker containers.</p><p>An image contains everything required to run an application, such as:</p><ul><li>Application code</li><li>Dependencies</li><li>Libraries</li><li>Runtime</li><li>Configuration</li></ul><p>An image is read-only and is used to create one or more containers.</p><h4><strong>Docker container</strong></h4><p>Docker container is a running instance of a Docker image.</p><p>If Docker image is the blueprint, Docker container is the actual running application created using that blueprint.</p><p>For example:</p><blockquote>Docker Image → Docker Container →Running Application</blockquote><p>We can create multiple containers from the same image.</p><p><strong>Docker network</strong></p><p>Docker network is a communication channel that allows containers to communicate with other containers.</p><p>For example, if we have:</p><blockquote>React Container → Backend Container → Database Container</blockquote><p>The containers need a way to communicate with each other. Docker networks provide this communication.</p><p>Containers connected to the same Docker network can communicate with each other using their <strong>container/service names</strong>.</p><p><strong>Docker volumes</strong></p><p>Docker volumes are used to store data outside the container’s writable layer.</p><p>This is important because containers are temporary. If a container is deleted, the data stored inside it can also be deleted.</p><p>Volumes are commonly used for databases.</p><p>Example:</p><blockquote>PostgreSQL Container → PostgreSQL Volume → Database Data</blockquote><p>Even if we remove and recreate the PostgreSQL container, the data can remain in the volume.</p><p><strong>Docker workflow</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K5ZmPaz3hAUJ5Rz7KgK_ow.jpeg" /><figcaption>Docker workflow</figcaption></figure><p><strong>Docker client</strong></p><p>Docker client is the UI/interface that we use to interact with Docker.</p><p>We can interact with Docker using:</p><ul><li>Command line</li><li>GUI applications</li><li>Docker Desktop</li></ul><p>For example:</p><p><em>docker run ubuntu</em></p><p>Here, we are using the Docker CLI to communicate with Docker. The Docker client sends our command to the Docker daemon.</p><p><strong>Docker host / Docker daemon</strong></p><p>Docker daemon is the background process that manages Docker.</p><p>It is responsible for things such as:</p><ul><li>Creating containers</li><li>Starting containers</li><li>Stopping containers</li><li>Creating networks</li><li>Creating volumes</li><li>Building images</li></ul><p>The Docker client communicates with the Docker daemon.</p><p>Docker Client → Docker Daemon → Containers / Images / Networks / Volumes</p><p><strong>Docker registry / Docker Hub</strong></p><p>Docker registry is a centralized repository used to store and distribute Docker images.</p><p>Docker Hub is the most commonly used for public Docker registry. This works like a library of Docker images.</p><p>For example, we can find images for:</p><p>Ubuntu</p><p>Node.js</p><p>Python</p><p>PostgreSQL</p><p>Redis</p><p>Nginx</p><p>MongoDB</p><p>We can pull an image from Docker Hub:</p><p><em>docker pull ubuntu</em></p><p>We can also publish our own image to Docker Hub using the our own credentials of the Docker hub</p><p><strong>How to create a Docker image?</strong></p><p>We normally create a Docker image using a <strong>Dockerfile</strong>. A Dockerfile contains instructions that tell Docker how to build the image.</p><p><strong>Most commonly used Dockerfile keywords</strong></p><p><strong>FROM</strong></p><p>Specifies the base image.</p><p>Example:</p><p><em>FROM node:20-alpine</em></p><p>This means we are using Node.js 20 Alpine as the base image.</p><p><strong>WORKDIR</strong></p><p>Specifies the working directory inside the container.</p><p><em>WORKDIR /app</em></p><p>After this, commands will normally execute from:</p><p>/app</p><p><strong>COPY</strong></p><p>Copies files from our local machine into the Docker image.</p><p><em>COPY . .</em></p><p>This means copy the current directory into the current working directory of the image.</p><p><strong>RUN</strong></p><p>Executes a command while building the Docker image.</p><p>For example:</p><p><em>RUN npm install</em></p><p>This installs the dependencies while the image is being built.</p><p><strong>EXPOSE</strong></p><p>Specifies the port that the application is expected to listen on.</p><p><em>EXPOSE 3000</em></p><p>Important: EXPOSE does not actually publish the port to the host.</p><p>For publishing a port, we use:</p><p><em>docker run -p 3000:3000 image-name</em></p><p><strong>ENV</strong></p><p>Defines environment variables inside the image/container.</p><p><em>ENV NODE_ENV=production</em></p><p><strong>ARG</strong></p><p>Defines a build-time variable.</p><p><em>ARG VERSION=1.0</em></p><p>ARG is mainly available while building the image.</p><p><strong>VOLUME</strong></p><p>Specifies a location intended for persistent data.</p><p><em>VOLUME /data</em></p><p>In real projects, volumes are often configured through Docker commands or Docker Compose.</p><p><strong>CMD</strong></p><p>Specifies the default command that runs when a container starts.</p><p><em>CMD [“node”, “hello.js”]</em></p><p>CMD can be overridden when running the container.</p><p><strong>ENTRYPOINT</strong></p><p>Defines the main executable of the container.</p><p><em>ENTRYPOINT [“node”]</em></p><p>It is normally used when we want the container to behave like a specific executable.</p><p>The main differences between CMD and ENTRYPOINT are:</p><p>CMD</p><p>· Default command/arguments</p><p>ENTRYPOINT</p><p>· Main executable</p><p>· They can also be used together.</p><p>For example:</p><p><em>ENTRYPOINT [“node”]</em></p><p><em>CMD [“hello.js”]</em></p><p>This effectively runs:</p><p>node hello.js</p><p><strong>How to pull an image and run it?</strong></p><p><strong>1. Create a separate directory</strong></p><p>Create a separate directory and open it in your default IDE.</p><p><strong>2. Pull the image</strong></p><p>Run this command in the terminal or command prompt:</p><p><em>docker pull ubuntu</em></p><p>This pulls the latest available Ubuntu image from the configured registry.</p><p>Note: We are pulling an Ubuntu Docker image, not the Ubuntu kernel.</p><p><strong>3. Create and run a container</strong></p><p><em>docker run -it ubuntu</em></p><p>Here:</p><p>docker run (Create and start a container)</p><p>-it (Interactive terminal)</p><p>ubuntu (Image used to create the container)</p><p>You will now get an Ubuntu terminal inside the container.</p><p>For example:</p><p>root@container-id:/#</p><p>We are now interacting with the Ubuntu environment inside the Docker container.</p><p>To leave the container:</p><p><em>exit</em></p><p><strong>How to create our own Docker image?</strong></p><p>Let’s create a simple Node.js application.</p><p><strong>1. Create the files</strong></p><p>Create a separate directory.</p><p>Inside the directory create:</p><p>docker-example/</p><p>├── Dockerfile</p><p>└── hello.js</p><p>Inside hello.js:</p><p>console.log(“Hello from Docker!”);</p><p><strong>2. Create the Dockerfile</strong></p><p><em>FROM node:20-alpine</em></p><p><em>WORKDIR /app</em></p><p><em>COPY . .</em></p><p><em>CMD [“node”, “hello.js”]</em></p><p>Let’s understand what happens:</p><p>FROM (Get Node.js environment)</p><p>WORKDIR (Create/use /app)</p><p>COPY (Copy our application files)</p><p>CMD (Run hello.js)</p><p><strong>3. Build the image</strong></p><p>Run:</p><p><em>docker build -t hello-docker .</em></p><p>Here:</p><p>docker build (Build an image)</p><p>-t hello-docker (Give the image a name)</p><p>. (Use the current directory as the build context)</p><p>We now have our own Docker image:</p><p>hello-docker</p><p><strong>4. Run the image</strong></p><p><em>docker run hello-docker</em></p><p>Output:</p><p>Hello from Docker!</p><p><strong>How to Dockerize a React application?</strong></p><p>Let’s assume we have a React application created using Vite.</p><p><strong>1. Create a simple React project</strong></p><p>For example:</p><p><em>npm create vite@latest react-docker</em></p><p>Then install dependencies:</p><p><em>npm install</em></p><p><strong>2. Create a Dockerfile</strong></p><p>Inside the project:</p><pre>FROM node:20-alpine<br>WORKDIR /app<br>COPY package*.json ./<br>RUN npm install<br>COPY . .<br>EXPOSE 5173<br>CMD [&quot;npm&quot;, &quot;run&quot;, &quot;dev&quot;, &quot; -- &quot;, &quot; -- host&quot;, &quot;0.0.0.0&quot;]</pre><p>The important part here is:</p><p>— host 0.0.0.0</p><p>Vite normally needs to listen on an accessible network interface so that the application can be accessed through the Docker port mapping.</p><p><strong>3. Create a .dockerignore file</strong></p><p>Create:</p><p>.dockerignore</p><p>Add:</p><pre>node_modules/<br>dist/<br>.git/</pre><p>We don’t want to copy unnecessary files into the Docker build context.</p><p><strong>4. Build the image</strong></p><p><em>docker build -t react-docker .</em></p><p><strong>5. Run the container with port mapping</strong></p><p><em>docker run -p 5173:5173 react-docker</em></p><p>The format is:</p><p>-p HOST_PORT:CONTAINER_PORT</p><p>Therefore:</p><p>5173:5173</p><p>means:</p><p>Host machine port 5173 → Container port 5173</p><p>Now we can access the React application through:</p><p><a href="http://localhost:5173/">http://localhost:5173</a></p><p><strong>Problem with Docker during development</strong></p><p>There is a problem when developing applications using Docker.</p><p>Suppose we change <em>App.jsx </em>on our local machine.</p><p>The running Docker container may still contain the old version of the code. Therefore, we need to rebuild the image every time we change the code. Hence this is not convenient during development.</p><p>So how can we solve this?</p><p><strong>The solution is bind mounts / volumes.</strong></p><p><strong>Using volumes during React development</strong></p><p>First stop the currently running container.</p><p>Then run:</p><p><em>docker run -p 5173:5173 -v “$(pwd):/app” -v /app/node_modules react-docker</em></p><p>On Windows, the exact $(pwd) syntax can differ depending on whether you are using PowerShell, CMD, Git Bash, or WSL.</p><p><strong>How to publish a Docker image to Docker Hub?</strong></p><p>First, we need a Docker Hub account.</p><p><strong>1. Login</strong></p><p>type: <em>docker login</em></p><p><strong>2. Tag the image</strong></p><p>Suppose our local image is:</p><p>react-docker</p><p>We need to tag it using our Docker Hub username:</p><p><em>docker tag react-docker &lt;username&gt;/react-docker</em></p><p>For example:</p><p>myusername/react-docker</p><p>The general format is:</p><p>&lt;username&gt;/&lt;image-name&gt;</p><p><strong>3. Push the image</strong></p><p><em>docker push &lt;username&gt;/react-docker</em></p><p>Now the image is uploaded to Docker Hub.</p><p>Other people can pull it using:</p><p>docker pull &lt;username&gt;/react-docker</p><p><strong>How to use Docker Compose?</strong></p><p>When our application becomes more complicated, we may have multiple containers.</p><p>For example:</p><blockquote>React → Backend → PostgreSQL</blockquote><p>Managing every container separately can become difficult. This is where Docker Compose comes in.</p><p>Docker Compose allows us to define and manage multiple Docker services using one configuration file.</p><p><strong>Creating a Docker Compose project</strong></p><p><strong>1. Create a React project</strong></p><p><strong>2. Run Docker Init</strong></p><p>Inside the project directory:</p><p><em>docker init</em></p><p>Docker will help create files such as:</p><p>Dockerfile</p><p>.dockerignore</p><p>compose.yaml</p><p>Depending on the project and Docker version, the generated files can vary.</p><p><strong>Docker Compose file</strong></p><p>Inside compose.yaml, we define our services.</p><p>For example:</p><pre>services:<br>  web:<br>    build:<br>      context: .<br>    ports:<br>      - &quot;5173:5173&quot;<br>    volumes:<br>      - .:/app<br>      - /app/node_modules</pre><p>Let’s understand this.</p><p><strong>services</strong></p><p>services:</p><p>Defines the different services/containers that make up our application.</p><p>For example:</p><p>services:</p><p>web:</p><p>backend:</p><p>database:</p><p><strong>web:</strong></p><p>This is the name of our service.</p><p><strong>build</strong></p><p><em>build:</em></p><p><em>context: .</em></p><p>This tells Docker Compose where the Dockerfile and build context are located.</p><p>. means: Current directory</p><p><strong>ports:</strong></p><p>- “5173:5173”</p><p>Maps:</p><p>Host port 5173 → Container port 5173</p><p><strong>volumes</strong></p><p>volumes:</p><p>- .:/app</p><p>- /app/node_modules</p><p>The first volume:</p><p>.:/app</p><p>mounts the current local directory into /app inside the container.</p><p>The second:</p><p>/app/node_modules</p><p>keeps the container’s node_modules separate.</p><p>This is useful during development because changes made locally can immediately be reflected inside the container.</p><p><strong>Running Docker Compose</strong></p><p>Once we have the compose.yaml file, we can start the application using:</p><pre>docker compose up</pre><p>Docker Compose reads the configuration and creates the required containers.</p><p>To run in the background:</p><p><em>docker compose up -d</em></p><p>The -d means <strong>detached mode</strong>.</p><p>To stop the services:</p><p><em>docker compose down</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c92b1d3e5b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When Rewards Fail: Why AI Needs Inverse Reinforcement Learning]]></title>
            <link>https://medium.com/@sandilperera2003/when-rewards-fail-why-ai-needs-inverse-reinforcement-learning-5c498b488656?source=rss-0afd30a96e02------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c498b488656</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Sandil Helitha Perera]]></dc:creator>
            <pubDate>Mon, 03 Aug 2026 01:10:13 GMT</pubDate>
            <atom:updated>2026-08-03T01:10:13.378Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Imagine you want to train your puppy to understand your everyday language. If you say “sit,” the puppy instantly sits down on the floor. Then you give it a piece of bacon as a reward. If you say “jump” and it sits on the floor instead, then you do not give it the bacon. Using this same method, we can teach robots to talk, walk, run, and perform many other tasks. Learning happens through trial and error, good choices get rewards, while bad choices get nothing.</em></p><h3>The five missing pieces of the puzzle</h3><p>First, you need to understand five key components used when training your dog. Let’s identify each missing piece of the puzzle.</p><p>1. Agent: The dog (Decision maker)</p><p>2. Environment: Everything the dog interacts with</p><p>3. State: What is happening right now? The current situation the dog observes.</p><p>4. Action: What does the dog decide to do? (sit, bark or eat)</p><p>5. Reward: Feedback given after an action. A treat gives a positive reward, while not receiving a treat gives little or no reward. (Gives the bacon or not giving the bacon to the dog)</p><p>In standard Reinforcement learning, the dog gradually learns a policy (a strategy for choosing the best action in each situation) that maximizes rewards over time. We can represent this using the following equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*iVLWaHH4_aWboZByJCEUeA.png" /></figure><p>R — Reward function</p><p>π– Policy function (the routine or path the agent follows).</p><p>s — State (Current state of the environment)</p><p>a — Action (Action choose by the agent)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BubdOA9VgoPua7Y3EZno_A.png" /></figure><h3>Reward Engineering Crisis</h3><p>Imagine you want to train your dog to perform special tasks, such as guiding a blind owner. For these kinds of tasks, how do you define the reward function (the treat rules)? Because of the many different situations the dog may encounter, it is difficult to define a fixed set of rewards. As a result, creating a good reward function becomes very challenging.</p><p>For example, if you give the dog a treat every time it brings you your slipper, the dog may discover a loophole. It could start hiding your slippers behind the couch just so it can bring them back to you 20 times a day and earn more treats.</p><p>Similarly, if you give the dog a treat every time it barks at strangers near the door, it may start barking at the wind blowing through the window because it has learned that barking often leads to a reward.</p><p>These are examples of <strong>reward hacking</strong> (or “treat hacking”). The agent finds unintended ways to maximize its rewards without actually completing the task as intended. This is why defining a good reward function for complex, nuanced behaviors are extremely difficult. You can easily end up rewarding bad habits instead of the behavior you actually wanted.</p><h3>Inverse Reinforcement Learning (IRL)</h3><blockquote>A machine learning method that figures out an agent’s hidden reward function by watching its behavior or expert choices</blockquote><p>In standard Reinforcement Learning, we define the reward function for the agent. In Inverse Reinforcement Learning (IRL), the agent figures out the reward function by observing an expert’s behavior or demonstrations.</p><p>Imagine you bring a new puppy, but you also have a perfectly trained service dog in the house. You don’t know the exact treat schedule that was used to train the service dog. The puppy watches the service dog navigate busy streets, pause before crossing roads, and ignore fallen food on the sidewalk. By observing the service dog, the puppy begins to reverse-engineer the values behind its behavior: safety matters more than speed, ignoring food on the ground is better than eating it, and pausing at the curb leads to better outcomes.</p><p>Puppy does not mindlessly copy movements, it is learning what the master dog cares about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*TIaGElAPzMwV-5kdbEIv_w.png" /></figure><p>Here, the observed expert policy is used to infer the hidden reward function that explains why those actions were chosen.</p><p>IRL is valuable when it’s difficult to manually specify rewards:</p><ul><li>Autonomous driving cars: learn driving preferences from humans.</li><li>Robotics: learn tasks from demonstrations.</li><li>Healthcare: infer treatment objectives from expert clinicians.</li><li>Human behavior modeling: understand decision-making processes.</li></ul><h3>Conclusion</h3><p>Inverse Reinforcement Learning allows machines to understand the hidden goals and preferences behind an expert’s actions instead of simply copying their behavior. By observing demonstrations, an agent can discover the reward function that explains why certain decisions are made. This makes IRL useful for complex tasks where manually defining every possible reward rule is difficult.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c498b488656" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why can’t AI Agents remember?]]></title>
            <link>https://medium.com/@sandilperera2003/why-cant-ai-agents-remember-68b4a278734b?source=rss-0afd30a96e02------2</link>
            <guid isPermaLink="false">https://medium.com/p/68b4a278734b</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Sandil Helitha Perera]]></dc:creator>
            <pubDate>Sat, 20 Jun 2026 11:49:15 GMT</pubDate>
            <atom:updated>2026-06-20T11:49:15.627Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Imagine becoming the CEO of the best fast-growing startup. You have access to the world&#39;s most brilliant advisors. They can analyze the market with split seconds, predict risks and possess the finest reasoning. But every 30 minutes they lose all memory of your conversation. They forget about your company mission, goals, the decisions you made earlier in the day and even why the meeting began in the first place. By the end of the day your team trapped in endless loop of explaining the same thing to the agent.</em> The limitation is never the intelligence; it is the inability to retain and evolve from past experiences.</p><h3><strong>Why memory matters for AI Agents?</strong></h3><p>Human relationships are built on accumulated experiences. We remember the experiences of human beings and their reactions to specific situations. Memory transforms isolated interactions into meaningful, continuous relationships. For AI agents, memory serves the same purpose, it allows agents to remember past conversations, understand evolving user needs and build knowledge over time, transforming isolated prompts into persistent, intelligent relationships. There are two memory augmentation architectures that extends the capability of LLMs to access external information beyond its context window.</p><h3>RAG vs MAG</h3><blockquote><a href="https://towardsdatascience.com/beyond-rag/">RAG gave AI the ability to read and reference data effectively, MAG gives AI a digital “second brain” that remembers you, your goals, and your past projects.</a></blockquote><p>Both RAG and MAG can be viewed as external memory paradigms, but only MAG is designed as a long-term memory paradigm for AI agents. <strong>RAG</strong> (Retrieval augmented generation) is a technique used to increase the accuracy of LLMs by fetching information from external documents to generate a valid response. Typically, this information is stored in vector databases and retrieved during inference. Stored information is usually composed of static documents (PDF, docs, excel) which do not represent agents’ evolving experience.<strong> MAG</strong> (memory augmented generation) is a system architecture that gives generative models such as Large Language Models (LLMs) a persistent memory, allowing them to recall past interactions, user preferences and historical context across different conversations and tasks. MAG allows AI agents to reason about past experiences and events. Traditional RAG systems usually treat the knowledge base as a static repository, while MAG treats it as a cognitive structured evolving state.</p><h3>Why can’t we use massive context windows?</h3><p>This is a common misconception worth debunking. Because massive context windows with large number of tokens introduces context decay. Context decay is closely tied to the “lost-in-the-middle” phenomenon, a specific failure mode where an LLM is particularly prone to forgetting or ignoring critical details that are buried in the middle of a large context window. Because base LLMs lack an intrinsic, persisted, stable internal memory mechanism, information becomes inaccessible during inference once they falls outside of the context window. Personalized memory usually implemented as external layer on top of the model. <em>Imagine writing an important note on a whiteboard with limited space. Adding new information requires erasing old. At first only irrelevant details disappear but eventually critical information gets cleared as well. This is the essence of context decay.</em> There are several underlying mechanistic factors that affect context decay:</p><p><strong>Attention dilution:</strong> As more tokens are added to the context, the model’s attention mechanism gets spread too thin across the text.</p><p><strong>Positional encoding limitations:</strong> The model’s architecture struggles to accurately represent and retain the exact positions of tokens that are separated by vast distances.</p><p><strong>Token interference:</strong> Competing pieces of information within a massive prompt can interfere with the model’s ability to isolate the specific details needed for a given reasoning task.</p><p>While many companies promote unlimited context windows, utilizing full windows at scale is economically toxic. depending on the provider and model, costs for million-token contexts can run from well under a dollar to several dollars per million tokens.</p><h3>What is the solution?</h3><p>In reality, both biological and artificial memory systems are far more sophisticated. Similar to humans, AI agents must not only remember information but also determine what should be retained, what can be forgotten and how knowledge should be organized. Consequently, modern memory architectures possess multiple advanced memory networks, each responsible for distinct aspect of information processing and retention.</p><ol><li><strong>Temporal Graph</strong>: This network connects events in a strict chronological order. This gives AI agents a concrete sense of timeline accountability, allowing them to perform chronological reasoning by linking ordered pairs of events. This graph acts as an immutable, directed chain that connects memory events based on their timestamps. If the system detects a “When” question, this retrieval mechanism biases its search heavily towards this temporal chain.</li><li><strong>Causal Graph</strong>: This network consists of directed edges that represent logical cause-and-effect deduction between memories. It explicitly supports the agent’s ability to answer “Why” queries by mapping out how one event led to another.</li><li><strong>Semantic Graph</strong>: This network uses undirected edges to connect conceptually similar events rather than temporal or causal similarities. It links memories based on their associative proximity, specifically using the cosine similarity of their dense vector embeddings.</li><li><strong>Entity Graph</strong>: This network connects individual memory events to shared, abstract entity nodes. This structure helps solve the “object permanence” problem, allowing the agent to track the same person, place, or object across completely disjoint segments of its timeline.</li></ol><p>With these four network graphs it is possible to maintain a consistent behavioral pattern for the AI agent that resembles coherent personality over time.</p><h3>Then how does the agent use its memory?</h3><p>When user sends a message AI agents should respond quickly. If the Agent tries to perform complex reasoning and thinking, it may fail to communicate with in minimum period of time. There is Dual stream memory evolution pipeline that is explicitly designed to solve this latency related problems during the inference process of AI agents.</p><p><strong>Fast path (synaptic ingestion)</strong></p><p>This is a synchronous low latency loop that directly operates on the user interactions. This immediately creates a directed temporal edge from the previous node to the current node and behaves like a write through memory, no waiting for batch processing and no dependency on LLM inference cycles. This is not designed for deep reasoning but for fast ingestion and lightweight indexing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*36RILFY9cKl6sHQ7AOcCCA.png" /></figure><p><strong>The Slow Path (Structural Consolidation)</strong></p><p>System process memories asynchronously in the background for deeper understanding and reasoning. This path consolidates raw memories into structured knowledge.<em> Imagine an AI librarian working after hours, during the daytime books are placed on the shelf so that visitors can find them easily (fast path), at night librarian reorganizes the books and create cross references (slow path).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_o-lkHByAYZDEQtPbpmLQ.png" /></figure><h3>How can we integrate personality to the Agent?</h3><p>Just as humans possess personality, AI agents can also be endowed with a unique personality. This is not encoded in a single component rather it emerges from a complex subsystem of all the components inside the agent (memory, inference, cache, etc.) Agents&#39; personality can be defined mathematically using several factors and three specific axes, each scored from 1–5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yptJxTy_w9hQ-LFsomR4TQ.png" /></figure><p><strong>Skepticism:</strong> This ranges from flexible (1) to skeptical (5). Higher numbers encourage cautious evaluation of claims while lower numbers foster exploratory behavior.</p><p><strong>Literalism:</strong> Ranges from flexible (1) to literal (5). High literalism forces the agents to focus on exact wording while low literalism encourages reading between the lines and interpreting implicit meanings.</p><p><strong>Empathy:</strong> Ranges from detached (1) to empathetic (5). High empathy ensures that the agent uses supportive and emotional language while low empathy focuses on blunt, task first communication.</p><p>Suppose there are two agents “Agent A” and “Agent B”. User feeds this sentence to those agents <em>“Employees working remotely reported greater flexibility but attended fewer in person meetings”</em>. We can analyze the behaviors of two agents:</p><p><strong>Agent A</strong> (Trusting and empathetic) — This agent values employee wellbeing and autonomy. It may reason that remote work is beneficial because this sentence explicitly stated that remote work increases flexibility.</p><p><strong>Agent B</strong> (Skeptical and Literal) — This agent is more structured and accountable to its actions. It may reason that remote work is not beneficial because there are fewer in person interactions that have a tendency to reduce the accountability. Hence personality determines which facts receive more importance, which relationships are emphasized and how tradeoffs are evaluated.</p><h3>What do you think?</h3><p>As we continue to explore agentic memory architectures, the challenge is no longer building larger models, but building structured systems that remember, reflect and learn from experience. Perhaps the next major breakthrough in AI may come from discovering new ways to remember and evolve from the experience.</p><h3>References</h3><ol><li>Jiang, Dongming, Yi Li, Guanpeng Li, and Bingzhe Li. <strong>“MAGMA: A Multi-Graph based Agentic Memory Architecture for AI Agents.”</strong></li><li>Hu, Chuanrui, Xingze Gao, Zuyi Zhou, Dannong Xu, Yi Bai, Xintong Li, Hui Zhang, Tong Li, Chong Zhang, Lidong Bing, and Yafeng Deng. <strong>“EverMemOS: A Self-Organizing Memory Operating System for Structured Long-Horizon Reasoning.”</strong></li><li>Latimer, Chris, Nicoló Boschi, Andrew Neeser, Chris Bartholomew, Gaurav Srivastava, Xuan Wang, and Naren Ramakrishnan. <strong>“HINDSIGHT IS 20/20: BUILDING AGENT MEMORY THAT RETAINS, RECALLS, AND REFLECTS.”</strong></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68b4a278734b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MCP VS API: “USB-C” for AI changing everything]]></title>
            <link>https://medium.com/@sandilperera2003/mcp-vs-api-usb-c-for-ai-changing-everything-91f79f80f515?source=rss-0afd30a96e02------2</link>
            <guid isPermaLink="false">https://medium.com/p/91f79f80f515</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sandil Helitha Perera]]></dc:creator>
            <pubDate>Tue, 10 Feb 2026 06:43:27 GMT</pubDate>
            <atom:updated>2026-05-28T14:26:28.589Z</atom:updated>
            <content:encoded><![CDATA[<h3>Giving AI “Hands”</h3><p>Right now, Large Language Models (LLMs) are like “brains in a jar.” They are incredibly smart, but they can’t actually <em>do</em> anything outside of their chat window without developer intervention.</p><p>To give an AI the ability to check your calendar, query a database, book an appointment in Calander or post to Slack, we currently use a technique called <strong>Function Calling</strong> (or Tool Use). However, this creates a massive manual overhead:</p><pre>@tool<br>def multiply(a: int, b: int) -&gt; int:<br>    &quot;&quot;&quot;Multiply two integers.&quot;&quot;&quot;<br>    return a * b</pre><ul><li><strong>Manual Schema Definition:</strong> For every single tool, you have to write a JSON schema that describes the function name, its parameters, and what it returns. If the API changes, your schema breaks.</li><li><strong>The Glue Code Nightmare:</strong> You have to write “wrapper” code that takes the AI’s request, authenticates with a specific API key, executes the call, and then translates the result back into a format the AI understands.</li><li><strong>Security Fragmentation:</strong> You end up managing API keys and permissions in ten different places for ten different services.</li></ul><h3>The M×N Complexity</h3><p>In the current ecosystem, integrations are <strong>point-to-point</strong>.</p><ul><li><strong>M</strong> = The number of AI Applications (Claude, ChatGPT, Cursor).</li><li><strong>N</strong> = The number of Data Sources/Tools (GitHub, Jira, Google Drive, Local Postgres DB).</li></ul><p>If you want every AI app to talk to every data source, you face <strong>M x N </strong>complexity. You have to build a custom integration for every single pairing. If you add 1 new tool, you have to update 5 different AI apps to support it. This is a heavy toll on developer time that slows down the adoption of AI agents.</p><h3>Making APIs “AI-Readable”</h3><p>Before web browsers, if you wanted to access data from a server, you needed a specific client for that specific protocol. The browser standardized how we “view” data. MCP standardizes how AI “uses” data.</p><ul><li><strong>APIs</strong> were designed for humans to read documentation and write code.</li><li><strong>MCP</strong> is designed for the LLM to “inspect” the server and understand the tools available without needing a human to write a new schema.</li></ul><p>Instead of the developer saying, <em>“Here is how you call the GitHub API,”</em> the developer says, <em>“Here is an MCP Server for GitHub.”</em> The AI then connects to that server and asks, <em>“What tools do you have?”</em> The server responds with its own capabilities.</p><h3>A Technical Comparison</h3><p>Analogy of “Before vs After of MCP”:</p><ul><li><strong>Before MCP:</strong> You are a translator in a room with 10 people speaking 10 different languages. You have to learn every language to help them communicate.</li></ul><p>In the traditional world, if you want your AI to use a tool (like a simple Weather API), you have to manually define a schema that the LLM can understand. This is brittle and wordy.</p><pre># You have to manually write this JSON schema for every tool<br>weather_tool_schema = {<br>    &quot;name&quot;: &quot;get_weather&quot;,<br>    &quot;description&quot;: &quot;Get the current weather in a user specifies location&quot;,<br>    &quot;parameters&quot;: {<br>        &quot;type&quot;: &quot;object&quot;,<br>        &quot;properties&quot;: {<br>            &quot;location&quot;: {&quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;The city and state, e.g. San Francisco, CA&quot;},<br>            &quot;unit&quot;: {&quot;type&quot;: &quot;string&quot;, &quot;enum&quot;: [&quot;celsius&quot;, &quot;fahrenheit&quot;]}<br>        },<br>        &quot;required&quot;: [&quot;location&quot;]<br>    }<br>}<br><br># Then you have to write the logic to call the actual API<br>def get_weather(location, unit=&quot;celsius&quot;):<br>    return f&quot;The weather in {location} is 22 degrees {unit}.&quot;<br><br># Finally, you have to integrate this with the LLM provider</pre><ul><li><strong>After MCP:</strong> Everyone agrees to speak one universal language. You only need to know that one language to facilitate the entire room.</li></ul><p>Hence, In the API world, the developer is the translator. In the MCP world, the developer is the architect. We are moving away from writing ‘how’ to connect and moving toward defining ‘what’ the AI is allowed to access.</p><h3>What is MCP?</h3><blockquote>Model Context Protocol (MCP) is an open-standard protocol that enables AI models to seamlessly swap data and tools across different platforms without custom code for every integration.</blockquote><p>It was developed to solve the “isolation” of LLMs. Instead of a developer having to build a “bridge” for every new data source, MCP provides a “standardized dock” where data sources can simply plug in. Evolution of the MCP era can be categorized to three sections.</p><ul><li><strong>The “Proprietary” Era (Pre-USB):</strong> Recall the early 2000s. If you had a Nokia phone, a Sony camera, and a Dell laptop, you needed three different charging cables and three different data transfer cords. If you lost one, you were stuck. This is where AI is today. If you want Claude to read your GitHub and ChatGPT to read your GitHub, you have to build two separate integrations using two different SDKs.</li><li><strong>The Universal Standard (The USB-C Era):</strong> Then came USB-C. One cable to rule them all. It doesn’t matter if the device is a mouse, a monitor, or a hard drive, if it has a USB-C port, it just “works.” MCP is that port for AI. It allows any AI <em>“Host”</em> (the laptop) to talk to any <em>“Server”</em> using one single language.</li><li><strong>Negotiation at the Port:</strong> When you plug a phone into a laptop via USB-C, they<em> communicate</em> to each other instantly: <em>“I can provide 20W of power, and I have 500GB of files. What do you need?”</em> MCP does the same: When an AI connects to an MCP server, the server says, <em>“I have a tool called ‘search_files’ and a resource called ‘user_logs’. Here is how you use them.”</em> The developer doesn’t have to explain the tools to the AI, the tools explain themselves.</li></ul><h3>How it Works?</h3><p>MCP isnt just a new way to call an API, its a different way to organize a system. In a traditional setup, your app talks directly to an API. In MCP, we add a layer of separation that makes the system<em> “Agentic.”</em></p><p>To understand the concept more clearly we will take the Three-Tier Architecture: The Chain of Command<br>Think of this like a high-end restaurant:</p><p><strong>1. The Host</strong> (The &quot;Dining Room&quot;)<br><em>The user interface where the AI conversation happens.</em></p><p><em>Examples</em>: Claude Desktop, Cursor, or a custom internal dashboard you’ve built for your company.</p><p>It is the &quot;container.&quot; It doesn&#39;t know how to talk to GitHub or Slack; it just knows it has an LLM that needs data. It manages the user’s session and permissions.</p><p><strong>2. The Client</strong> (The &quot;Maitre D&quot;)<br><em>It is a hidden component living inside the Host.</em></p><p>The Client is the bridge. Its only responsibility is to maintain a connection to various servers. When you integrate a new tool, the Client is what does the handshake. It asks the Server: <em>&quot;What&#39;s on the menu today?&quot; </em>and then tells the AI model what tools are available.</p><p><strong>3. The Server</strong> (The &quot;Kitchen&quot;)<br><em>It is a small, lightweight program (can be local or remote) that actually &quot;knows&quot; how to do things.</em></p><p>This is the Translator. It takes a structured request from the AI and converts it into a traditional REST API call to GitHub.</p><p>The Key Difference: The Server doesn&#39;t just return raw data, it returns Context. It packages the API response into a format that the LLM can digest immediately.</p><h3><strong>Why You Should Care?</strong></h3><p>In traditional development, if you add a &quot;Delete File&quot; feature to your API, your AI won&#39;t know it exists until you manually update its prompt and redeploy your code. With MCP, the discovery happens at runtime. When your AI agent starts, it asks the MCP server, &quot;What can you do today?&quot; If you’ve added a new tool to the server, the agent immediately sees it and knows how to use it. This means your agents get &quot;smarter&quot; the moment your backend evolves, without a single line of frontend or prompt-engineering change.</p><p><strong>Contextual Efficiency</strong><br>One of the biggest costs in AI development is the &quot;Prompt Tax.&quot; Developers often &quot;stuff&quot; the prompt with every piece of user data just in case the AI needs it.</p><p><em>The API Way</em>: You fetch a 2,000-line JSON of user data and dump it into the prompt.</p><p><em>The MCP Way</em>: You give the AI a resource pointer. The model only &quot;pulls&quot; the specific lines it needs when it reaches that step in its reasoning. This is &quot;Just-in-Time Context.&quot; It saves thousands of tokens per request, reduces &quot;hallucinations&quot; caused by information overload, and directly lowers your API bill.</p><p><strong><em>The Protocol Layer:</em></strong><em> Under the hood, MCP uses </em><strong><em>JSON-RPC 2.0</em></strong><em>. This is the “secret sauce” that makes it lightweight. It doesn’t care if the connection is a local process (Stdio) or a remote web server (SSE). It’s just a standard way for the Brain (LLM) to send a request and the Hands (Server) to send back a result.</em></p><h3><strong>Conclusion</strong></h3><p>MCP represents a shift in how AI systems connect to the outside world. Instead of building countless custom integrations between each AI application and every tool or data source, MCP introduces a universal, discoverable interface that allows models to understand and use capabilities dynamically. This reduces integration overhead, improves scalability, and allows AI agents to evolve alongside backend systems without constant redevelopment.</p><p>While APIs remain essential, MCP reframes integration from manual wiring to standardized capability discovery, enabling more autonomous and adaptable AI systems. If broadly adopted, it could do for AI tooling what USB-C did for hardware, simplifying connections, accelerating innovation, and lowering the barrier for building powerful, tool-using AI agents.</p><p>In short, MCP moves us closer to AI systems that don’t just <em>know</em> things, but can reliably <em>do</em> things more securely, efficiently, and at scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91f79f80f515" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>