Agent loop
The core cycle an agent runs: observe context, choose an action (often a tool call), apply the result, and repeat until the task is done or a stop condition hits.
Learn
When to use it
Use an agent loop when a single model call isn't sufficient to complete a task. Agent loops enable the agent to observe, decide, act, and iterate, allowing for complex workflows like "monitor a system, trigger alerts, and adjust configurations until stability is achieved."
Quick example
In ChatGPT, when automating customer support, the model needs to assess user queries, decide on the best response or action, and continue the conversation until the issue is resolved. The agent loop in ChatGPT executes this cycle, enabling the model to handle ongoing interactions dynamically. This loop is what allows ChatGPT to maintain context and respond appropriately over multiple turns.
query → agent loop → response → repeat until issue resolved → stop
Ecosystem
Agent loops interact with tools and memory systems to maintain context and execute tasks effectively.
┌─ tools ↺─┐
context →│ agent loop │→ stop
└─ memory ──┘
Misconceptions
| Misconception | Rebuttal |
|---|---|
| It's a one-time process | It's a continuous cycle until a stop condition is met |
| Only for simple tasks | Handles complex, multi-step workflows |
Trade-offs
- Adaptability — requires careful management of context and state
- Task completion — can lead to token burn if not efficiently managed