Nexolve

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
  1. 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.
  2. 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.
  3. L3

    Reasoning

    (AI agent)
    • Planner

      LLM decides the next step

      . Hands work to: Tool executor, Responder.
  4. 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.
  5. 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.
  6. L6

    World

    (System of record)
    • Tools and APIs

      Results come back

      . Hands work to: Planner.
    • User reply

    • Trace store

      Every step, replayable

The model proposes; code disposes. Arguments are validated and rules checked before any tool runs, consequential actions wait for a person, and every observation goes back to the planner until the goal is met.

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.

Workflow versus agent
Who decides the stepsWorkflowThe developer, in advanceAgentThe model, at run time
PredictabilityWorkflowHighAgentLower; bounded by rules
Cost per runWorkflowLow and fixedAgentVariable
Best forWorkflowKnown, repeatable processesAgentOpen-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.

01

Reason and act

The ReAct pattern interleaves reasoning with actions, so each step is chosen in light of what the last one returned.

02

Function calling

Models emit structured calls against JSON schemas, which code validates before anything runs.

03

MCP

The Model Context Protocol standardises how tools are described and called, so one agent can use many systems through one interface.

04

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.

01

Working memory

The current conversation, tool results and instructions, held in the context window.

02

Episodic memory

Logs of past runs and conversations, summarised or retrieved when relevant.

03

Semantic memory

Facts and documents in a vector or keyword index, fetched by retrieval.

04

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.

01

Least privilege

Each tool gets only the access it needs; read and write are separate; credentials are scoped per agent.

02

Rules in code

Limits such as maximum refund or allowed recipients are checked before a tool runs, whatever the model says.

03

Human approval

Irreversible or consequential actions wait in a queue for a named person.

04

Prompt injection defence

Content from documents, emails and web pages is treated as data, labelled as untrusted, and never allowed to grant new permissions.

05

Budgets and timeouts

Caps on steps, tokens and time stop loops and runaway costs.

06

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

Build it with us

We Build This For Real Businesses.

The services where this architecture does the work, designed, built and handed over by Nexolve.

FAQ

Questions About AI Agent Architecture.

Still unsure about something? Ask us

Use a workflow when the steps are known in advance; it is cheaper and more predictable. Use an agent when the path depends on what it finds along the way. Many good systems are workflows with one or two agentic steps inside.

Frontier models from Anthropic, OpenAI and Google are all strong at tool use. The right choice depends on the task, latency and cost; many systems use a strong model to plan and smaller ones for simple steps.

With the right design, yes: least-privilege tools, rules checked in code, human approval for consequential actions, and full traces. Trust is earned by measuring it against real cases first.

Common choices include LangGraph, the OpenAI Agents SDK, Anthropic's Claude Agent SDK and plain code over the model APIs. The framework matters less than the tools, rules and evaluation around it.

Contact

Want This Architecture Built For You?

A 20-minute call. We'll listen to the problem, tell you honestly whether we're the right team for it, and outline what the build would look like.

  1. 01Tell us the problemA 20-minute call. Rough is fine.
  2. 02Get a scoped planWhat we'd build and what it takes, within 48 hours.
  3. 03Start on your timelineOnce the scope is signed off, we build in milestones.