Agent Loop¶
Introduction¶
The core characteristic of an Agent is not tool usage, memory, or planning.
The defining characteristic of an Agent is the ability to operate in a continuous loop.
Unlike a traditional LLM that generates a single response, an Agent repeatedly:
- Observes the environment
- Reasons about the current state
- Decides what to do next
- Executes an action
- Evaluates the result
This process continues until the goal is achieved.
LLM vs Agent¶
LLM¶
A traditional LLM interaction is usually a single step.
User Input
↓
LLM
↓
Response
Example:
User:
What is the capital of France?
LLM:
Paris.
The execution ends immediately after the response is generated.
Agent¶
An Agent continuously interacts with its environment.
Goal
↓
Observe
↓
Reason
↓
Act
↓
Observe
↓
Reason
↓
Act
The process stops only when:
Goal Achieved
or
Task Aborted
The Basic Agent Loop¶
Most Agent systems can be represented as:
Observe
↓
Think
↓
Act
↓
Observe
A more detailed version:
Observation
↓
Reasoning
↓
Planning
↓
Action
↓
Environment
↓
Observation
This cycle forms the foundation of modern Agent systems.
Step 1: Observation¶
The Agent gathers information about the current state.
Sources may include:
- User requests
- Files
- Databases
- APIs
- Web pages
- Tool outputs
Example:
Goal:
Fix a failing unit test
Observation:
Test suite reports:
testCreateUser failed
The Agent now has context for decision making.
Step 2: Reasoning¶
The Agent analyzes available information.
Example:
The test is failing because
the expected value differs
from the actual value.
Reasoning is usually performed by an LLM.
The output is not yet an action.
It is a decision about what should happen next.
Step 3: Planning¶
The Agent determines the next step.
Example:
1. Open source file
2. Locate implementation
3. Compare logic
4. Modify code
5. Run tests
Planning can be:
Reactive¶
One step at a time
or
Structured¶
Generate complete plan first
Different Agent architectures choose different approaches.
Step 4: Action¶
The Agent executes a task.
Examples:
Read file
Search web
Call API
Execute code
Write file
Actions allow the Agent to interact with the outside world.
Without actions, an Agent becomes a chatbot.
Step 5: Feedback¶
Every action produces a result.
Example:
Run tests
Output:
3 tests passed
1 test failed
The Agent receives new information and enters the next iteration.
Observation
The loop continues.
Example: Coding Agent¶
Goal:
Fix failing test
Loop execution:
Observe:
Read test failure
↓
Reason:
Identify likely bug
↓
Act:
Open source file
↓
Observe:
Review implementation
↓
Reason:
Find incorrect logic
↓
Act:
Modify code
↓
Act:
Run tests
↓
Observe:
All tests pass
↓
Goal Achieved
Example: Research Agent¶
Goal:
Create report about AI coding agents
Loop execution:
Search web
↓
Read articles
↓
Extract information
↓
Identify missing data
↓
Search again
↓
Generate report
↓
Goal Achieved
The Agent repeatedly acquires new information before producing a final result.
Why the Loop Matters¶
Without a loop:
Input
↓
Output
The system cannot adapt.
With a loop:
Observe
↓
Act
↓
Observe
↓
Act
The system can respond to changing conditions.
This ability is what makes Agents useful for complex tasks.
Common Agent Loop Variations¶
OODA Loop¶
Originally developed for military decision making.
Observe
↓
Orient
↓
Decide
↓
Act
Many Agent systems resemble this structure.
ReAct¶
One of the most influential Agent patterns.
Thought
↓
Action
↓
Observation
Repeated until completion.
Plan-and-Execute¶
Create Plan
↓
Execute Step
↓
Execute Step
↓
Execute Step
Suitable for long tasks.
Reflection Loop¶
Adds self-review.
Generate
↓
Review
↓
Improve
Used by advanced Agent systems.
Modern Agent Runtime¶
Most production agents implement a loop similar to:
while not goal_completed:
observe()
think()
choose_action()
execute_action()
evaluate_result()
This runtime loop is the heart of every Agent system.
Whether the Agent is:
- a coding assistant
- a research assistant
- a browser agent
- a multi-agent system
the same fundamental pattern exists.
Key Takeaways¶
The Agent Loop is the core mechanism of an Agent.
Agent Loop:
Observe
→ Reason
→ Plan
→ Act
→ Observe
An LLM typically generates one response.
An Agent continuously interacts with its environment.
The ability to repeatedly observe and act
is what transforms an LLM-powered system
into an Agent.