← Back to concept explainers

Concept Fable

Agent loop

Conclusion first:The agent loop is the basic closed loop of Agent operation: observe the current state, reason or plan, choose an action, execute through tools or code, then write the execution result back into context and enter the next round. The key to an enterprise Agent is not just that the model can answer, but that each round must continue advancing with the latest state, permission boundaries, tool results, and failure information. Without a clear loop, an Agent is easily led by local signals, repeats execution, misses new states, or continues acting on tasks that have been canceled.

Agent Loop · Agent architecture

Read the story first. There is no rush to give a definition here; let the question grow on its own first.

Fable

The night watchman of the courtyard and the courtyard that was never fully walked

At Bluestone Clinic, someone always had to patrol the courtyard at night. At first there were only three wards, and one patrolman carried a lantern from the east corridor to the west corridor, checking the medicine stove, the door bolt, and the patients' water bowls. Whatever he saw, he handled along the way, and before dawn he submitted a simple note.

Later, the clinic expanded into a seven-courtyard compound. Patients had urgent and non-urgent cases, the medicine stoves had open and low fires, family members passed messages on the spot, and the accounting office still had to verify precious medicinal materials. The patrol still walked according to old habits, and after one round, new events that had happened earlier had already become old accounts later.

The shopkeeper first added a rule: every night you must walk ten full laps. The night watchman complied, and the notes were full of neat lap counts. But the heat did not become more accurate because of the lap counts, and the patients were not safer because of more footsteps. Someone then gave him a thick ledger, requiring him to write a judgment every time he encountered something. The ledger grew fuller and fuller, but the night watchman grew slower and slower. Sometimes, while he was busy explaining the previous room, the copper bell in the next room had already rung three times.

The real incident happened on a rainy night. A patient in the west wing was coughing blood, and the night watchman went to fetch medicine; on the way he saw the lamp in the east corridor had gone out and turned back to light it; by the time he returned, the medicine had gone cold. He wasn't lazy—he just decided his next step based only on what was happening right in front of him, and the state of the whole compound never entered his mind.

The old pharmacist took over the night rounds. He did not ask the night watchman to be smarter; he simply hung four wooden tags at his waist: observe, judge, act, recycle. Each time he entered a room, he first updated the status on the tags; before deciding the next step, he had to look at what the previous action had brought back; if the result changed the condition, the next round began from the new state.

They also stipulated that high-risk actions cannot be performed directly. Changing prescriptions, opening the vault, or transferring to the critical care ward all require placing a request in the manager's small box to await approval. Ordinary actions can proceed, but every step must leave a record of who did it, why, and what was brought back.

A few weeks later, the night patrol had not become magical, but it had become much more stable. A light going out no longer seized all the attention, and medicine going cold was no longer buried under a round of footsteps. After each action, the patrolman returned to the courtyard's latest state, not to his own guess from a moment ago.

Only then did the shopkeeper understand that a complex courtyard cannot be guarded by a single clever judgment. For night patrol to be continuous, someone who can act must repeatedly observe, choose, execute, absorb the result, and restart the next step within the boundaries. Later the clinic passed this night patrol method on to a new apprentice. At first the apprentice only memorized the names of the four wooden cards, and soon made the old mistake again: seeing a lamp go out, he ran to the lamp; hearing a cough, he ran to the ward. The old pharmacist made him state clearly, before every action, the current state, the expected result and the change to check in the next round. If he could not say it clearly, he should not move yet. After several nights, he understood that a loop is not about walking more circles, but about making every action bring the courtyard back to a clearer starting point.

Reveal

This story is about: the agent loop

The agent loop is the basic closed loop of Agent operation: observe the current state, reason or plan, choose an action, execute through tools or code, then write the execution result back into context and enter the next round. The key to an enterprise Agent is not just that the model can answer, but that each round must continue advancing with the latest state, permission boundaries, tool results, and failure information. Without a clear loop, an Agent is easily led by local signals, repeats execution, misses new states, or continues acting on tasks that have been canceled.

What matters is that it is not just a term, but a structural problem that repeatedly appears in real AI / Agent systems. Understanding it lets you judge when to add a model, when to change a process, and when to add governance.

Metaphor mapping

  • Night Patrol at the Clinic: How an Enterprise Agent Handles Continuous Business Tasks
  • Wards, medicine furnaces, family messages: states, events, and external feedback in business environments
  • Must complete ten laps: superficial patching that measures Agent behavior only by counts or process checklists
  • Thick booklet: only adds reasoning text, without forming an executable state closed loop
  • Four wooden signs—observe, judge, act, recycle: observe, reason/plan, act, update in the Agent Loop
  • The shopkeeper's small box: human approval and permission boundaries for high-risk actions
  • Leave a result at every step: a traceable, recoverable execution record
  • Returning to the courtyard's latest state: every loop iteration must absorb tool results and environmental changes

Andy Ren Xu's judgment

The practical value of this concept is that it helps you break "AI features that look smart" into deliverable, verifiable, and governable units of work.

ReActplannerexecutortool usescratchpadorchestration

Related distinctions

This concept is easily confused with adjacent concepts; it is recommended to continue to the comparison page.

京ICP备2026014272号