Build context
Assemble instructions, messages, state and relevant retrieved data.
An AI agent is not merely “an LLM that thinks repeatedly.” It is a software control loop that gives a model context, tools, memory, guardrails and stopping rules — then decides what happens next.
Assemble instructions, messages, state and relevant retrieved data.
The LLM produces either an answer, a tool request, or another structured action.
The runtime validates the model response against schemas, policy and control logic.
Execute approved tools, persist results and append the outcome to state.
Return a final answer or continue — subject to explicit budgets and termination rules.
The important refinement is architectural: the orchestrator owns the loop. The LLM does not independently keep itself alive; it receives one turn of context at a time.
# simplified production-oriented agent loop
state = initialize_state()
step = 0
while not should_terminate(state, step):
step += 1
messages = build_context(state)
response = call_model(
messages=messages,
tools=tool_schemas
)
if response.type == "final":
persist_final(state, response)
break
elif response.type == "tool_call":
validate_tool_call(response)
result = execute_tool(response)
record_result(state, result)
else:
record_assistant_turn(state, response)
enforce_budgets(state) # time, tokens, cost, stepsThe original infographic is conceptually strong, but a production-grade explanation benefits from separating model intelligence from runtime control.
Messages, task plan, retrieved documents, intermediate results, user/session data and structured scratch state maintained outside the model.
Search, APIs, code, databases, files, calculators, email and domain-specific functions. Tools extend reach; they also increase risk.
Final answer, maximum steps, no-progress detection, timeout, cost ceiling, token budget, explicit user cancel or unrecoverable error.
The application decides what context the model receives, what tools are exposed, whether calls are valid and whether another turn should happen.
Long-running agents must summarize, prune or retrieve selectively. “Just keep appending everything” eventually becomes expensive and brittle.
Each turn should be inspectable: prompts, tool calls, latency, token usage, errors, costs and stop reason. Otherwise debugging becomes guesswork.
Behavior emerges from the combination of model capabilities, system instructions, context construction, tool schemas, retrieval, memory policy, orchestration logic, permissions, guardrails and termination strategy. Two products using the same model can behave very differently because their runtimes differ.
The model can reason, but dependable operation comes from constraints, validation, observability and failure handling around it.
✓ Structured tool schemas and input validation
✓ Explicit max-step and time budgets
✓ Per-tool timeout and retry policy
✓ Trace IDs and iteration logs
✓ User-visible confirmation for consequential actions
✓ Sensitive-data boundaries
✓ Deterministic stop reasons
✓ Fallback behavior for unavailable tools
✓ Evaluation set for common and adversarial tasks
✓ Human escalation path where appropriate
Interprets context, proposes next actions and generates language or structured outputs.
Controls the loop, state transitions, tool availability, guardrails and termination.
Convert model proposals into effects on the world — which is why validation and permissions matter so much.
Not inherently. It only knows what the application includes in its context. The orchestrator can tell it about prior turns, budgets or loop status, but that is runtime-provided information.
No universal definition exists. A useful distinction is that agentic systems choose among possible next actions dynamically, while ordinary workflows follow a predetermined sequence.
Typical causes include ambiguous goals, weak tool descriptions, inconsistent state, missing error recovery, context overload, non-idempotent tools or inadequate stopping logic.
Least-privilege tool access, strong validation, explicit confirmation for high-impact actions, bounded iteration, observability, secure secret handling and policy enforcement outside the model.