Why a Loop Is Not Enough

The Paris request now becomes a real business task:

I am Marco Polo, employee e-4471, grade L4, from Mumbai. Book my outbound flight and a three-night hotel stay in Paris next week, within policy and ₹1,50,000, after my manager approves.

Earlier chapters showed how an agent can search, check policy, and replan. A deployed agent needs four more abilities.

The four reliability needs

flowchart TB G[Paris trip goal] --> M[Remember
survive a crash] G --> A[Wait for approval
pause before booking] G --> R[Recover from errors
retry safely] G --> T[Show its steps
record every decision]
Need What it means for the trip
Remember Keep the plan and budget even if the program crashes.
Wait for approval Stop before booking and continue after the manager says yes.
Recover from errors Retry a failed search, but never book twice.
Show its steps Record each decision so the plan can be checked later.

A hand-written agent loop

The basic loop is still useful:

history = []

for step in range(MAX_STEPS):
    action = model.choose_next_action(history)  # think
    result = run_tool(action)                   # act
    history.append(result)                      # remember

    if action.name == "finish":
        break
flowchart LR T[Think
model picks a tool] --> A[Act
code runs the tool] A --> R[Remember
append the result] R --> T

This can plan a trip in one running Python process. It is not yet ready to handle real money.

What the loop still cannot do

1. Survive a restart

history lives in process memory. If the server stops, the policy, fare shortlist, and remaining budget disappear.

2. Pause and resume

The loop can stop, but it has no durable place to wait four hours for a manager. Starting it again normally starts a new run.

3. Retry the right thing

A fare search timeout and an invalid travel date are different problems:

One broad except block cannot make those decisions safely.

4. Bound more than steps

A step counter prevents an endless loop, but production limits also include time, tokens, model calls, and money.

5. Replay a disputed decision

If the traveller asks, "Why did it choose this fare?", an in-memory list may not show the exact state, tool arguments, retries, and approval used at each step.

What goes wrong

One-line summary

The agent loop supplies think, act, and remember; the next layers make that loop persistent, pausable, recoverable, bounded, and inspectable.

Key terms