Barcelona Code School

Since 2015 / 500+ graduates

AI Agent Architecture Explained: 7 Essential Layers

System design guide

AI Agent Architecture Explained: 7 Essential Layers

See what sits around the model, where control should live and how a request becomes a traceable, approved action.

Published 13 October 2026 · Barcelona Code School

AI agent architecture is the system around a model that turns a goal into controlled, observable work. A practical design has seven layers: entry and identity, orchestration and policy, model reasoning, tools, state and memory, approval and execution, and observability and evaluation. The model may choose a next step, but code and downstream systems must enforce permissions, limits, approvals and safe stopping.

Key takeaways

  • The model is one component, not the whole agent system.
  • Every boundary should pass structured data with an explicit owner.
  • Keep deterministic business rules outside probabilistic model judgment.
  • Separate read tools from write tools and gate consequential actions.
  • Design failure states, traces and tests before increasing autonomy.

The seven layers of an AI agent

Architecture is less about choosing a fashionable framework and more about deciding where data, judgment and authority live. The diagram below is a reference model, not a universal product stack.

Figure 1. A controlled AI agent architecture

Deterministic controls surround the model loop; evidence spans the full run.

Text equivalent: an authenticated request enters a policy and orchestration layer. The model receives bounded context and may select a typed tool. State preserves transaction facts, while optional long-term memory is separately governed. Write actions cross an approval and authorization boundary before execution. Every step produces trace data and structured outcomes for debugging and evaluation.

1. Entry and identity

The entry layer accepts a goal from a user, event or scheduled job. It establishes who requested the work, which organisation and record it belongs to, and what scope was granted. Input validation, authentication and rate limits begin here.

2. Policy and orchestration

This layer decides what path is allowed: a deterministic workflow, an agent loop, a human handoff or a refusal. It owns retry limits, timeouts, stop conditions and budgets. Use a fixed workflow when the steps are known; reserve model-directed routing for real ambiguity.

3. Model and instructions

The model interprets context, proposes a plan or chooses a tool. Its instructions define the role, goal, constraints and completion condition. The model can recommend an action, but should not be the final authority on identity, permissions or irreversible business rules.

4. Tools and knowledge

Tools give the system ground truth and the ability to act. Give each tool a narrow purpose, typed parameters, clear error responses and minimum privileges. Separate reads from writes: searching a CRM is not the same permission as changing a customer record.

5. Run state and memory

Run state holds facts needed to complete this transaction: identifiers, tool results, approval status and the next allowed step. Long-term memory persists selected information for future runs. Do not turn every conversation or hidden reasoning token into memory; define purpose, consent, retention and deletion.

6. Approval and execution

This is the authority boundary. A person reviews high-impact, sensitive or irreversible actions. After approval, deterministic code re-checks authorization, validates the payload and performs the write with an idempotency key. A timeout is not proof that a write failed.

7. Observability and evaluation

A trace should connect the request, model decision, tool call, approval, execution result and terminal status without exposing unnecessary sensitive data. Evaluation cases then test whether the system completed the task, used allowed tools and stopped safely.

Define the contracts before choosing a framework

A framework can run the loop, but it cannot decide your business boundary. Start with the records that cross each layer.

{
  "run_id": "case-1042",
  "actor_id": "user-27",
  "goal": "prepare a customer reply",
  "scope": ["customer:read", "draft:create"],
  "state": "awaiting_approval",
  "proposed_action": {
    "tool": "message.send",
    "arguments_hash": "sha256:..."
  },
  "approval": null,
  "attempt": 1,
  "trace_id": "trace-8f2"
}

The model may prepare proposed_action. The execution service checks the authenticated actor, current scope, approval object and destination state before any send.

BoundaryInput contractOutput contractOwner
Entry → controlGoal, identity, tenant, scopeAccepted, refused or routed requestApplication
Control → modelInstructions, bounded context, allowed toolsStructured decision or clarificationAgent runtime
Model → toolTool name and schema-valid argumentsTyped result or typed errorTool service
State → memoryApproved memory candidateStored, rejected or expired recordData owner
Proposal → executionAction, scope, approval, idempotency keyReceipt, known failure or uncertain outcomeDownstream system
Run → evidenceEvents with trace IDRedacted trace and evaluation outcomeOperations

How to design the architecture

  1. Name one business outcome. Define the trigger, terminal success state, non-goals and the human owner.
  2. Choose the least autonomous path. Use rules for known steps and introduce model choice only where ambiguity makes it useful.
  3. Define state and schemas. Specify required fields, provenance, lifecycle and which outputs downstream code may trust.
  4. Build narrow tools. Split reads from writes, grant minimum scope and return machine-readable errors.
  5. Place approval gates. Require a person for sensitive, consequential or irreversible actions; bind approval to the exact payload.
  6. Design recovery. Set timeouts, attempt limits, idempotency keys, destination checks and a human escalation package.
  7. Add traces and evals. Measure task completion, policy compliance, tool correctness, cost and latency against representative cases.
A guardrail prompt is not an authorization system. Enforce identity, scope, limits and final write permission in code and in the downstream service.

Permissions, approval and recovery

SituationArchitecture controlSafe result
Untrusted text asks for a hidden actionTreat retrieved content as data; tool allowlist and downstream authorization remain activeInstruction is ignored or run stops
Model requests an unauthorized toolRuntime checks tool policy and actor scopeDenied event is traced
High-impact write proposedHuman approval bound to tool, arguments and expiryNo write before approval
Tool returns malformed dataSchema validation; no silent coercionRetry bounded or human escalation
Write times outCheck destination using idempotency key before retryNo blind duplicate
Agent exceeds step or cost limitDeterministic stop conditionPartial evidence handed to a person
Trace contains sensitive fieldsRedaction, access control and retention policyUseful evidence without unnecessary exposure

Architecture test matrix

TestExpected evidencePass condition
Valid read-only requestIdentity, route, tool result, final statusCorrect answer; no write permission used
Missing or invalid inputValidation eventRejected before model/tool call
Prompt injection in retrieved textContent source and denied actionNo scope expansion or secret disclosure
Unauthorized writePolicy decision and actor scopeWrite is blocked
Approval rejected or expiredApproval statusNo execution; terminal safe state
Tool timeout after possible writeIdempotency key and destination checkNo duplicate transaction
Malformed model outputSchema errorBounded repair or escalation
Step/cost limit reachedUsage and stop reasonRun stops with a useful handoff
Trace reviewLinked events, redaction and outcomeOwner can explain what happened

Success criteria

  • Every run has an authenticated actor, a scope and a terminal status.
  • Model output crosses schema validation before code trusts it.
  • Read and write permissions are separate.
  • High-impact writes require explicit approval.
  • Retries cannot silently duplicate side effects.
  • A trace reconstructs the run without storing unnecessary sensitive data.
  • Evaluation includes expected failures, not only happy paths.

Learn to turn architecture into a working system

Understanding the layers is the first step; the useful skill is connecting them into a process that survives real inputs, permissions and failures. Barcelona Code School's AI Agent & Automation Bootcamp focuses on visual business automation with n8n: workflows, integrations, human approvals, testing and portfolio projects. It is not a LangGraph or low-level Python framework course.

Explore the AI Agent & Automation Bootcamp

Frequently asked questions

What are the main components of AI agent architecture?

A useful production view has seven layers: entry and identity, policy and orchestration, model reasoning, tools, state and memory, approval and execution, and observability and evaluation. The exact implementation varies, but each boundary needs a clear contract and owner.

Is an AI agent just an LLM with tools?

A model with instructions and tools is the smallest useful agent loop. A dependable application also needs authentication, state, authorization, approval rules, error handling, logs and tests around that loop.

Where should business rules live in an AI agent?

Deterministic rules such as permissions, spending limits, required fields and irreversible-action approvals should be enforced in code or downstream systems. Do not rely on the model to remember or correctly apply security policy.

Does every AI agent need long-term memory?

No. Keep run state only for values needed to finish the current transaction. Add durable memory only when a defined future task needs it, with consent, retention, correction and deletion rules.

How do you test an AI agent architecture?

Test each layer and the boundaries between layers: invalid input, unauthorized tools, untrusted content, malformed model output, timeouts, duplicate retries, rejected approvals and incomplete traces. A test passes only when the system reaches the expected safe state.

Sources

  1. OpenAI: A practical guide to building agents.
  2. Anthropic: Building effective agents.
  3. OWASP: LLM06:2025 Excessive Agency.
  4. BCS: How to Build an AI Agent.
Back to posts