# Agentic loops The agentic loop is the fundamental execution pattern of [[AI Agents]]: observe, think, act, evaluate, repeat. The agent perceives its environment (reads files, receives user input, checks tool output), reasons about what to do next, takes an action (executes a tool, writes code, makes an API call), evaluates the result, and decides whether to continue or stop. ``` while task_not_complete: observe() → think() → select_tool() → act() → evaluate() ``` What distinguishes an agentic loop from a simple LLM call is persistence and autonomy. A single call generates text. A loop generates text, acts on it, observes the consequences, and adapts. This is what makes [[How coding agents work|coding agents work]]: they write code, run it, read the error, fix the code, and re-run it, without human intervention between steps. Loop variants: - **ReAct** (Reasoning + Acting): interleave reasoning traces with tool calls - **Plan-and-Execute**: generate a full plan first, then execute steps - **Reflexion**: after execution, reflect on what went wrong and retry with lessons learned The loop is bounded by the [[Context Window]] and [[Token Budget]]. Each iteration adds to the conversation history, consuming tokens. Long-running loops risk [[Context Bloat]] and degraded output quality. [[AI Subagents]] help by offloading multi-step work to fresh context windows. The loop is also what creates risk: each autonomous action can compound errors. [[AI Guardrails]] and human-in-the-loop checkpoints exist to constrain what the loop can do unsupervised. ## References - ## Related - [[AI Agents]] - [[How coding agents work]] - [[AI Agent Harness]] - [[Agentic Engineering]] - [[AI Subagents]] - [[Context Window]] - [[Token Budget]] - [[AI Guardrails]] - [[Feedback Loop]]