Announcing US$ 3.2M pre-seed round · OneVC · Maya · Norte Ventures Read →
Back to blog

Agentic loop:
what it is and how an AI agent's cycle works

In short

An agent is given the task of explaining why the ERP records more units of an item than the warehouse system counted in the inventory. Every query it makes depends on the result of the previous one. That sequence has a name: the agentic loop, the cycle in which the system calls the model, carries out the indicated action and feeds the result back into the context until a stop criterion is met. Every turn consumes tokens, and the number of turns depends on the context the agent finds. This is where the Company Brain comes in: the layer that knows the company, meaning what data exists, where it lives, how it relates and who can see what.

The agentic loop repeats call, action and result until a stop condition

The agentic loop is the software mechanism that runs an AI agent. The model produces structured text indicating the next action: call a tool, look up a piece of data, ask a person for confirmation or finish. The code around the model, called the orchestrator, carries out the action, appends the result to the context and calls the model again. The stop rule lives in that code.

Every turn of the cycle goes through the same six steps

In the stock discrepancy case, one turn follows this order:

  1. Goal: explain the difference in an item's balance at a branch, with the conditions for finishing.
  2. Context assembly: instructions, tools, data already obtained and earlier results go into the call.
  3. Model call: the model indicates the next action, such as querying the item's movements since the last inventory.
  4. Execution: the orchestrator checks permissions and runs the query.
  5. Incorporating the result: the tool's response goes into the context of the next call.
  6. Stop check: if no criterion has been met, another turn begins.

In one of the turns, the receiving notes show a return received at the warehouse with no entry in the ERP. The model indicates the adjustment, and the cycle pauses until inventory control approves it.

The steps of the agentic loop as a ring, from assembling the context to checking whether to stop
Every turn of the agentic loop goes through the same six steps

A single call and a fixed flow have a number of steps known in advance

A single call to the model takes one input and returns one output, at a predictable cost. A fixed automation flow runs a sequence written by a person, such as opening a task for the stockroom when the balance diverges. The agentic loop defines the sequence during execution, and the number of model calls is only known at the end. That flexibility hands the project the job of limiting cost and duration.

Stop criteria define when the agentic loop ends

At every turn, the orchestrator checks explicit conditions for finishing:

  • Goal reached: the final answer matches the format defined in the task.
  • Iteration limit: a cap on turns per run.
  • Cost or time limit: a token budget or a maximum duration.
  • Error: an unavailable tool or a repeated invalid result ends the run with the reason recorded.
  • Human approval: the next action requires a person's confirmation.

Without these criteria, the loop can spin forever. Every repeated turn adds cost without bringing the task closer to its goal.

Each turn resends the accumulated context and raises token usage

In most implementations, the model keeps no state between calls. Each turn resends the instructions, the tool descriptions and every result obtained so far. Because the accumulated context goes into every following call, total cost grows faster than the number of turns.

In 2024, Princeton University researchers showed that state-of-the-art agents can be needlessly complex and costly, costing far more than simple alternatives with similar accuracy and argued for measuring cost and accuracy together. In a company, the cost of an agentic loop depends on how many turns the task needs, how much context goes into each turn and which model runs each call.

Cost per turn in the agentic loop, with accumulated results resent on every call
In the agentic loop, each turn resends the accumulated results and token usage grows

The cycle's failures add up with the number of turns

Some failures show up often in a long agentic loop:

  • Repeated tool calls: the same query comes back with almost identical parameters, because the previous result was ambiguous.
  • Losing the goal: intermediate results take up most of the context and the original instruction loses weight.
  • Wrong or outdated result: the action starts from a balance read before a recent movement.
  • External content: text read in a document or email can carry embedded instructions, a risk known as prompt injection.

Approval points put a person inside the cycle

Checking a balance is a read. Posting a stock adjustment changes the branch's accounting result. The cycle's design separates these classes of action and places an approval point before the ones with the greatest consequences. There, the cycle pauses and shows the responsible person the proposed action and the origin of each piece of data.

The Company Brain cuts the turns spent working out what each record is

With raw data, a good share of the turns goes into discovering the basics. The item has one code in the ERP and another in the warehouse. The ERP counts in boxes, and the warehouse counts in units. Every attempt to reconcile this is a paid turn.

The Company Brain delivers that work already resolved. The knowledge graph links the ERP item to the warehouse item and to the receiving notes. The business ontology records each system's unit of measure and the conversion rule. The context arrives via MCP, the open protocol that connects models to data sources, with permissions inherited from the source system. Every query is logged with its source, and with fewer turns some of the calls can run on lower-cost models.

An agentic loop over raw data compared with an agentic loop that queries the Company Brain via MCP
With context resolved in the Company Brain, the agentic loop spends fewer turns on discovery

The agentic loop depends on well-described tools and correct sources

Tools with vague descriptions keep producing wrong calls. A balance posted late in the ERP is still the information the agent receives. Limits and approval points remain the responsibility of whoever designs the cycle.

The first agentic loop in production starts with designing the cycle

The starting point is a frequent task with known sources, such as investigating stock discrepancies. Before the first test, the design records the goal, the answer format, the limit on turns and tokens, the stop criteria and the approval point. The log of the turns in each run shows where the agent spent calls on discovery, and that is the first context to resolve.

Get the next articles on context architecture for AI