The Agent Loop
Every agent, no matter how sophisticated, runs the same simple cycle underneath: observe β decide β act β repeat. Understanding this loop is understanding agents β the rest is detail. The cycle continues until the goal is met or a limit forces it to stop.

The four phases
Each turn of the loop walks through the same four steps:
- Observe β gather the current state: the original goal, the conversation so far, and the result of the last action. This becomes the model's context for this turn.
- Decide β call the model with that context and let it choose the next move: call a tool, ask a clarifying question, or declare the goal complete.
- Act β execute the model's choice. If it picked a tool, your code runs that tool and captures the result. The model proposes; your code performs.
- Repeat β feed the result back in as a new observation and go around again.
The model only ever produces text or a structured tool request. The actual doing β the API call, the database write β happens in your code, which is where you keep control.
When the loop ends
A loop that can't stop is a runaway bill and a hung request. An agent must have explicit exit conditions, and you should always have more than one:
- Goal reached β the model signals it's done and you've verified the result.
- Iteration cap β a hard maximum number of turns (say, 10). When hit, the loop stops whether or not the goal was met.
- Budget cap β a token or wall-clock ceiling that ends the run before costs spiral.
- Failure β a tool errors unrecoverably, or the model asks for something disallowed.
"The model decides it's finished" can never be the only exit. Models miscount, repeat themselves, and occasionally insist they're not done forever. The non-model limits are your safety net.
A concrete walk-through
Imagine an agent asked to "find which lesson covers temperature and summarize it." Turn one: it calls a search tool (act), gets back three candidate chunks (observe), and decides one is the match (decide). Turn two: it reads that lesson, decides it has enough, and writes the summary β goal reached, loop exits after two iterations.
Note what made it safe: a small, well-defined toolset, a result fed back each turn, and a cap ready to catch it if it had kept searching. LyraLearn doesn't run this loop for its Tutor β its flow is fixed β but the same observe/act discipline is exactly what you'd build the day a task genuinely needs the model to choose its own path.