> Markdown version of [/videos/1988-your-ai-agent-is-just-a-while-loop-with-an-api-call-let-me-prove-it?t=277](https://www.wearedevelopers.com/videos/1988-your-ai-agent-is-just-a-while-loop-with-an-api-call-let-me-prove-it?t=277). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Your AI Agent is just a while loop with an API call. Let me prove it Your complex AI agent is just a stateless language model trapped inside a while loop. Strip away the abstractions to master agent architecture, token economics, and sandbox security. - **Speakers:** [Michał Michalczuk](https://www.wearedevelopers.com/@michal-michalczuk) - **Event:** World Congress 2026 Europe - Virtual Stage - **Published:** July 2, 2026 - **Duration:** 32:34 - **URL:** https://www.wearedevelopers.com/videos/1988-your-ai-agent-is-just-a-while-loop-with-an-api-call-let-me-prove-it ## Summary Demystifying AI agents reveals that they are fundamentally just a language model wrapped in a "harness"—a simple execution loop containing API calls and local tools. While modern frameworks like the Vercel AI SDK allow developers to instantiate an agent in just two lines of code, stripping away these abstractions exposes the underlying mechanics. By building a Node.js agent from scratch using Mistral, it becomes clear that the LLM itself is completely stateless. It does not run code; it merely parses prompts and returns JSON-based tool calls that the local machine executes, whether those are bash commands, file modifications, or external API requests. Because LLMs operate statelessly, developing production-ready agents introduces immense security and architectural challenges. Granting an LLM raw shell access is highly dangerous, making isolated execution environments like Docker sandboxes an absolute necessity for safe local execution. Furthermore, sophisticated multi-agent systems are achieved simply by wrapping secondary sub-agents—such as a specialized coding assistant—as discrete tools that the primary loop can trigger. This demonstrates that even complex architectures, like the leaked structure of Claude Code, rely on the same fundamental loop of user input, LLM delegation, and local tool dispatch. The most hidden complexity of building AI agents lies in token economics and context orchestration. Because the LLM cannot remember previous interactions, every single API call must repeatedly transmit the entire conversation history, the system prompt, detailed tool definitions, and previous tool outputs. This creates a "ball of mud effect" where input token costs skyrocket as the context window fills with large datasets like email threads or calendar events. Ultimately, while creating a basic agent is computationally simple, engineering a smart and cost-effective system requires strict guardrails, precise prompts, and rigorous context management, proving that "with great amount of data comes great amount of tokens." **Keywords:** AI agent architecture, LLM statelessness, cumulative token costs, vercel AI SDK, node.js AI development, docker sandboxing, LLM tool execution, multi-agent orchestration, mistral API integration, context window management, agent harness patterns, API loop design, prompt payload optimization, claude code architecture ## Chapters 1. **Exploring modern AI SDKs and production deployment challenges** (00:00) — Modern AI SDKs simplify initial creation but often introduce unexpected costs and compliance hurdles during production. 1. **Building a basic conversational AI agent in Node.js** (02:41) — A rudimentary script passes persistent conversation history arrays to an API to simulate chat memory. 1. **Integrating tool definitions for local bash shell execution** (04:37) — Providing a shell capability lets the agent directly execute terminal process commands on the host machine. 1. **Securing tool execution using isolated Docker sandboxes** (06:50) — Running unpredictable shell commands securely requires isolated sandbox environments to protect base operating systems. 1. **Implementing persistent memory through self-modifying agent capabilities** (09:40) — Enabling self-modification allows an agent to persist important conversational logic and references in local storage files. 1. **Building a multi-agent system with coding sub-agents** (13:36) — Separating complex tasks into specialized sub-agents minimizes context payloads and safely orchestrates delegated coding workflows. 1. **Defining the core architecture of an AI agent** (16:12) — The underlying pattern of commercial AI products relies on a continuous loop connecting foundation models with robust tool harnesses. 1. **Analyzing token costs and cumulative history payloads** (19:03) — Stateless requests force consecutive accumulation of context history and static schema structures, massively inflating input token consumption. 1. **Measuring real-world token consumption in data-intensive workflows** (25:40) — Retrieving background context from broad domains like calendars rapidly exhausts token limits while expanding request dimensions. 1. **Key architectural takeaways for building reliable AI agents** (30:04) — Designing helpful agent experiences hinges on deeply understanding stateless API behaviors and strictly defining task boundaries. ## Related Moments - [Exploring the core architecture and components of AI agents](https://www.wearedevelopers.com/videos/1510-on-a-secret-mission-developing-ai-agents) (from "On a Secret Mission: Developing AI Agents") - [Understanding the core AI agent execution loop](https://www.wearedevelopers.com/videos/1631-from-a2a-to-mcp-how-ai-s-brains-are-connecting-to-arms-and-legs) (from "From A2A to MCP: How AI’s “Brains” are Connecting to “Arms and Legs”") - [Constructing scalable AI solutions using LangChain and LangGraph](https://www.wearedevelopers.com/videos/1512-building-ai-applications-with-langchain-and-node-js) (from "Building AI Applications with LangChain and Node.js") - [Core architecture and reasoning loops of AI agents](https://www.wearedevelopers.com/videos/100334-teaching-agents-to-pay-what-devs-need-to-know) (from "Teaching agents to pay: what devs need to know") - [Inspiration and challenges of scaling AI agent communication](https://www.wearedevelopers.com/videos/1465-event-driven-architecture-breaking-conversational-barriers-with-distributed-ai-agents) (from "Event-Driven Architecture: Breaking Conversational Barriers with Distributed AI Agents") - [Leveraging the comprehensive generative artificial intelligence stack](https://www.wearedevelopers.com/videos/969-make-it-simple-using-generative-ai-to-accelerate-learning) (from "Make it simple, using generative AI to accelerate learning") ## Related Articles - [Never delegate the understanding](https://www.wearedevelopers.com/magazine/749-never-delegate-the-understanding) - [A 5-Step Open-Source Setup for Agentic Engineering](https://www.wearedevelopers.com/magazine/738-a-5-step-open-source-setup-for-agentic-engineering) - [The Overflow: AI and Agentic Coding](https://www.wearedevelopers.com/magazine/721-the-overflow-ai-and-agentic-coding) - [The Web We Broke (And Why AI Agents Are Paying the Price) - AgentCon Berlin](https://www.wearedevelopers.com/magazine/735-the-web-we-broke-and-why-ai-agents-are-paying-the-price-agentcon-berlin) ## Related Jobs - [Senior AI/ML Engineer](https://www.wearedevelopers.com/jobs/48352-senior-ai-ml-engineer) at **PagerDuty** - [Senior AI Developer](https://www.wearedevelopers.com/jobs/ext/2836034-senior-ai-developer) at **PwC** - [ML Engineer](https://www.wearedevelopers.com/jobs/48448-ml-engineer) at **Docker, Inc.** - [Head of Agentic AI / Lead AI Engineer](https://www.wearedevelopers.com/jobs/48488-head-of-agentic-ai-lead-ai-engineer) at **1st solution consulting gmbh** - [AI Software Engineer (Germany)](https://www.wearedevelopers.com/jobs/48317-ai-software-engineer-germany) at **Sunhat** - [MLOps AI Engineer](https://www.wearedevelopers.com/jobs/ext/2565312-mlops-ai-engineer) at **TeamViewer Germany GmbH,**