# Agent Loop

> **TL;DR.** An agent loop is the control-flow pattern at the center of every autonomous LLM agent: the model observes its context, reasons about what to do, calls a tool, reads the result, and loops — until it produces plain text with no more tool calls, or a budget rule cuts the cycle.

- **Category:** AI / Developer Tools / Agent Infrastructure
- **Stage:** established
- **Age:** 384 days
- **Origin date:** 2025-05-15
- **First detected:** 2026-04-16
- **Canonical URL:** https://earlyterms.com/term/agent-loop
- **Sources:** 11 primary URLs

## Definition

An agent loop is the control-flow pattern at the center of every autonomous LLM agent: the model observes its context, reasons about what to do, calls a tool, reads the result, and loops — until it produces plain text with no more tool calls, or a budget rule cuts the cycle. In the canonical form, the whole mechanism is about nine lines of Python.

What's new in 2026 is canonicalization. [OpenAI's Jan 23, 2026 "Unrolling the Codex agent loop"](https://openai.com/index/unrolling-the-codex-agent-loop/) (456 HN points) used the phrase as a product-page title. Letta's ["Rearchitecting Letta's Agent Loop"](https://www.letta.com/blog/letta-v1-agent) placed it alongside ReAct, MemGPT, and Claude Code. Every major platform voice — OpenAI, Anthropic, LangChain, Letta, IBM — converged on the same two-word label.

## Example

[Sketch.dev's "The unreasonable effectiveness of an LLM agent loop with tool use"](https://sketch.dev/blog/agent-loop) (447 HN points, May 2025) published the reference nine-line implementation: `while True: output, tool_calls = llm(msg); if tool_calls: msg = [handle(tc) for tc in tool_calls] else: msg = user_input()`. Claude Code's master loop (codenamed nO) is the same pattern hardened with an async dual-buffer queue.

## Analogy

It's the REPL of the AI era — read-eval-print, except "eval" is a frontier model and "print" can touch your filesystem and production database.

## Why it's emerging now

Three years after ReAct named the pattern, "agent loop" hit canonical status in 2026 when OpenAI, Letta, and PromptLayer all used the exact phrase in flagship posts within 12 months. A 2026 wave of cost-horror stories (one team going from $127/wk to $47k/wk) keeps the term sticky.

## Related terms

- *parent:* Agent Harness
- *parent:* Managed Agents
- *parent:* ReAct
- *related:* Coding Agents
- *related:* Claude Agent SDK
- *child:* Ralph Loop
- *alias:* agentic loop
- *alias:* LLM loop
- *alias:* agent execution loop
- *related:* event loop
- *related:* MemGPT
- *related:* LangGraph

## Sources

1. [sketch.dev — The unreasonable effectiveness of an LLM agent loop with tool use (reference 9-line implementation)](https://sketch.dev/blog/agent-loop)
2. [OpenAI — Unrolling the Codex agent loop](https://openai.com/index/unrolling-the-codex-agent-loop/)
3. [Letta — Rearchitecting Letta's Agent Loop: Lessons from ReAct, MemGPT & Claude Code](https://www.letta.com/blog/letta-v1-agent)
4. [PromptLayer — Claude Code: Behind-the-scenes of the master agent loop (nO)](https://blog.promptlayer.com/claude-code-behind-the-scenes-of-the-master-agent-loop/)
5. [Steve Kinney — The Anatomy of an Agent Loop](https://stevekinney.com/writing/agent-loops)
6. [Victor Dibia — The Agent Execution Loop: How to Build an AI Agent From Scratch](https://newsletter.victordibia.com/p/the-agent-execution-loop-how-to-build)
7. [TianPan.co — Agentic Engineering Patterns: The While Loop Is the Easy Part](https://tianpan.co/blog/2026-02-05-agentic-engineering-patterns-while-loop-easy-part)
8. [Alibaba Cloud — From ReAct to Ralph Loop: A Continuous Iteration Paradigm for AI Agents](https://www.alibabacloud.com/blog/from-react-to-ralph-loop-a-continuous-iteration-paradigm-for-ai-agents_602799)
9. [Hacker News — Unrolling the Codex agent loop (456 points)](https://news.ycombinator.com/item?id=46737630)
10. [Hacker News — The unreasonable effectiveness of an LLM agent loop with tool use (447 points)](https://news.ycombinator.com/item?id=43998472)
11. [snarktank/ralph — autonomous AI agent loop (17.1k stars)](https://github.com/snarktank/ralph)

---
_Generated by EarlyTerms · https://earlyterms.com/term/agent-loop_
