Agents vs Chatbots: The 4-Part Execution Loop (LLM + Tools + Memory + Loop)
Distinguish single-pass chatbots from four-part autonomous agents and prevent context rot before working memory passes 70%.
- 15 min
- Foundations
- T01
- Verify all four required components (LLM, Tools, Memory, Loop) before calling any workflow an agent.
- Bind curated non-overlapping tools and load disk context just-in-time rather than dumping whole repos.
- Prevent context rot above 50%-70% fill with compaction or fresh resets carrying a 3-part handoff.

Read the script
Why do 90% of workflows marketed as "AI agents" break down the first time an engineer changes five real files? Because most of them are single-pass chatbots pretending to be autonomous, forcing a human to copy logs back and forth as the hidden execution loop.
A real autonomous agent requires four concrete building blocks working together: LLM, Tools, Memory, and a bounded Loop. The LLM chooses the next step rather than guessing an entire codebase in one shot. Curated non-overlapping Tools—such as read, search, edit, and test—connect directly to files and shell checks. Memory splits cleanly into working context and persistent disk specs loaded just-in-time via grep. Finally, a bounded Loop drives Think, Act, Observe, and State Update until automated tests exit zero or a strict max_turns cap halts execution.
Here is the trap that breaks long sessions: context saturation. Even when a model supports 200K to 1M tokens, rule adherence drops steeply once working memory passes 50% to 70% fill. Noisy stack traces crowd out early rules, triggering context rot and repeated failed patches.
Keep long tasks healthy by watching the context meter and performing compaction or resetting into a fresh session around 65% fill—always passing a crisp 3-part handoff note listing goal, verified_state on disk, and next_step.
Open the T01 Agent Loop Lab below. Step the toy bug fix through Think, Tool, Observe, and Memory, reset before hitting 70% context fill, and supply all three handoff fields to hit PASS.
Single-Pass Chatbots Versus True Four-Part Agents
A chatbot answers one prompt and stops, whereas an agent executes a closed feedback loop against real files, tools, and verification checks.
Many products labeled "AI agent" today are only single-pass wrappers. You send a question, the model retrieves a text snippet, prints one reply, and forgets working state unless a human copies code out, hits an error, and pastes logs back manually. That pattern (Prompt -> LLM -> Output) leaves the human acting as the execution loop.
An autonomous coding or operations agent flips that architecture using four mandatory blocks (LLM + Tools + Memory + Loop):
- LLM (Policy Engine): Inspects the current state and decides the next concrete action instead of dumping final guesswork.
- Tools (Environment Bridge): Connects to filesystem reads/edits, search, shell commands, test runners, databases, or browser checks.
- Memory (Dual State): Splits cleanly between Working Memory inside the live context window and Persistent Memory stored on disk (
Markdown,JSON,SQLite) and queried just-in-time. - Loop (Runtime Controller): Drives
Think -> Act (Tool) -> Observe -> Update Stateacross multiple turns until deterministic verification passes or a hard stop limit trips.
Run a fast three-question litmus check on any workflow: Does it invoke external tools directly? Does it iterate across multiple steps on its own? Does verified state survive across fresh sessions? If any answer is no, you are driving a chatbot, not an agent.
Most people slap a system prompt onto a chat window and wonder why multi-file refactors collapse the moment real test errors appear.
Curated Minimal Toolsets and Just-In-Time Disk Memory
Giving an agent dozens of overlapping tools or pasting whole codebases upfront degrades tool selection accuracy long before work begins.

Suppose you want an agent to fix a failing discount bug in a 400-file TypeScript repository. Two rookie designs fail immediately. Design A attaches 45 overlapping tools (five file readers, six search wrappers, ten Slack/calendar bridges), forcing the model to waste reasoning tokens choosing which redundant command fits. Design B pastes 120,000 tokens of raw source files straight into the initial prompt so the model "knows everything."
Strong agent architectures go the exact opposite way. Bind a curated, non-overlapping minimal toolset—typically just four crisp primitives (read, search, edit, test) plus git status. Store architecture notes, schemas, and project plans on disk, never bloated inside the initial prompt. When the agent encounters an error in discount.ts, it searches for the symbol via grep, reads the exact 45 relevant lines on demand, applies a targeted patch, and runs the test suite. Loading narrow slices just-in-time keeps working context sharp, reduces token latency across turns, and lets the terminal trace finish cleanly (read -> grep -> patch -> test PASS ✓).
Most people assume stuffing every single project file into the opening prompt makes an agent smarter, when in reality massive upfront noise dilutes focus from line one and hides subtle failure signals inside walls of irrelevant imports.
Context Saturation Physics and the 50-70% Rot Threshold
Although modern models advertise 200K–1M token windows, instruction following and edit precision drop steeply once working context crosses 50%–70% fill.
Think of Working Memory like a cramped workbench rather than an infinite warehouse. Early in a session (10%–35% fill), the model tracks file paths, edge cases, and coding rules cleanly. By turn eighteen—after 15 failed stack traces, long npm logs, and superseded file snapshots pile up—the active buffer crosses 70% saturation. Two measurable failure modes kick in simultaneously: recency bias (the agent over-weights the latest noisy error log while forgetting rules stated at turn one) and context rot (it repeats previously failed fixes, edits stale line numbers, or quietly skips verification checks).
Preventing context rot demands deliberate hygiene rather than squeezing one marathon chat to 98%. First, pipe verbose command logs through quiet modes or summarize failures into disk files instead of dumping 3,000 raw lines into chat. Second, monitor active fill continuously: trigger compaction or cleanly retire the session before crossing the 60%–70% threshold. When handing off to a fresh session, pass a compact 3-part handoff note:
- Goal: The single objective still remaining in scope.
- Verified State: Which files actually changed and which deterministic tests already passed on disk.
- Next Step: The exact first action the fresh session should run without re-reading the entire workspace.
Most people keep arguing with an overloaded session at 85% fill for another hour, burning tokens while the agent reintroduces bugs it already solved twenty turns ago and loses track of early constraints.
Bounded Loops, Max Turns, and Deterministic Exit Gates
An autonomous loop without hard turn caps and objective verification either spirals infinitely or declares victory on broken code.
An execution loop needs explicit walls on both sides: a strict ceiling preventing runaway cost, and a real proof gate blocking premature "done" claims. Always declare an explicit max_turns budget (for example, 12 or 20 turns for a scoped task) plus a wall-clock timeout per shell command so a hung server never freezes the loop.
Equally important is the exit condition. Never let the LLM grade its own work solely by saying "Everything looks complete now." Bind the loop exit to deterministic external checks: unit tests pass (npm test exit code 0), TypeScript compiles cleanly (tsc --noEmit), or a linter confirms zero syntax violations. If the model edits pricing.ts, runs tests, sees one failing assertion on line 42, updates the tax rounding rule, and runs tests again until exit 0, the loop exits with verified evidence. If max_turns hits first, the loop halts cleanly, writes a 3-part handoff state to disk, and surfaces the blocker instead of guessing blindly or hiding broken code behind optimistic summaries.
Most people give agents open-ended "keep fixing until it works" instructions with zero turn ceiling or automated test command, paying for twenty wasted loops around one missing import before stepping in manually.
Five-Step Agent Audit and T01 Practice Simulator
Before running any automated coding or operations workflow, confirm all four blocks exist, strip redundant tools, enforce < 70% context resets, and lock exit verification.
Apply this five-step checklist whenever building or auditing an agent workflow:
- Verify all four blocks (
LLM,Tools,Memorysplit between working and disk, andLoopcaps) exist before calling any tool an autonomous agent. - Trim your tool list down to non-overlapping primitives (
read,search,edit,test) so selection stays fast and deterministic. - Keep durable specs, schemas, and rules on disk and pull slices via search on demand instead of pasting full repositories upfront.
- Watch the working context meter closely and execute compaction or a fresh session reset with a 3-part handoff (
goal,verified_state,next_step) before passing70%saturation. - Enforce strict
max_turnslimits and require objective test or build verification before accepting completion.
Most people blame model intelligence when a long workflow breaks, ignoring that oversized toolkits, raw terminal spam, and 80%+ context rot caused the failure.
Open the T01 Agent Loop Lab trainer below (free:ai01-l01-s1), step a toy bug-fix workflow through Think -> Tool -> Observe -> Memory, choose Compact or Fresh Session + Handoff before the context meter breaches 70%, and fill all three handoff fields (goal, verified_state, next_step) to earn PASS.
Educational engineering guide · verify shell commands before running on production hosts.
Practice lab · T01
Step the toy bug-fix task through Think -> Tool -> Observe -> Memory, keep working context below 70%, and supply a valid 3-part handoff note.
Task verified complete with context < 70% AND handoff includes non-empty goal, verified_state, and next_step.
Knowledge check
What to do today
Glossary
- 4-Part Execution Loop
- An agent runtime pairing LLM policy, external Tools, dual Working/Persistent Memory, and a bounded Think-Act-Observe Loop.
- Context Rot
- Drop in instruction following and edit accuracy when working memory becomes crowded above 50%-70% saturation.
- Just-In-Time Retrieval
- Storing specifications on disk and reading small targeted slices via search instead of loading whole repositories upfront.
- 3-Part Handoff Note
- Compact reset packet listing remaining goal, verified disk state/test results, and the exact next action.