Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
The Agent Loop  ›  Lesson

Observe, Reflect, and Know When to Stop

Observation & Reflection 12 minAfter each action the agent observes the result, reflects on whether it is done, should adjust, or should escalate, and the loop ends through explicit stopping criteria such as a final answer or step and budget limits.

Observe, Reflect, and Know When to Stop

The train search comes back: "No sleeper seats available on 15 October." A careless agent would search the same thing again, and again, burning money until someone pulls the plug. Tripmate needs to read the result, think about what it means, and know when the job is done — or when to give up.

The rule

Read every result, adjust the plan, and stop on purpose.

Observation is taking in what the action produced: the tool result, an error, or the fact that nothing came back. Reflection is asking what that means for the goal:

  • Did the step succeed? ("Three trains found.")
  • Did it fail in a way I can fix? ("Date format rejected — send it as YYYY-MM-DD.")
  • Did it change the plan? ("No sleepers Thursday — try Friday, or try third AC.")

Then the loop goes back to reasoning with the new facts.

Stopping criteria are the rules that end the loop. Good agents have several, because any single one can fail:

  • Goal met — the model gives a final answer instead of another tool call.
  • Step limit — for example, at most 15 tool calls per request.
  • Budget limit — a cap on tokens, money or time.
  • Stuck detection — the same call with the same arguments repeated.
  • Needs a human — a decision only the user can make, like paying a higher fare.
loop:
    reply = model(context)
    if reply is a final answer:   stop (goal met)
    if steps >= 15 or cost >= limit:  stop (report what was found)
    result = run_tool(reply.tool_call)
    context.add(result)           # observation feeds the next turn

The shortcut

After every observation, sort it into one of three bins: "done", "adjust", or "escalate". Done → answer. Adjust → change the next step (never repeat an identical failed call). Escalate → stop and ask the user, or report honestly.

Tripmate hits a full trainStep 1 of 4
  1. Observe

    search_trains for Thursday returns no sleeper seats.

The classic failure is the infinite loop: an agent retrying the same failing call forever. A hard step limit catches it even when the model's judgement does not.

Drills

Answer fast — trust the rule.

quick drill

A tool returns an error saying the date format is wrong. What is the best next step?

quick drill

Why give an agent a hard maximum number of steps?

quick drill

The only train that fits costs twice Asha's budget. Which bin is this?

quick drill

Which signal most clearly means the goal is met in a typical loop?

Remember

  • Observe every result, reflect on what it means, and feed it into the next decision.
  • Shortcut: done, adjust, or escalate — and never repeat an identical failed call.
  • Trap: loops with no step, budget or stuck limit.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainDesign the stopping rules

Tripmate once ran 60 tool calls searching the same full train again and again. Explain what went wrong in terms of observation and reflection, and list the stopping criteria you would add.