<?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: Boussaden Taha</title>
    <description>The latest articles on DEV Community by Boussaden Taha (@tahaboussaden).</description>
    <link>https://dev.to/tahaboussaden</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%2F3900404%2F3d52ed42-22fc-4c43-ae31-2fa1c39461d3.jpeg</url>
      <title>DEV Community: Boussaden Taha</title>
      <link>https://dev.to/tahaboussaden</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tahaboussaden"/>
    <language>en</language>
    <item>
      <title>Agents</title>
      <dc:creator>Boussaden Taha</dc:creator>
      <pubDate>Sat, 09 May 2026 09:17:15 +0000</pubDate>
      <link>https://dev.to/tahaboussaden/agents-4acj</link>
      <guid>https://dev.to/tahaboussaden/agents-4acj</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article is my point of view on agents with a technical deep dive on them. I'll be sharing my journey on how I built a working AI agent from scratch, decomposing every component and discussing the trade offs, the latency, the cost and reliability all along.&lt;br&gt;
My goal is to make this deterministic system that's wrapped around a probabilistic core explicit.&lt;/p&gt;
&lt;h2&gt;
  
  
  Defining an AI Agent
&lt;/h2&gt;

&lt;p&gt;Before building anything, we need to draw hard boundaries between three commonly conflated systems, which are scripts, chatbots and finally agents.&lt;/p&gt;
&lt;h3&gt;
  
  
  Assumptions
&lt;/h3&gt;

&lt;p&gt;You should be comfortable with JavaScript (async/await, APIs), Basic HTTP concepts and JSON data structures.&lt;/p&gt;
&lt;h4&gt;
  
  
  Scripts (Deterministic Program)
&lt;/h4&gt;

&lt;p&gt;A script is a just fixed mapping:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    y=f(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Same input → same output&lt;/li&gt;
&lt;li&gt;No adaptation&lt;/li&gt;
&lt;li&gt;No internal state beyond execution context
for example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function classify(input){
      if(input.includes("error")) return "bug";
      return "general";
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With no notion of iteration, decision under uncertainty or external tool usage.&lt;/p&gt;

&lt;h4&gt;
  
  
  Chatbots (Single-Step LLM System)
&lt;/h4&gt;

&lt;p&gt;A chatbot introduces probabilistic behavior:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y∼p(y∣x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is generated from a probability distribution, so still just a single step with no iterative reasoning loop and no explicit action execution.&lt;/p&gt;

&lt;p&gt;for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const response = await llm("Explain recursion simply");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even with conversation history, this remains a mapping, not a system, with no persistent goal tracking and no structured interaction with the environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  Agent (Iterative, Stateful System)
&lt;/h4&gt;

&lt;p&gt;An agent is fundamentally different:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    at∼π(a∣st),st+1=f(st,at,rt)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mathematical Term&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Code Representation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;( st )&lt;/td&gt;
&lt;td&gt;Current state&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;state&lt;/code&gt; object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;( at )&lt;/td&gt;
&lt;td&gt;Chosen action&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;action&lt;/code&gt; JSON&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;( rt )&lt;/td&gt;
&lt;td&gt;Tool execution result&lt;/td&gt;
&lt;td&gt;&lt;code&gt;result&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;( \pi )&lt;/td&gt;
&lt;td&gt;Policy (decision model)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;llm()&lt;/code&gt; function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;( f )&lt;/td&gt;
&lt;td&gt;State transition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;updateState()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    async function step(state, memory){
      const action = await policy(state, memory);   // at
      const result = await execute(action);         // rt
      const nextState = updateState(state, result); // s_{t+1}

      return { nextState, action, result };
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's iterative with multi-step execution, stateful maintaining memory across stepsand action-oriented interacting with tools/environment&lt;/p&gt;

&lt;p&gt;for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    while(!done){
        const action = decide(state);
        const result = act(action);
        state = update(state, result);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loop is the defining feature, without it you just have a wrapper around an API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;I myself, just began learning about AI agents, and this is my very first small one, &lt;code&gt;tinybot&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import { groq } from '@ai-sdk/groq';
    import { generateText } from 'ai';

    const model = groq('llama-3.3-70b-versatile', {
      apiKey: 'groq api key goes here',
    });

    const { text } = await generateText({
      model: model,
      system: 'Answer everything in exactly 3 words.',
      prompt: 'What is the meaning of life?',
    });

    console.log(text);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;tinybot&lt;/code&gt; response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    taha@192 tinybot % node tinybot.js                                                               
    Find True Happiness
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why Most AI Agent Tutorials Fall Short
&lt;/h3&gt;

&lt;p&gt;For me, I think most tutorials treat AI agents as black boxes, thus creating an over abstraction because of the reliance on frameworks that hide core mechanics.&lt;br&gt;
Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const agent = new Agent({...});
    await agent.run();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And as a result many or some cannot debug failures, extend functionality and reason about performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  A More Precise View
&lt;/h3&gt;

&lt;p&gt;At its core, an AI agent can be modeled as a discrete-time control system.&lt;/p&gt;

&lt;p&gt;At each time step t, the agent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Observes a state st&lt;/li&gt;
&lt;li&gt;Chooses an action a​&lt;/li&gt;
&lt;li&gt;Receives a result rt&lt;/li&gt;
&lt;li&gt;Transitions to a new state st+1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can express this formally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    st+1=f(st,at,rt)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;st = current state (input + memory)&lt;/li&gt;
&lt;li&gt;at = action chosen by the agent&lt;/li&gt;
&lt;li&gt;rt = result of executing the action&lt;/li&gt;
&lt;li&gt;f = state transition function&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  State Representation (st)
&lt;/h3&gt;

&lt;p&gt;State is the most underexplained part of agent systems.&lt;br&gt;
Formally, it is everything the agent conditions on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    st=(x,mt,ht)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;x = current input&lt;/li&gt;
&lt;li&gt;mt= memory (retrieved knowledge)&lt;/li&gt;
&lt;li&gt;ht= interaction history&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const state = {
      input: "Find a good fishing rod under $1000",
      memory: [...retrievedDocs],
      history: [...previousSteps]
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key insight:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The LLM never “sees” your system, only the serialized state you provide; meaning &lt;code&gt;Bad state design = bad decisions.&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Deterministic System, Probabilistic Core
&lt;/h3&gt;

&lt;p&gt;An important distinction is that an agent system (loop, tools, memory) is deterministic and the policy (LLM) is probabilistic.&lt;br&gt;
We can think of the full system as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Deterministic Runtime + Probabilistic Policy = AI Agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or more formally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Agent=Runtime(π,T,M)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;π = policy (LLM)&lt;/li&gt;
&lt;li&gt;T = set of tools&lt;/li&gt;
&lt;li&gt;M = memory system&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why This Matters
&lt;/h3&gt;

&lt;p&gt;This framing is not academic, it just impacts how you build systems, for example if you don’t control st, the agent behaves unpredictably, if you don’t constrain at, the agent may hallucinate actions, and if f is poorly designed, the system becomes unstable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stateless vs Stateful Systems
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Stateless
&lt;/h4&gt;

&lt;p&gt;Stateless, means each decision is independent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;at∼π(a∣x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;No memory&lt;/li&gt;
&lt;li&gt;No accumulation of knowledge&lt;/li&gt;
&lt;li&gt;Limited reasoning depth&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Stateful
&lt;/h4&gt;

&lt;p&gt;Decisions depend on history:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;at∼π(a∣st)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enables multi-step reasoning&lt;/li&gt;
&lt;li&gt;Allows correction and refinement&lt;/li&gt;
&lt;li&gt;Introduces complexity (memory growth, noise)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Code Comparison
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Stateless:
&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Summarize this article&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Stateful:
&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;buildPrompt&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;history&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;retrievedMemory&lt;/span&gt;
    &lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  From Theory to Execution: Full Step Trace
&lt;/h3&gt;

&lt;p&gt;Let’s walk one iteration concretely:&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Initial state
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Find a good fishing rod under $1000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;history&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
        &lt;span class="na"&gt;memory&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;h4&gt;
  
  
  Step 2: Policy decision
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&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="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"search_products"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"args"&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="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"fishing rod under 1500"&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;h4&gt;
  
  
  Step 3: Tool execution
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;result&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="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;Rod 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;800&lt;/span&gt; &lt;span class="p"&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;Rod 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;650&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;h4&gt;
  
  
  Step 4: Policy decision
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&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="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"search_products"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"args"&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="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"fishing rod under 1000"&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;h4&gt;
  
  
  Step 5: State transition
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;state&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="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;history&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;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;search_products&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nx"&gt;result&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;h3&gt;
  
  
  Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;An agent is defined by its loop, not its model&lt;/li&gt;
&lt;li&gt;State design directly determines decision quality&lt;/li&gt;
&lt;li&gt;The LLM is just a policy function, not the system itself&lt;/li&gt;
&lt;li&gt;Determinism is a configuration choice, not a default&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;After defining what an agent, we need to see the structure of this system. The questions we need to answer is&lt;br&gt;
how do we decompose an agent into components that are modular, testable, and maybe scalable?&lt;br&gt;
The answer is that an agent can be represented as a composition of interacting modules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Agent=(π,M,T,E)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;π = policy (LLM decision function)&lt;/li&gt;
&lt;li&gt;M = memory system&lt;/li&gt;
&lt;li&gt;T = toolset&lt;/li&gt;
&lt;li&gt;E = execution runtime (loop + orchestration)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conceptual Architecture
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    User Input
        ↓
    State Builder (input + memory + history)
        ↓
    Policy (LLM)
        ↓
    Action (JSON)
        ↓
    Tool Executor
        ↓
    Result
        ↓
    Memory Update
        ↓
    Loop (repeat or terminate)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How I see it is this conceptual architecture you see above is that its more of a feedback system than a pipeline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Flow
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;State → Policy
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Serialize state into a prompt&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Policy → Action
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;LLM outputs structured decision&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Action → Tool
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;System executes external function&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tool → Result
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Returns data to agent&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Result → State Update
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Incorporated into next iteration&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Concrete representation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    async function agentStep(state, memory){
      const prompt = buildPrompt(state, memory);

      const action = await llm(prompt);       // π(st)
      const parsed = parseAction(action);     // structured at

      const result = await execute(parsed);   // T(at)

      const nextState = updateState(state, parsed, result); // f(...)

      return { nextState, parsed, result };
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;
&lt;h3&gt;
  
  
  Serialization Boundary
&lt;/h3&gt;

&lt;p&gt;A serialization boundary is the checkpoint, as for an agent to "packs its bags" to travel across a network or wait in storage it needs to take a formal format, like a JSON, YAML and TOON formats.&lt;/p&gt;

&lt;p&gt;AT the end, the keypoint to remember is that the LLM cannot operate on objects, it operates on text.&lt;/p&gt;

&lt;p&gt;So we define a serialization function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function buildPrompt(state) {
      return `
        You are an agent.

        User goal:
        ${state.input}

        History:
        ${JSON.stringify(state.history)}

        Available tools:
        ${JSON.stringify(toolSchemas)}
      `;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;br&gt;
Final Verdict: The serialization function is the encoding half of the process and the decoding half happens inside the LLM's "brain" when it parses your prompt to understand the context.&lt;/p&gt;
&lt;h2&gt;
  
  
  Memory Systems
&lt;/h2&gt;

&lt;p&gt;Without memory, the agent reduces to just a stateless function, as it turns an agent from a reactive loop into a system capable of contextual reasoning and personalization.&lt;/p&gt;
&lt;h3&gt;
  
  
  Short Term Memory
&lt;/h3&gt;

&lt;p&gt;Short term memory is what you pass directly into the model.&lt;/p&gt;
&lt;h4&gt;
  
  
  Implementation
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const history = [
      {
        action: { name: "search_products", args: { query: "fishing rod" } },
        result: [{ name: "Rod 1", price: 850 }]
      }
    ];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;
&lt;h4&gt;
  
  
  Injecting into prompt
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    function buildPrompt(state) {
      return `
        User goal:
        ${state.input}

        History:
        ${JSON.stringify(state.history, null, 2)}
      `;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;
&lt;h3&gt;
  
  
  Long Term Memory
&lt;/h3&gt;

&lt;p&gt;Short term memory is insufficient for the agent to remember large documents, user preferences and cross session knowledge; well here persistent memory is introduced.&lt;/p&gt;
&lt;h4&gt;
  
  
  Storage Options
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Database (PostgreSQL, MongoDB)&lt;/li&gt;
&lt;li&gt;Vector database (for semantic search)&lt;/li&gt;
&lt;li&gt;File based storage (simple file systems)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    await db.insert({
      userId: "123",
      text: "User prefers Scorpion fishing rods",
      createdAt: Date.now()
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;
&lt;h2&gt;
  
  
  Tooling and Action Execution
&lt;/h2&gt;

&lt;p&gt;Memory allows an agent to think with context but tools allow an agent to act on the world.&lt;br&gt;
With tools, it becomes an interactive system capable of retrieving data, triggering workflows, and producing side effects; and without these tools, an agent is limited to text generation.&lt;/p&gt;
&lt;h3&gt;
  
  
  What Makes a “Tool”
&lt;/h3&gt;

&lt;p&gt;A tool is any callable function that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Accepts structured input&lt;/li&gt;
&lt;li&gt;Performs an operation (internal or external)&lt;/li&gt;
&lt;li&gt;Returns a result to the agent&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Examples of Tools
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;API calls (weather, search, payments)&lt;/li&gt;
&lt;li&gt;File system operations&lt;/li&gt;
&lt;li&gt;Computation utilities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const tools = {
      getWeather: async ({ city }) =&amp;gt; {
        const res = await fetch(`https://api.weather.com/${city}`);
        return res.json();
      }
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;p&gt;Bare in mind that in tools scope, timeouts matter a lot as without constraints, latency can go endelessly.&lt;br&gt;
One slow tool can block the entire agent loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core Runtime
&lt;/h2&gt;

&lt;p&gt;The center of the entire system is the agent loop. Everything we’ve built so far, from policy, memory to tools, only becomes meaningful when orchestrated through a controlled execution loop&lt;/p&gt;

&lt;h3&gt;
  
  
  Minimal loop
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    async function runAgent(input) {
      let state = {
        input,
        history: [],
        memory: []
      };

      for (let step = 0; step &amp;lt; 10; step++) {
        const action = await policy(state);
        const result = await execute(action);

        state = updateState(state, action, result);

        if (isDone(state, action)) break;
      }

      return state.output;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;h3&gt;
  
  
  Termination Conditions
&lt;/h3&gt;

&lt;p&gt;Without termination logic, the loop is unbounded.&lt;/p&gt;

&lt;h4&gt;
  
  
  Practical Conditions
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Explicit Final Action
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (action.type === "final"){
  return action.output;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Max Step Limit
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (step &amp;gt;= MAX_STEPS){
  throw new Error("Max steps exceeded");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Heuristic Completion
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isDone(state){
  return state.history.length &amp;gt; 0 &amp;amp;&amp;amp;
         state.history[state.history.length - 1].action.type === "final";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why This Matters
&lt;/h3&gt;

&lt;p&gt;Without termination, we will have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Infinite loops&lt;/li&gt;
&lt;li&gt;Unbounded cost&lt;/li&gt;
&lt;li&gt;API rate issues&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;This article walked through what an AI agent actually looks like under the hood, from the control loop to memory and tools with small minimal JavaScript implementation. Keep in mind that this is not a deep or complete system just a minimal, educational implementation, basically just what I learned while exploring AI agents and there’s still a lot missing.&lt;br&gt;
If you’re trying to learn this too, my advice is don’t start with frameworks, just try to build a small agent yourself; even a basic version will force you to understand a lot and that’s where the real learning happens.&lt;/p&gt;

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