The Agent Loop: Plan, Act, Observe, and Repeat
Prabhat
Aug 19, 20265 min read8 views
Today's outcome: Turn a task into a repeating sequence of plan → act → observe → repeat, with a clear condition for stopping.
This is Day 3 of AI Agents in 30 Days. In Day 2, we mapped the parts of an agent. Today, we connect those parts through the loop that makes progress possible.
Advertisement
The mental model
An agent rarely completes a useful task with one model response. It receives a goal and the information currently available, decides what should happen next, performs an action, and examines the result. That result becomes new information for the next decision.
You can remember the process with four verbs:
Plan: Decide the next useful step.
Act: Produce an output or use an available tool.
Observe: Read the result, feedback, error, or changed state.
Repeat: Update the plan and choose the next step.
The OpenAI Agents SDK documents a concrete version of this pattern: the runner calls the model, ends when it receives a final output, follows a handoff when requested, or executes tool calls and runs the loop again. It can also enforce a maximum number of turns. See the current OpenAI Agents SDK running-agents guide.
The words used by a framework may differ, but the central idea is the same: each result affects the next decision.
A practical example: revising a study schedule
Suppose the goal is:
Create a realistic weekly plan for Math, Java, and revision.
First loop
Plan: Fit the three subjects into the available week.
Act: Create the first schedule.
Observe: The learner says, “Tuesday is too busy.”
Repeat: Move the Java session to Wednesday and review the updated schedule.
The feedback is not a failure. It is an observation that changes what the agent should do next.
Second loop
The agent can now check whether Wednesday is available and whether the weekly workload remains balanced. If the revised schedule meets the learner's constraints, the agent can return it as the final result. If not, it can continue.
Stage | Question to ask | Study-planner example |
|---|---|---|
Plan | What is the next useful step? | Place the remaining study session |
Act | What can the system do now? | Create or revise the schedule |
Observe | What changed or came back? | Tuesday is too busy |
Repeat | What should happen next? | Move the session and check again |
Stop | When is the task complete? | The schedule fits the learner's week |
Why the stopping condition matters
A loop needs a reason to finish. Otherwise, an agent may keep revising a result that is already useful, repeat the same action, or spend more time and money without making progress.
A stopping condition might be:
the requested result has been produced;
all required checks pass;
the user approves the result;
the next action requires human permission;
a turn, time, or cost limit has been reached; or
the agent cannot continue safely with the available information.
Not every task requires several loops. A simple request may finish after one response. The loop becomes valuable when the task needs actions, feedback, revision, or multiple dependent steps.
Try this today
Choose one small task, such as planning tomorrow's study session, organizing a reading list, or comparing two learning resources.
Write four lines:
Goal: What result do I want?
First action: What should happen first?
Expected observation: What result or feedback will I check?
Next decision: What changes after that observation?
Then add one stopping condition: How will I know the task is complete?
Completed example you can copy
Task: Plan tomorrow's Java study session.
Goal:
Create a realistic 90-minute plan covering collections and practice.
First action:
List the topics, available time, and one practice problem.
Expected observation:
Check whether the plan fits 90 minutes and whether each topic has practice time.
Next decision:
If the plan is too long, reduce reading time and keep the practice problem.
Stopping condition:
Finish when the plan fits 90 minutes and includes both learning and practice.
Common misconceptions
“The plan must describe every future step.”
It does not. The plan only needs to identify a useful next step. Later observations may make a long initial plan obsolete.
“Every action must call an external tool.”
No. An action can be a tool call, a structured output, a question for the user, or another allowed operation. Use tools only when the task requires them.
“Repeating means running the same prompt again.”
A useful loop includes the new observation. Repeating without incorporating the result is not progress.
“A longer loop means a smarter agent.”
More turns can also mean wasted work. A good agent stops when the goal is met or when continuing is unsafe or unproductive.
Quick knowledge check
What turns the result of one action into input for the next decision?
Why does an agent need a stopping condition?
If a learner says Tuesday is too busy, which stage receives that information?
Answers
The observe stage captures the result, and the next planning step uses it.
It prevents unnecessary or endless repetition and defines when the goal is complete.
Observe receives the feedback; repeat uses it to revise the plan.
Download the handwritten notes
Use the one-page notes as a quick reference for the four-stage loop, study-planner example, exercise, and stopping condition.
day-03-handwritten-notes.pdfContinue learning with Korshub
Understanding the loop is easier when you practise with small, bounded projects. Korshub helps learners discover course listings and continue to the official course platform to review the current details and enrol when a course fits their goals.
Explore courses on Korshub and look for resources on AI agents, prompt engineering, Python, APIs, or automation. Course prices, access models, and availability can change, so verify the current information on the official course page before enrolling.
Series navigation
Previous: Day 2 - Anatomy of an AI Agent
Roadmap: AI Agents in 30 Days
Next: Day 4 - Context and Instructions (link after publication)