Skip to article content Blogs

The Real Architecture Behind Production AI Agents

What it takes to turn an agent demo into a system an organisation can trust: identity, orchestration, saved state, guardrails, and observability.

Hands routing colorful cables across an analog orchestration patchboard

Summary

An agent demo is a prompt wired to a few tools. A production agent is a workflow system: it knows who it is acting for, saves its progress, checks the rules before every action, and stops for a person when the action is risky. This is how I think about each of those layers.

A demo answers. A production system completes work.

Most agent diagrams follow the same clean flow: context, rules, agents, action. It looks elegant, it is easy to explain, and it makes a good pitch deck. Once you look at it as a backend engineer, it gets more complicated.

A chatbot that summarises a document is one thing. An agent that creates tickets, updates documents, reviews code, or escalates to people is another. The moment a system starts taking action, you have to be able to answer some plain questions.

  • Can the agent reach only what this user is allowed to reach?
  • Can it recover if a task fails halfway?
  • Can a person review or override the important actions?
  • Can someone audit what it did, later?
  • Can we measure quality, cost, and latency?

These are not implementation details. They are the difference between a toy and something an organisation can trust.

The layers around the model

I think about a production agent as a set of layers around the model. Each one solves a single problem, and each one keeps the system from turning into a black box with too much access and too little control.

The production-agent operating layerEnterprise systems connect to identity-aware context. An orchestrator coordinates bounded agents and tools. Policy gates external actions while durable state, observability, and human control govern the full workflow.allowedreviewcheckpointstracesaudits

Enterprise systems

Connectors

Identity + permission-aware context

Workflow orchestrator

Bounded agents

Typed tools

Policy gate

Governed actions

Human approval

Durable state

Observability + evaluation

The production-agent operating layerEnterprise systems connect to identity-aware context. An orchestrator coordinates bounded agents and tools. Policy gates external actions while durable state, observability, and human control govern the full workflow.allowedreviewcheckpointstracesaudits

Enterprise systems

Connectors

Identity + permission-aware context

Workflow orchestrator

Bounded agents

Typed tools

Policy gate

Governed actions

Human approval

Durable state

Observability + evaluation

The production-agent operating layer. The model is one box. Trust, recovery, and control come from everything around it.
  1. Enterprise systems expose knowledge, events, and actions through connectors.
  2. Identity and access controls establish what the caller may read or change.
  3. The context layer supplies relevant, permission-safe evidence.
  4. The orchestrator routes and coordinates the workflow.
  5. Bounded agents propose work through typed tools.
  6. Policy evaluates every proposed external action.
  7. Low-risk allowed actions execute; higher-risk actions pause for human review.
  8. Durable state records progress so the workflow can pause, retry, and recover.
  9. Observability and evaluation trace the workflow and measure its outcome.

These are responsibilities, not ten separate services. A small team can keep all of them in one application as long as the boundaries stay visible in the code and the logs. And you probably do not need several agents on day one. One capable agent inside a proper workflow is easier to test than a group of agents talking to each other.

Connectors, identity, and context

Connectors bring in the raw material: Slack, Jira, GitHub, Outlook, SharePoint, Notion. Calling them API integrations undersells the work. A good connector handles sync jobs, webhooks, rate limits, pagination, deleted documents, and permission changes, and every source behaves differently. Syncing Slack messages is nothing like syncing SharePoint documents.

Identity is where most of the risk sits. An agent cannot safely run on one global service account. If someone asks the support agent a question, it must not pull finance or HR documents just because they happen to be in the index. Access has to be checked when content is indexed, when it is retrieved, and again when an action runs. RFC 9700 makes the same point about tokens: scope them to the resource and the action.

Context is the last piece. People reduce it to embeddings and a vector database, but one answer can need a Slack thread, a Jira ticket, a pull request, and a product spec. Good retrieval is about relevance, freshness, authority, and permission, not just similarity. I go deeper on that in the RAG 101 guide.

Agents need orchestration, not just prompts

This is the layer simple diagrams leave out. Agents do not coordinate by magic. If a product agent drafts a spec, how does the engineering agent know to start? If QA finds a bug, how does the work get back to engineering? If the task takes twenty minutes, where is its state? If something fails, who retries?

Something has to own those answers. It can be a supervisor agent that delegates, or a plain backend with queues, workers, and a state machine. Which one depends on the work.

Choosing an execution shapeA task that finishes in one request uses a synchronous loop. Longer work in one system uses a durable workflow. Work across services or teams uses event-driven coordination.yesnonoyes

Task to automate

Finishes inside one request?

Synchronous agent loop

Spans several services or teams?

Durable workflow

Event-driven coordination

Summarise a document, draft a reply

Investigate an incident, prepare a release

PR-to-QA handoff, support escalation

Choosing an execution shapeA task that finishes in one request uses a synchronous loop. Longer work in one system uses a durable workflow. Work across services or teams uses event-driven coordination.yesnonoyes

Task to automate

Finishes inside one request?

Synchronous agent loop

Spans several services or teams?

Durable workflow

Event-driven coordination

Summarise a document, draft a reply

Investigate an incident, prepare a release

PR-to-QA handoff, support escalation

Choosing an execution shape. Choose by how long the work runs and how many systems it crosses.
  1. Start from the task to automate.
  2. If it finishes inside one request, use a synchronous agent loop.
  3. If it runs longer but stays in one system, use a durable workflow.
  4. If it spans several services or teams, use event-driven coordination.

Whatever the shape, each step has the same division of labour. The agent proposes. Policy decides. A tool does the deterministic part. The orchestrator writes down what happened.

Who owns what in one workflow stepThe orchestrator coordinates an agent, a policy check, a tool call, and a checkpoint for a single step.State storeToolPolicyAgentOrchestratorstep + permission-safecontextproposed typed actionevaluate caller, action, evidenceallow, deny, or require approvalexecute with idempotency key and timeouttyped resultcheckpoint step and result
Who owns what in one workflow stepThe orchestrator coordinates an agent, a policy check, a tool call, and a checkpoint for a single step.State storeToolPolicyAgentOrchestratorstep + permission-safecontextproposed typed actionevaluate caller, action, evidenceallow, deny, or require approvalexecute with idempotency key and timeouttyped resultcheckpoint step and result
Who owns what in one workflow step. The agent proposes. Policy decides, the tool acts, and the orchestrator records it.
  1. The orchestrator gives the agent one step and permission-safe context.
  2. The agent returns a proposed typed action.
  3. The orchestrator asks policy to evaluate the caller, action, and evidence.
  4. Policy answers allow, deny, or require approval.
  5. The orchestrator executes the tool with an idempotency key and timeout.
  6. The tool returns a typed result.
  7. The orchestrator checkpoints the step and its result.

State that survives a restart

Real work takes minutes, hours, or days. Tests run, webhooks arrive, people approve things after lunch, rate limits reset. If all of that lives inside one request or one long conversation, a restart loses it and nobody can audit it afterwards.

A durable agent workflowA request loads a checkpoint, plans the next step, evaluates policy, may pause for approval, executes an idempotent tool call, and saves the result. Bounded retries handle transient errors and escalation handles failures that cannot safely retry.deniedapproval requiredexpired or rejectedapprovedallowedsuccesstransient failureyesnoyesno

Request + workflow ID

Load or create checkpoint

Plan next pending step

Policy decision

Stop or escalate

Checkpoint + await approval

Revalidate identity + policy

Execute typed tool

Tool result

Checkpoint redacted result

Retry budget remains?

More steps?

Complete workflow

A durable agent workflowA request loads a checkpoint, plans the next step, evaluates policy, may pause for approval, executes an idempotent tool call, and saves the result. Bounded retries handle transient errors and escalation handles failures that cannot safely retry.deniedapproval requiredexpired or rejectedapprovedallowedsuccesstransient failureyesnoyesno

Request + workflow ID

Load or create checkpoint

Plan next pending step

Policy decision

Stop or escalate

Checkpoint + await approval

Revalidate identity + policy

Execute typed tool

Tool result

Checkpoint redacted result

Retry budget remains?

More steps?

Complete workflow

A durable workflow can pause and recover. Every wait and every action is a saved state, so the workflow can stop and pick up where it left off.
  1. Receive a request with a stable workflow identifier.
  2. Load an existing checkpoint or create initial workflow state.
  3. Plan or resume the next pending step.
  4. Evaluate the proposed action against identity and policy.
  5. If approval is required, checkpoint the action and pause.
  6. After approval, revalidate authority before continuing.
  7. Execute the tool with an idempotency key and timeout.
  8. Retry transient failures within a bounded policy.
  9. Escalate denied, expired, or repeatedly failing work.
  10. Checkpoint the successful result and continue until complete.

So the workflow saves a checkpoint after every meaningful step and puts a timeout on every wait. It assumes an event can arrive twice, and uses a stable ID so a retry does not send the same email again. A temporary failure gets a limited number of retries. Anything else goes to a person.

Guardrails should follow the risk of the action

A rule written into a prompt is a suggestion. The check that matters is ordinary code that runs after the model proposes something and before any tool is called: is the input well-formed, is this caller allowed, are the preconditions true, does it need approval?

Autonomy follows action riskA typed action passes through a policy gate that considers authority, sensitivity, blast radius, evidence, and reversibility. Reads, drafts, reversible writes, and irreversible actions receive progressively stronger controls.readdraftreversible writeirreversible or high impactnoyesapprovedrejected or expired

Typed action proposal

Evaluate authority, target, evidence, blast radius, and reversibility

Action class

Permission + data-scope check

Schema + output validation

Preconditions + idempotency + risk threshold

Explicit approval or block

Execute governed action

Return proposal for review or use

Approval required?

Human approval

Stop safely

Audit outcome

Autonomy follows action riskA typed action passes through a policy gate that considers authority, sensitivity, blast radius, evidence, and reversibility. Reads, drafts, reversible writes, and irreversible actions receive progressively stronger controls.readdraftreversible writeirreversible or high impactnoyesapprovedrejected or expired

Typed action proposal

Evaluate authority, target, evidence, blast radius, and reversibility

Action class

Permission + data-scope check

Schema + output validation

Preconditions + idempotency + risk threshold

Explicit approval or block

Execute governed action

Return proposal for review or use

Approval required?

Human approval

Stop safely

Audit outcome

Autonomy follows action risk. The same proposal gets a different answer depending on who asks, what it touches, and whether it can be undone.
  1. The agent proposes a typed action but does not execute it directly.
  2. The policy gate evaluates caller authority, target, data sensitivity, blast radius, evidence, and reversibility.
  3. A read action may proceed after permission and data-scope checks.
  4. A draft action may proceed after output validation because it has no external effect.
  5. A reversible write requires stronger validation and may need approval above a risk threshold.
  6. An irreversible or high-impact action requires explicit approval or is blocked.
  7. Every decision and resulting action is recorded in the audit trail.

The same proposal can deserve a different answer depending on who is asking, what it touches, and whether it can be undone. Reading a document is not sending an email, and sending an email is not deleting a repository. OWASP calls the failure mode excessive agency: more functionality, permissions, or autonomy than the task needs.

Keep a person in the loop on purpose

Human review should not be something that only happens after the system has already failed. It belongs in the workflow wherever a decision needs judgment or cannot be undone. Low-risk reads and drafts can go through on their own.

Approval as a workflow stateA proposed action waits for approval and leaves that state by being approved, edited, rejected, or expired.policy requires reviewreviewer approvesreviewer correctsresubmitreviewer rejectsno response in timerevalidate, then run

Awaiting approval

Proposed

Approved

Edited

Rejected

Expired

Executed

Approval as a workflow stateA proposed action waits for approval and leaves that state by being approved, edited, rejected, or expired.policy requires reviewreviewer approvesreviewer correctsresubmitreviewer rejectsno response in timerevalidate, then run

Awaiting approval

Proposed

Approved

Edited

Rejected

Expired

Executed

Approval as a workflow state. Approving is one of four ways out. Editing, rejecting, and expiring need designing too.
  1. An action is proposed.
  2. Policy requires review, so the workflow waits for approval.
  3. A reviewer can approve it.
  4. A reviewer can edit it, which sends it back for approval.
  5. A reviewer can reject it.
  6. If nobody responds in time, it expires.
  7. An approved action is revalidated and executed.

Approving is only one of the ways out of that state. The reviewer needs to see the proposed action and the evidence behind it, and be able to edit it or send it back. One approval covers one action, not everything after it. And when nobody answers, the request has to expire or move to someone else.

If you cannot see it, you cannot trust it

Ordinary monitoring tells you the system is up. For an agent you also need to know whether the work was useful, grounded in real sources, permitted, and finished.

That means one ID that follows a request through every model call, retrieval, tool call, retry, and approval. It means counting outcomes such as completed, corrected, escalated, and abandoned, with cost and latency for each step. And it means testing against real tasks, including hostile ones. Prompts and tool results often contain secrets, so log metadata by default and the content only when you have to.

OpenTelemetry’s semantic conventions give you a shared vocabulary for this. The generative-AI conventions are newer than the rest, so pin the version you build against. For the governance side, the NIST Generative AI Profile is the reference I would start from.

What that looks like in code

The framework matters less than keeping these responsibilities apart. Here is the loop with nothing vendor-specific in it.

def run_workflow(workflow_id: str, request: WorkRequest) -> Result:
    state = state_store.load_or_create(
        workflow_id=workflow_id,
        requested_by=request.principal_id,
        objective=request.objective,
    )

    principal = identity.resolve_and_revalidate(state.requested_by)
    plan = planner.create_or_resume(state, request.context)

    for step in plan.pending_steps():
        action = agent.propose(step=step, context=state.safe_context())
        decision = policy.evaluate(
            principal=principal,
            action=action,
            evidence=state.evidence,
        )

        audit.record(workflow_id, action, decision)

        if decision.requires_approval:
            state.checkpoint(status="awaiting_approval", action=action)
            return approvals.request(workflow_id, action, decision.reason)

        if not decision.allowed:
            return state.finish(status="denied", reason=decision.reason)

        result = tools.execute(
            action,
            principal=principal,
            idempotency_key=f"{workflow_id}:{step.id}",
            timeout=step.timeout,
            retry_policy=step.retry_policy,
        )

        state.checkpoint(
            status="step_completed",
            step=step,
            result=result.redacted(),
        )

    return state.finish(status="completed")

Notice what the model is not in charge of: identity, policy, retries, timeouts, the audit record, and the state. It proposes work inside those boundaries.

Before you ship

The short version, as the questions I would ask in a review.

  1. For every action the agent can take, do we know who it affects and whether it can be undone?
  2. Does every tool have typed inputs and a safe way to be called twice?
  3. Have we tested with several roles, including someone whose access was just revoked?
  4. What happens on a timeout, a duplicate event, or a half-finished tool call?
  5. Can a reviewer see the evidence, edit the proposal, and say no?
  6. Can we trace one request end to end and say what it cost?

The difference between a demo and a production system is rarely the model. It is everything around it.

References

  1. The Real Architecture Behind Production AI Agents

    Abhishek Choudhury. Original article, published May 2026.

  2. RFC 9700: Best Current Practice for OAuth 2.0 Security

    IETF. Current guidance for token security and privilege restriction.

  3. Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile

    National Institute of Standards and Technology. A cross-sector profile for identifying and managing generative-AI risk.

  4. LLM06:2025 Excessive Agency

    OWASP GenAI Security Project. Excessive functionality, permissions, and autonomy in LLM systems.

  5. OpenTelemetry semantic conventions

    OpenTelemetry. A shared vocabulary for tracing, metrics, logs, and events.

  6. Retrieval-Augmented Generation (RAG 101)

    Abhishek Choudhury. The companion guide to permission-aware retrieval and context assembly.