Skip to content
Skip to content
PGB Learn

Planning and the agent loop

Think, act, observe

An agent does not answer in one shot. It runs a loop:

  1. Think. The model reads the goal, the history so far and the tools available, and decides what to do next.
  2. Act. It asks for a tool call, or decides it is finished and writes the final answer.
  3. Observe. The platform runs the tool and the result is added to the history.

Then the loop goes round again. Each trip is one turn. The loop ends when the model gives a final answer, when something stops it (a limit, a cancel, a failure), or when it needs a person's approval and must wait.

Planning

Planning is just the "think" step at scale. For a simple job the agent plans in one line and acts. For a bigger job it may break the goal into sub-steps, do one, look at the result, and revise the plan. You can help in two ways:

  • Give it the plan. Numbered steps in the instructions make behaviour predictable and traces easy to read.
  • Give it a way out. "If the page cannot be fetched, say so and stop" prevents the agent from looping on a failure.

Why loops need limits

A loop can go wrong in a few ways: it can repeat a failing step, wander off the task, or keep going because nothing tells it to stop. Real platforms therefore cap the number of turns, the time spent in one go, and the cost of a run. Limits are not an insult to the model. They are the same seatbelts every engineer builds into any process that can repeat itself.

Reading the loop is the best debugging tool

Because each turn is recorded, you can see exactly why an agent did something: what it thought, which tool it called with which arguments, and what came back. When a result is wrong, the cause is almost always visible in one specific turn.

How this looks in PGB Agents

Every run has a trace. The steps appear in order as Thinking, Calls a tool, the tool's returned result, possibly Needs your approval, and finally Answer with a Result box. Show details on a tool step reveals the exact arguments and result. Each run has a step limit, a time limit and a budget, and a run can be cancelled at any time.

Try it yourself

  1. Run "Concept lab" with the input https://example.com and read the trace from top to bottom. Label each step in your head as think, act or observe.
  2. Edit the instructions so the page address given is something that does not exist, for example https://example.invalid/page, and run again. Find the failed tool step and read what the agent did next. Did your fallback instruction help?
  3. Open Budget and note the Per run (USD) value. Imagine the loop never ended: that number is what stops it.

Recap

  • The agent loop is think, act, observe, repeated until done or stopped.
  • Plans can be written into instructions, and every instruction set needs a way out for failure.
  • Loops need limits on turns, time and cost.
  • The trace shows each turn so you can debug by reading.

Open Access Course

Free

forever
  • 8 structured lessons across 4 modules
  • Interactive knowledge checks with instant feedback
  • Verifiable completion certificate & PDF