Skip to content
Architecture 2026-07-01 10 min

AI Agent Architecture

Planning loops, tool use, guardrails, memory and evaluation for production agents.

By Mohammad Zayed

Overview

Production AI agents need a bounded loop: plan, act, observe, validate, repeat — with hard limits on cost and steps.

Components

  • Planner — decides the next action from state.
  • Executor — runs typed tool functions.
  • Guardrails — budgets, policy and validation.
  • Memory — conversation and working state.

Diagram

Agent loop
Goal │ ▼ [ Planner ] → [ Executor ] → [ Validator ] │ │ │ fail → retry (capped) ▼ [ Memory ] → complete? → respond

Every step passes a validation gate before the next iteration.

Control loop

agent/run.ts
for (let step = 0; step < MAX_STEPS; step++) {
  const action = await planner(state);
  await guardrails.assert(action, state.usage);
  const result = await executor(action);
  if (!(await validator(result))) continue;
  state.append(result);
  if (state.isComplete()) break;
}
Always cap steps and tokens. Unbounded loops are the fastest path to a surprise bill.

Deployment

Run as queue workers so long runs survive crashes; persist state to Postgres for resume.

Security

Scope tool credentials to least privilege, never let the model write raw SQL, require human approval for payments and deletes.

Frequently asked questions

Is this the only way to build it?
No. These are reference patterns we reuse. Adapt the boundaries to your constraints, team and compliance needs.
Should I copy this exactly?
Use it as a starting point. Validate each decision against your traffic, data sensitivity and team size.
Can NorthFlow implement this?
Yes. Share a project brief and we'll tailor the architecture to your product.

Continue reading

Want this architecture for your product?

Share one workflow and the outcome you want. We'll review your brief and suggest an appropriate next step; scope and deliverables are agreed before work begins.

Founder-led delivery · Existing systems first · Available internationally