AI Agent Execution LoopAI Agent Execution LoopStage 1 of 7 · 7 stages · ~5 min
AI RUNTIME · PROPOSAL TO SIDE EFFECT

A model can request a refund; the host decides what happens

Follow one customer request through context assembly, a typed tool proposal, host validation, execution, returned evidence, and completion.

7 stages~5 min
  1. ASSEMBLE THE TURN
  2. CHECK THE PROPOSAL
  3. RETURN THE EVIDENCE
Read mode · answer first

How an AI agent execution loop works

Follow one AI agent request through instructions, a typed tool call, host approval, execution, returned evidence, retries, and completion.

Cheat sheet · 5 essential ideas

The whole story in 5 lines

An agent is a model inside a host-managed loop that turns typed proposals into checked actions and returned evidence.

  1. The model receives the user goal together with application rules and available capabilities.
  2. The model emits either text or a tool request based on what the task still needs.
  3. A schema turns a proposed action into named fields that software can inspect.
  4. The host owns validation, permissions, credentials, and the final decision to execute.
  5. Results return as evidence, then the model finishes, repairs the call, or stops at a limit.
What two kinds of input shape the worked refund request?
The user supplies the goal while the application supplies rules and available tools. Both enter the model context with different authority.
What observable choices can the model make next?
It can produce text or emit a structured tool request. The host reacts to the output item rather than inspecting private reasoning.
Why is a tool schema more useful than a sentence saying to refund something?
The schema names required fields and allowed values. That lets ordinary software parse and validate the proposed action.
Why does the host sit between the model and the tool?
The host controls credentials and execution. It can reject malformed, disallowed, or unapproved calls before any side effect happens.
What lets the model connect a returned result to the correct request?
A call identity links the result to the earlier request. The model then uses that result as evidence for its next output.
Download PDF cheat sheet
Stage 1 of 7

A refund cannot happen through words alone

A refund cannot happen through words alone

A customer asks for order 1042 to be refunded because the screen arrived cracked. A useful answer must change an account, not merely sound confident.

The model can propose what should happen, but it does not secretly own the store database. A host application controls tools, credentials, and real side effects.

The request points at a locked refund action, while the model begins outside that boundary. What must connect language to the real system?

Pause and predict
What safely connects the model to the refund system?

The complete route now appears between the request and the account change. We will follow inputs, a decision, a typed call, host checks, execution, and return.

Four terms will carry us through the lesson: model, tool call, host, and tool result. Now let us start with what enters the model.

Stage 2 of 7

The model receives a goal inside rules

The model receives a goal inside rules

We begin with two sources that matter for the same turn. The customer supplies a concrete goal, while the application supplies rules for handling account changes. Keeping them separate makes their authority easier to inspect.

Our worked application says to use tools for account changes and require approval before writes. Those rules limit how the customer request may be completed. The user goal remains important without overriding those safeguards.

The goal asks for a refund, but the application forbids an unchecked write. The two inputs now point toward different immediate behaviors. Which source should control that conflict?

Pause and predict
Which input controls the conflict in this worked OpenAI-style request?

Both bands enter the model together, but their order stays intact. In OpenAI Responses, top-level instructions take priority over the input parameter for that request. The host deliberately constructs this ordered context before inference.

Here is the key: the model receives a goal, rules, and available capabilities before acting. That bundle defines the choices available for this turn. Next, we will inspect its observable choice between text and a tool request.

Stage 3 of 7

The next output is text or a tool request

The next output is text or a tool request

Now that the request and rules are together, the model must choose its next observable output. We do not need to invent or expose private reasoning. The host only needs a well-defined output item.

One branch produces ordinary assistant text. That works when the answer already exists in context and no external system must be read or changed. Text communicates a result without requesting an external capability.

The refund still requires a real account change, and only the host can reach that system. A sentence cannot supply execution evidence by itself. Which output can move the task forward?

Pause and predict
Which output can request the external refund action?

The tool branch receives the request because the goal remains unfinished outside the model. This output is a proposal for the host, not proof of execution. Its meaning is deliberately narrower than a success claim.

The observable contract is simple: text communicates, while a tool item requests capability. The host can branch on that public item type. Next, we will open that item and inspect the fields software can validate.

Stage 4 of 7

A schema shapes the proposed action

A schema shapes the proposed action

We just selected the tool branch. The host previously advertised a refund tool with a name, description, and JSON Schema for its accepted arguments. That advertisement is the proposed action contract.

The schema requires an order identifier and a reason from a small allowed set. Unknown fields are rejected in this strict worked definition. Strictness narrows the shapes that downstream software must handle.

The call names refund_order and supplies both arguments, but a later result must still find this exact request. Multiple calls may exist in one conversation. Which field provides that link?

Pause and predict
Which field links the later result to this call?

Every call field now fits a declared slot, including the call identity. Ordinary software can parse this record and reject missing, mistyped, or unexpected arguments. Validation still does not authorize the side effect.

OpenAI names this output a function_call, while MCP wraps comparable data in tools/call. The envelope differs, but typed names and arguments create the same boundary. Each runtime still owns its exact wire format. Next comes host validation.

Stage 5 of 7

The host checks before it executes

The host checks before it executes

The typed call has left the model, but nothing has executed yet. The host receives the proposal because it owns the actual tool connection and credentials.

The host parses the arguments, checks the advertised schema, and confirms refund_order is allowed. Each check can stop the call before a side effect.

The fields are valid and the tool is allowed, but this call changes an account. Who gives the final permission to cross the boundary?

Pause and predict
Who owns the final execution decision?

Approval opens the final gate, so the call reaches the executor. A denial would divert the same valid proposal into a blocked result instead.

Switch Approval between Approve and Deny. The downstream path changes between an executor-bound call and a blocked result, while the proposed arguments stay identical.

The host is the trust boundary because it validates, authorizes, and dispatches. The exact interface varies by runtime. Next, we will execute the call and return evidence.

Stage 6 of 7

Execution returns evidence for the next decision

★ If you remember one thing · A tool result becomes new model input, so execution can continue as a controlled loop.
Execution returns evidence for the next decision

The call has passed every host check, so the executor can route refund_order to the account service. The model remains outside that trusted execution boundary.

The refund tool runs with the validated arguments and returns a submitted receipt. Execution may also return a structured failure rather than ordinary success data.

The host now holds a real tool result linked to call_refund_1042. Where must that evidence go before the model can answer truthfully?

Pause and predict
Where does the linked tool result go next?

The green result travels back into the model ledger under the same call identity. This return closes one iteration and gives the model grounded evidence.

A successful receipt lets the model finish, while a recoverable error can produce a corrected call. A denial or permanent failure should become an honest limitation.

Hosts also enforce budgets for time, cost, and repeated calls. Our three-turn ceiling is illustrative, but the principle prevents an error from becoming an endless loop.

The agent stops when the goal is satisfied or a host boundary says to stop. Otherwise, returned evidence starts another checked iteration. Now let us step back and see the whole picture together.

Stage 7 of 7

The host-managed loop as one system

The host-managed loop as one system

We started with the input boundary. The model received the customer goal together with application rules and a list of available capabilities.

Then we learned that the model emits an observable choice. Text communicates directly, while a tool item asks the host for external capability.

Next, the schema gave that proposal a machine-checkable shape. Required arguments and a call identity let software validate and later match the result.

The host gate kept authority outside the model. It parsed the call, checked policy, gathered approval, and controlled the credentials used for execution.

Execution produced evidence that returned to the model. Success finished the goal, recoverable errors invited repair, and hard limits stopped unsafe repetition.

Together, these boundaries explain the whole agent loop. A model proposes the next step, while the host checks actions, returns evidence, and decides when execution must end.

Cheat sheet · 5 essential ideas

The whole story in 5 lines

An agent is a model inside a host-managed loop that turns typed proposals into checked actions and returned evidence.

  1. The model receives the user goal together with application rules and available capabilities.
  2. The model emits either text or a tool request based on what the task still needs.
  3. A schema turns a proposed action into named fields that software can inspect.
  4. The host owns validation, permissions, credentials, and the final decision to execute.
  5. Results return as evidence, then the model finishes, repairs the call, or stops at a limit.
What two kinds of input shape the worked refund request?
The user supplies the goal while the application supplies rules and available tools. Both enter the model context with different authority.
What observable choices can the model make next?
It can produce text or emit a structured tool request. The host reacts to the output item rather than inspecting private reasoning.
Why is a tool schema more useful than a sentence saying to refund something?
The schema names required fields and allowed values. That lets ordinary software parse and validate the proposed action.
Why does the host sit between the model and the tool?
The host controls credentials and execution. It can reject malformed, disallowed, or unapproved calls before any side effect happens.
What lets the model connect a returned result to the correct request?
A call identity links the result to the earlier request. The model then uses that result as evidence for its next output.