LyraLearn AI Learning Platform
Exams
← Module 9 Β· Agent Design Patterns
🎧 Listen

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.

Circular diagram of the agent cycle observe, decide, act, repeat, with multiple exit gates for goal reached, iteration cap, and budget cap.

The four phases

Each turn of the loop walks through the same four steps:

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:

"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.

🧠 Quiz yourself on this lesson →

Ask the AI Tutor

Grounded in the course lessons β€” it cites its sources and says when it doesn't know.