agent loop
In plain wordsThe repeating cycle at the heart of an AI agent: the model decides what to do next, software carries it out, the result is shown to the model, and the cycle repeats until the task is finished.
The control loop that runs an AI agentAI agent, n.: An AI system that does not just answer but acts: given a goal, it decides on steps, uses tools such as a browser or code editor, checks the results and keeps going until the job is done.. On each turn the harnessharness, n.: The software around an AI model that gives it instructions and tools, carries out its actions and decides when it stops. The model is the engine; the harness is the rest of the car. sends the accumulated contextcontext window, n.: How much an AI model can read and keep in view at once: the instructions, the conversation so far and any attached documents. Text that does not fit has to be cut, summarized or left out. — instructions, conversation, tool definitions and earlier results — to the model; the model replies either with one or more tool callstool call, n.: A single request from an AI model to use one of its tools — naming the tool and filling in the details — which the surrounding software then carries out and reports back on. or with a final answer; the harness executes the calls, appends their results as observations and calls the model again. The loop ends at a stop conditionstop condition, n.: The rule that tells an AI agent when to stop working — because the task is done, a time or cost limit has been reached, or something has gone wrong.: the model answers without requesting a tool, a turn or token budget runs out, a human interrupts, or a check such as a test suite passes. Because every step re-reads a growing context, long loops rely on compactioncompaction, n.: Like replacing a stack of rough notes with a one-page digest: when an AI's conversation grows too long for its memory, the history is condensed into a summary and the work continues from there. or subagentssubagent, n.: A helper AI agent that a main agent starts to handle one piece of a job; it works in its own separate workspace and reports back a short summary when it is done. to stay within the window. The design descends from the observation–action cycle of reinforcement learningreinforcement learning, n.: A way of teaching a computer program by trial and error: it tries actions, earns points for good results and penalties for bad ones, and gradually learns which choices pay off over time. and from the reason–act–observe pattern of ReActReAct, prop. n.: A method in which an AI alternates between thinking out loud about what to do next and taking an action, such as a web search, then uses what it observed to plan its next step..
Most of the agent loop's time goes to waiting on the test runner, not on the model.
Origin
The perception–action cycle is as old as agent-based AI. For language models the loop was set out by ReActReAct, prop. n.: A method in which an AI alternates between thinking out loud about what to do next and taking an action, such as a web search, then uses what it observed to plan its next step. (Shunyu Yao et al., 2022) and popularized by LangChain agents and AutoGPTAutoGPT, prop. n.: A 2023 open-source program that gave GPT-4 a goal and let it run on its own — planning, searching the web and writing files in a loop — becoming the first viral 'autonomous AI agent'. in 2023; native function callingfunction calling, n.: A feature of AI model services that lets the model reply with a neatly formatted request to run one of a program's functions, rather than with ordinary text; the program, not the model, then runs it. APIs, introduced by OpenAI in June 2023, made it the standard architecture of agent products.
Usage note
Some writers reserve 'agent loop' for the bare execution cycle and treat prompts, tool design and memory as scaffoldingscaffolding, n.: The code, prompts and tools built around an AI model so it can carry out tasks it could not manage from a bare prompt — like the scaffolding that lets builders reach every part of a building.; others use it for the whole runtime. Not to be confused with a training looptraining loop, n.: The repeating cycle at the heart of training software: grab some examples, let the model guess, measure the error, adjust the model, and do it again — often millions of times.: the agent loop runs at inference time and updates no weights.
Related
- harnessharness, n.: The software around an AI model that gives it instructions and tools, carries out its actions and decides when it stops. The model is the engine; the harness is the rest of the car.
- tool calltool call, n.: A single request from an AI model to use one of its tools — naming the tool and filling in the details — which the surrounding software then carries out and reports back on.
- stop conditionstop condition, n.: The rule that tells an AI agent when to stop working — because the task is done, a time or cost limit has been reached, or something has gone wrong.
- ReActReAct, prop. n.: A method in which an AI alternates between thinking out loud about what to do next and taking an action, such as a web search, then uses what it observed to plan its next step.
- scaffoldingscaffolding, n.: The code, prompts and tools built around an AI model so it can carry out tasks it could not manage from a bare prompt — like the scaffolding that lets builders reach every part of a building.
- compactioncompaction, n.: Like replacing a stack of rough notes with a one-page digest: when an AI's conversation grows too long for its memory, the history is condensed into a summary and the work continues from there.
- context engineeringcontext engineering, n.: Managing an AI model's reading material: choosing, trimming and arranging the instructions, documents, tool results and memories it is given on every turn, so that it has what the task needs and little else.
- training looptraining loop, n.: The repeating cycle at the heart of training software: grab some examples, let the model guess, measure the error, adjust the model, and do it again — often millions of times.
Sources
- Yao, S., Zhao, J., Yu, D., Du, N., Shafran, I., Narasimhan, K. & Cao, Y. (2022). ReAct: Synergizing Reasoning and Acting in Language Models. arXiv:2210.03629 (ICLR 2023). arxiv.org/abs/2210.03629
- Willison, S. (2025). I think 'agent' may finally have a widely enough agreed upon definition to be useful jargon now. Simon Willison's Weblog. simonwillison.net/2025/Sep/18/agents
Mentioned in
agentic AIagentic AI, n.: AI built to pursue goals on its own — planning, taking actions and adjusting along the way — instead of only responding to one prompt at a time. 'Agentic' describes how much of this independence a system has., AI agentAI agent, n.: An AI system that does not just answer but acts: given a goal, it decides on steps, uses tools such as a browser or code editor, checks the results and keeps going until the job is done., agentagent, n.: Something that acts. In AI, a program that observes its situation and takes actions toward a goal: a game-playing learner, a software helper, or a chatbot that uses tools to complete tasks., agent frameworkagent framework, n.: A software library that gives developers ready-made parts for building AI agents — model connections, tool handling, memory, multi-agent coordination and logging — so they need not write everything from scratch., agentic RAGagentic RAG, n.: Retrieval in which the AI runs its own research: it decides what to search for, looks at the results, searches again if needed, and only then answers., AutoGPTAutoGPT, prop. n.: A 2023 open-source program that gave GPT-4 a goal and let it run on its own — planning, searching the web and writing files in a loop — becoming the first viral 'autonomous AI agent'., Claude CodeClaude Code, prop. n.: A coding assistant from Anthropic that works as an agent: given a programming task, it explores the project, changes the code and runs programs to check its work, from the web, a desktop app, an editor or a terminal., harnessharness, n.: The software around an AI model that gives it instructions and tools, carries out its actions and decides when it stops. The model is the engine; the harness is the rest of the car., LangChainLangChain, prop. n.: A popular free software toolkit, and the company behind it, for building applications that connect AI language models to documents, databases, tools and multi-step workflows., long-horizon tasklong-horizon task, n.: A job that takes many steps and a long time — hours or days of work rather than a single answer — so an AI must stay on track and recover from its own mistakes., orchestrationorchestration, n.: Coordinating several AI calls, tools or agents so each does its part in the right order and their results are combined into one finished piece of work, as a conductor directs an orchestra., ReActReAct, prop. n.: A method in which an AI alternates between thinking out loud about what to do next and taking an action, such as a web search, then uses what it observed to plan its next step., scaffoldingscaffolding, n.: The code, prompts and tools built around an AI model so it can carry out tasks it could not manage from a bare prompt — like the scaffolding that lets builders reach every part of a building., self-correctionself-correction, n.: An AI model noticing and fixing its own mistakes — by rereading its answer, running a test or checking a source — before it gives a final result., stop sequencestop sequence, n.: A piece of text that tells an AI model to stop writing as soon as it produces it — for example, stopping at a blank line or just before the next question., subagentsubagent, n.: A helper AI agent that a main agent starts to handle one piece of a job; it works in its own separate workspace and reports back a short summary when it is done., tool calltool call, n.: A single request from an AI model to use one of its tools — naming the tool and filling in the details — which the surrounding software then carries out and reports back on., training looptraining loop, n.: The repeating cycle at the heart of training software: grab some examples, let the model guess, measure the error, adjust the model, and do it again — often millions of times., BabyAGIBabyAGI, prop. n.: A tiny 2023 program that kept an AI working through an ever-changing to-do list — doing a task, adding new ones, reprioritizing — and helped start the craze for autonomous AI agents., Claude Plays PokémonClaude Plays Pokémon, prop. n.: A 2025 livestream in which Anthropic's Claude AI played the classic Game Boy game Pokémon Red by itself, watched by thousands as it struggled and slowly progressed; it inspired similar runs by other models., interleaved thinkinginterleaved thinking, n.: A way for an AI agent to pause and reason again after every action it takes — reading each search result or test output before deciding what to do next — instead of only thinking once at the start., LLM observabilityLLM observability, n.: Recording and inspecting what an AI application actually did on each request — prompts sent, documents found, tools used, answers given, time and cost — so problems can be found and fixed., Ralph Wiggum loopRalph Wiggum loop, n.: A blunt way of using AI coding assistants: feed the same instructions to the AI again and again in an endless loop until the software gets built., SGLangSGLang, prop. n.: A free, open-source engine for running AI language and image models on servers, built to be fast when many requests begin the same way, as in chat and agent workloads.