The agent loop is the core execution pattern: the agent receives the current state, reasons about what to do, takes an action, observes the result, and repeats — until the goal is complete or a stopping condition is reached.
Thought: reasoning about the current situation
Action: a specific tool call with parameters
Observation: the result (provided by the framework)
Thought: updated reasoning incorporating the observation
Action: next tool call
... repeat ...
Final Answer: response to the user
This structured alternation makes the agent's decision-making inspectable and debuggable — you can read the full thought-action-observation trace to understand exactly what the agent did and why.
Each loop iteration adds content to the LLM's context: actions, observations, and thoughts. Over many iterations, context grows and can approach the model's limit.
Summarization — Compress older parts of the history into a summary when they exceed a threshold.
Sliding window — Keep only the most recent N turns of history; discard the oldest.
External memory — Persist detailed history to a vector database and retrieve only the relevant parts per step.
Max iterations (e.g., stop after 50 steps). Timeout (stop after 5 minutes). Explicit termination output. Error thresholds (stop after 3 consecutive failures of the same action).
Before high-stakes actions (send email, delete file, make purchase), pause and request human approval. Essential for production agents where mistakes have real consequences.
Ask the AI assistant about the agent loop, the ReAct pattern, context accumulation, or how to design stopping conditions.