The Agent Loop: How AI Agents Get Things Done
Agentic AI systems can carry out multi-step tasks with varying degrees of autonomy. One of the core ideas behind them is the agent loop.
From a response to a loop
A typical single-turn LLM interaction looks like this:
Input → LLM → OutputOne prompt. One response. An agent adds a cycle:
Reason → Act → Observe
↑ │
└──────────────┘An example: adding authentication
Suppose you ask an agent: “Add JWT authentication to this codebase.” A single response might suggest an implementation. An agent with suitable tools can work through the task:
- Explore the repository.
- Find authentication-related modules and identify the framework.
- Write the implementation.
- Run the relevant tests.
- Inspect failures and read the error messages.
- Modify the code and run the tests again.
- Update affected files and assess whether the task is complete.
After every action, it observes the result and decides what to do next. In simplified pseudocode:
while not task_complete:
think()
act()
observe()In practice, the loop also needs stopping conditions, limits, and a way to ask for help. Passing tests alone does not guarantee that an implementation is correct or secure.
Tools give the model capabilities
The model typically interacts with its environment through tools. These can let it read and edit files, run tests, search a codebase, or execute commands.
At each step, the model selects a tool, supplies arguments, and uses the result to decide what to do next. The system controls which tools and permissions are available.
LLM + Tools + Agent Loop
The model chooses the next action. The tools provide the capabilities to carry it out. Together with feedback, they make it possible to move from describing a change to performing it.