Architecture · Agents
AI Agent Architecture: How Agents Plan, Use Tools And Stay Safe
The short answer
An AI agent is a language model running in a loop: it reads the goal and context, decides the next step, calls a tool, observes the result and repeats until the job is done or it hands over. Around that loop sit the parts that make it production-grade: memory, typed tools, rules checked in code, human approval for consequential actions, and traces of every step.
By Maitreya Kulkarni · Updated · 11 min read
01 · The architecture
How Is An AI Agent Wired Together?
A goal arrives, a context layer assembles what the model needs to know, the planner decides whether to call a tool or answer, the executor runs tools through policy checks and approvals, and each tool's result feeds back into the planner for the next step.
NX-AR-02 · Architecture
The agent loop
- Outside world
- Data & integration
- AI agent
- Your people
- System of record
- L1
Inputs
(Outside world)User goal
“Book a viewing for this lead”
. Hands work to: Context assembly.Event trigger
New record, schedule
. Hands work to: Context assembly.
Passes down: a goal - L2
Context
(Data & integration)Context assembly
Instructions, history, facts
. Hands work to: Planner.Long-term memory
Vector store, profiles
. Hands work to: Planner.Tool catalogue
Schemas it may call
. Hands work to: Planner.
Passes down: the prompt - L3
Reasoning
(AI agent)Planner
LLM decides the next step
. Hands work to: Tool executor, Responder.
Passes down: a tool call or an answer - L4
Action
(AI agent)Tool executor
Validates arguments, runs tools
. Hands work to: Policy check, Human approval.Responder
Writes the final reply
. Hands work to: Policy check.
Passes down: checked actions - L5
Control
(Your people)Policy check
Limits enforced in code
. Hands work to: Tools and APIs, User reply.Human approval
Money, contracts, people
. Hands work to: Tools and APIs.
Passes down: allowed actions - L6
World
(System of record)Tools and APIs
Results come back
. Hands work to: Planner.User reply
Trace store
Every step, replayable
02 · Definition
What Makes Software An AI Agent?
Autonomy over the steps. A chatbot answers one message at a time; a fixed workflow runs steps someone wrote in advance. An agent is given a goal and decides for itself which steps to take, which tools to call and when it is finished.
| Item | Workflow | Agent |
|---|---|---|
| Who decides the steps | WorkflowThe developer, in advance | AgentThe model, at run time |
| Predictability | WorkflowHigh | AgentLower; bounded by rules |
| Cost per run | WorkflowLow and fixed | AgentVariable |
| Best for | WorkflowKnown, repeatable processes | AgentOpen-ended tasks with many paths |
03 · The loop
How Does The Agent Loop Work?
The model is shown the goal, the context and the tools it may call. It replies either with a tool call (a function name and arguments) or a final answer. The application runs the tool, adds the result to the conversation and asks again, until an answer, a hand-off or a limit.
Reason and act
The ReAct pattern interleaves reasoning with actions, so each step is chosen in light of what the last one returned.
Function calling
Models emit structured calls against JSON schemas, which code validates before anything runs.
MCP
The Model Context Protocol standardises how tools are described and called, so one agent can use many systems through one interface.
Stopping
A final answer, a hand-off to a person, or a hard limit on steps, time or cost ends the run.
04 · Memory
How Do Agents Remember?
Through layers. The context window is working memory for one run; anything longer-lived has to be stored and retrieved deliberately, and choosing what to store is a design decision.
Working memory
The current conversation, tool results and instructions, held in the context window.
Episodic memory
Logs of past runs and conversations, summarised or retrieved when relevant.
Semantic memory
Facts and documents in a vector or keyword index, fetched by retrieval.
Procedural memory
Instructions, playbooks and skills the agent loads for a type of task.
05 · Safety
How Do You Keep An Agent Safe In Production?
By assuming the model will sometimes be wrong or manipulated, and building the system so that it cannot do much harm when it is. Safety lives in permissions, code and process, not in the prompt.
Least privilege
Each tool gets only the access it needs; read and write are separate; credentials are scoped per agent.
Rules in code
Limits such as maximum refund or allowed recipients are checked before a tool runs, whatever the model says.
Human approval
Irreversible or consequential actions wait in a queue for a named person.
Prompt injection defence
Content from documents, emails and web pages is treated as data, labelled as untrusted, and never allowed to grant new permissions.
Budgets and timeouts
Caps on steps, tokens and time stop loops and runaway costs.
Traces and evals
Every step is logged, and a test set of real cases runs on every change.
The ecosystem
Claude
OpenAI
Gemini
MCP
LangGraph
LangChain
n8n


