What are AI agents?
The agent loop
Understand observe → decide → act → observe again.
Lesson overview
The agent loop
The loop is the smallest useful mental model for an agent. A request enters the runtime with a goal and state. The model decides whether it can answer or needs another action. If it requests a tool, the application validates and executes it, then feeds the result back into the next step.
Stopping conditions
Every loop needs explicit stopping conditions: task completed, maximum steps reached, budget exceeded, policy denied, tool failure, or human escalation.
Why loops fail
Unbounded loops often come from ambiguous success criteria, tools returning low-quality results, or the model repeatedly choosing the same action. Add step budgets and detect repeated tool calls.
Learning path
Theory → Example → Code → Practice → Quiz → Challenge → Completion
Step 1
Theory
The agent loop
The loop is the smallest useful mental model for an agent. A request enters the runtime with a goal and state. The model decides whether it can answer or needs another action. If it requests a tool, the application validates and executes it, then feeds the result back into the next step.
Stopping conditions
Every loop needs explicit stopping conditions: task completed, maximum steps reached, budget exceeded, policy denied, tool failure, or human escalation.
Why loops fail
Unbounded loops often come from ambiguous success criteria, tools returning low-quality results, or the model repeatedly choosing the same action. Add step budgets and detect repeated tool calls.
Step 2
Example
Example
Apply The agent loop to a realistic production scenario and trace the decision step by step.
Step 3
Code
Code
Add implementation notes or a runnable example for this concept.
Step 4
Practice
Practice
Write down the inputs, expected output, constraints, and one failure case for The agent loop.
Step 5
Quiz
Quiz coming soon.
Step 6
Challenge
Challenge
Design a production-ready solution for The agent loop and explain one important trade-off.
Complete every stage
Work through every step in order, then the lesson will be marked complete.
Each chapter and subtopic has its own public URL under /ai-agent.