How to Build an Enterprise-Grade AI Agent: From Architecture to Production

    This article explains how to design an enterprise AI agent as an evolvable system, not just a chat UI. It covers capability vs. governance, a unified agent model, independent versioning of config/tools/APIs, layered architecture, identity and aggregates, execution as a state machine, out-of-model security, and a staged path from read-only pilots to controlled writes.

    1. Decide what you are building: a helper, or a system that can evolve?

    A chat page is usually straightforward: take user input, send context to a model, and show the result. The problem changes when the assistant reads internal documents, calls business APIs, or participates in release approval.

    The system must know: who initiated the request? Which materials can they access? Do tool calls need approval? Which configuration version ran this execution? Can failures be traced? After a new entry point is added, do existing permission rules still hold?

    Prompt stacking will not solve these questions.

    Building your own agent therefore needs two layers at once:

    • Capability layer: model reasoning, knowledge retrieval, tool calling, and task orchestration.
    • Governance layer: authentication, authorization, configuration release, execution isolation, audit, and cost accounting.

    Personal assistants can simplify governance. As soon as enterprise data and side-effecting operations are involved, authorization and audit are not optional. An architecture that can grow should let you start small without forcing a rewrite when scope expands.

    2. Use a complete scenario to set system boundaries

    Suppose you are building a production troubleshooting assistant. A user says:

    Last night the order service slowed down. Analyze likely causes and recommend the next checks.

    Completing that task may require:

    1. Identifying the target application, time window, and user identity.
    2. Retrieving runbooks and historical incidents.
    3. Querying metrics and related logs.
    4. Reading database diagnostics within authorized scope.
    5. Correlating sources into an evidence-backed conclusion.
    6. Explicitly marking uncertainty where evidence is weak.
    7. Routing configuration changes into approval instead of executing them directly.

    A real agent is often Q&A, retrieval, and tool use together. It is not a fixed category; it is a set of capabilities organized around a task.

    Architecture should follow this end-to-end path rather than splitting chat, knowledge, orchestration, and tools into disconnected products.

    3. First skeleton: one agent model so capabilities are not remodeled separately

    1. Do not encode capability types as mutually exclusive identities

    If the core entity is locked to exclusive types such as “Q&A,” “knowledge,” or “workflow,” where does a production troubleshooting assistant belong?

    It must retrieve documents, query live data, and possibly trigger approval. Forcing a single type leads to cross-type references, duplicated config, and special-case branches.

    A more stable approach: keep a unified agent identity and compose capabilities.

    An illustrative configuration:

    1. Agent config:
    2. identity: stable agent identifier
    3. goal: analyze production incidents and recommend actions
    4. model policy: inference parameters and fallbacks
    5. knowledge refs: runbooks, historical incidents
    6. tool refs: metrics query, log search
    7. execution policy: timeouts, step budget, failure handling
    8. security policy: read-only first, approval for sensitive ops
    9. output constraints: conclusion, evidence, risk, recommendations

    This is domain modeling, not a product API.

    Model policy, knowledge refs, and tool refs should point at independent configs rather than stuffing everything into the agent’s main record. A unified model means consistent identity and release rules, not unbounded tables.

    2. Entry points only adapt; they do not redefine the business

    The same troubleshooting agent may be called from a web UI, an embedded panel, an open API, and a local development environment.

    The entry layer handles:

    • authentication and identity propagation;
    • context such as current page, application, and ticket;
    • request/response formatting;
    • streaming, cancellation, and reconnect.

    The agent core handles:

    • whether context is trustworthy;
    • whether the request is authorized;
    • which knowledge to retrieve;
    • which tools may run;
    • whether output meets safety constraints.

    Client-supplied application names, tenant IDs, and permission claims must not be treated as authorization. They are unverified request context. Final authorization comes from server-side trusted identity and resource policy.

    New channels then add adapters, not a second agent stack.

    4. Second skeleton: three version tracks that evolve separately

    A “version number” without clear semantics is false safety. Agent config updates, tool contract changes, and access-interface upgrades are different kinds of change and should be managed separately.

    1. Agent configuration versions

    A config version is the behavior definition for a release: prompts, knowledge refs, tool bindings, model policy, and execution limits.

    Suggested rules:

    • Drafts are editable; published versions are immutable in place.
    • Each run is pinned to one config version.
    • Canary releases affect new runs only, not in-flight tasks.
    • Rollback switches a publish pointer; it does not overwrite history.

    If knowledge keeps changing, recording only a “knowledge base name” is not enough to reproduce issues. Record index revision IDs where needed, or at least the document versions and evidence snippets that were retrieved.

    Model generation still may not be bit-for-bit reproducible. The goal of tracing is to reconstruct key inputs and decision basis, not to promise fully deterministic output.

    2. Tool contract versions

    A tool contract defines inputs, outputs, error semantics, and side effects.

    Adding an optional query field is usually easier to keep compatible than removing a required field. Changing a “query-only” tool into “query and mutate” is a security-semantics change, not just a schema change.

    Tool upgrades should check:

    • parameter compatibility;
    • whether return meaning changed;
    • timeouts and error codes;
    • whether permission requirements increased;
    • whether write or delete behavior was added.

    In-flight tasks should keep using the pinned tool contract. If the backend cannot serve old versions, define a compatibility window and migration plan; a version field alone is not enough.

    3. Access contract versions

    Open APIs, client SDKs, and event formats also need independent evolution.

    Adding a field to a user-feedback event should not force every agent to republish. Changing an agent prompt should not force every client to upgrade.

    The three tracks link through a release manifest:

    1. Release manifest:
    2. agent config version
    3. bound tools and contract versions
    4. compatible access-contract range
    5. key resource revision IDs

    Independent evolution does not mean no coupling. It means explicit links so unrelated changes do not drag each other.

    5. Third skeleton: six responsibility layers and one-way dependencies

    Split the system into six layers:

    1. Domain: agents, run state, release rules, core constraints.
    2. Application: use cases such as publish, create run, cancel.
    3. Execution: step scheduling, tool coordination, budgets and timeouts.
    4. Port contracts: abstract interfaces for models, retrieval, storage, and tools.
    5. Infrastructure adapters: databases, queues, and external services.
    6. Entry: web APIs, open APIs, and other adapters.

    These layers need not form a rigid call chain. What matters is that dependencies point toward stable core rules; the core does not depend on concrete infrastructure.

    The domain layer should not import web frameworks, database drivers, or specific model clients. Execution talks to models and tools through ports; adapters implement I/O.

    Enforce boundaries with compile-time and CI checks

    Architecture docs will not stop an accidental import. Add gates:

    • core modules must not depend on entry frameworks;
    • domain modules must not access the database directly;
    • entry modules must not mutate execution state outside application use cases;
    • no cyclic dependencies;
    • shared client packages must not pull server frameworks.

    “Zero framework” should mean core contracts or thin clients are not bound to a particular framework—not that the whole system uses none.

    Separate control plane and execution plane

    The control plane manages config, permissions, release, and audit queries. The execution plane handles inference, retrieval, and tool calls.

    Execution is exposed to long tasks, blocked external APIs, and high concurrency. In enterprise deployments, separate processes help scale and isolate faults.

    Process split is only a start. If both share a connection pool that cannot isolate exhaustion, or execution nodes must read the admin backend live to finish a task, failures still propagate.

    Runs should carry immutable config references plus explicit resource quotas and permission validity windows.

    6. Fourth skeleton: five identities and two aggregate roots

    1. Five identifiers solve different problems

    On the core path:

    • Tenant ID: data and resource isolation.
    • Agent ID: capability identity.
    • Session ID: continuous interaction.
    • Run ID: one task execution.
    • Step ID: a model call, retrieval, or tool op inside a run.

    One session can spawn many runs; one run can contain many steps. Retries need a separate attempt sequence so multiple calls are not treated as one operation.

    These IDs correlate; they do not authorize. Guessing or obtaining a run ID does not grant access.

    Logs, events, metering, and audit records should share correlation fields so you can answer:

    Which user, through which entry, using which version, called which tools, and why was this the result?

    2. Definition and run as two aggregates

    Agent definition aggregate

    Owns agent identity, config versions, publish state, and bindings so release consistency holds.

    Run aggregate

    Owns one execution’s lifecycle, step summaries, budget, and terminal reason so state transitions stay consistent.

    An aggregate root does not mean one table or loading huge step logs into one object. Long conversations, raw logs, and large tool results can live separately and be referenced.

    Separate evolution keeps run-log writes from slowing config publish, and keeps config edits from rewriting the meaning of historical runs.

    7. Make execution a controlled state machine

    Agent execution should not be an unbounded model loop. It needs explicit states:

    1. created → queued → running
    2. running → awaiting approval → running
    3. running → succeeded / failed / canceled / timed out

    States can be simplified for the business; transition conditions must be clear.

    Cap execution budgets

    Each run should at least limit:

    • total wall time;
    • max steps;
    • max tool calls;
    • input/output size;
    • parallelism;
    • allowed resource scope.

    When the budget is exhausted, return confirmed facts and unfinished work—do not wrap partial results as a complete conclusion.

    Distinguish retries from duplicate side effects

    A network timeout does not mean the tool never ran. Blind retries on ticket creation or config mutation can duplicate side effects.

    Set retry policy by tool semantics:

    • Safe-to-repeat read-only ops may retry with limits.
    • Writes should prefer idempotency keys or status checks.
    • If the outcome cannot be confirmed, go to human verification rather than assuming failure.
    • Canceling a run usually only blocks later steps; it does not automatically undo completed external actions.

    These rules belong in the execution system, not only in prompts.

    8. Keep the security boundary outside the model

    Retrieved documents, logs, and tool returns can contain misleading instructions. Text the model sees must not automatically grant control-plane rights.

    Before actual execution, the server should re-check:

    1. whether the current user may call this tool;
    2. whether parameters fall in allowed resource scope;
    3. whether they contain sensitive data or out-of-scope targets;
    4. whether the operation needs approval;
    5. whether the run is still valid.

    For high-risk ops, use “model proposes a plan → user confirms → server validates → tool executes.” Approvals should bind to a specific tool, parameters, and target resources; changed parameters must not reuse an old approval.

    Also separate the assistant’s service identity from the end-user identity. A broadly privileged service account must not implicitly grant every user the same power.

    9. Start from a minimal closed loop and accept incrementally

    Phase 1: prove a read-only scenario

    Pick a well-scoped business question, a small knowledge set, and read-only tools. Complete authentication, evidence citation, run records, and budgets.

    Do not chase multi-agent collaboration yet. Introduce it only when the task truly needs distinct duties, independent permissions, or parallelism.

    Phase 2: prove consistency across entry points

    Call the same agent from web and open API. Check that authorization, config versions, audit fields, and error semantics match.

    The point is not UI polish; it is whether a new entry bypasses existing governance.

    Phase 3: complete release and failure recovery

    Build an evaluation set covering normal questions, weak evidence, tool timeouts, insufficient permission, and malicious input.

    Canaries should compare not only answer quality but tool success rate, latency, budget use, approval behavior, and unauthorized-access blocks. Thresholds must come from the real business, not unvalidated numbers.

    Phase 4: introduce controlled writes

    After the read-only path is stable, add writes, human approval, and compensation. Drill duplicate requests, mid-run cancel, and permission revocation.

    10. What you reuse is boundaries, not feature count

    The easiest part of building an agent is a chat entry. The hard part is keeping growing business capabilities consistent.

    A unified domain model solves capability composition. Independent version tracks solve change coupling. Module dependency boundaries solve code evolution. Identity and aggregates solve state tracing. Execution state machines, permission checks, and approval put those designs on every real operation.

    A simple health check: when you add an entry, knowledge source, or tool, can you do it mainly with adapters and published config—without cloning the permission system, rebuilding audit, or rewriting core logic?

    Stabilize those boundaries first, then grow intelligence, so a demo assistant can become a trustworthy, maintainable, continuously deliverable system.