AI Agent Platform Architecture: Four Hard Boundaries to Prevent Spaghetti Systems

    This article explains four architectural boundaries that keep an enterprise AI agent platform from becoming unmanageable as requirements expand: a single agent domain model based on capability assembly rather than form-based tables, three independent version tracks for configuration, assets, and flows, six one-way dependency layers enforced at compile time, and a five-level state ID hierarchy backed by a dual aggregate root data foundation. It also outlines a recommended implementation order and an acceptance checklist covering schema changes, independent rollback, compile-time dependency enforcement, and per-instance cost reconciliation.

    Introduction: Why Agent Platforms Get Messier Over Time

    Over the past year, AI agents have moved from demos into production, and their scope keeps expanding. They are no longer passive chat windows; they can retrieve internal documents, call controlled tools, break down multi-step tasks, and run automatically inside development and operations workflows. General-purpose capabilities from cloud providers such as Baidu AI Cloud (model services, object storage, message queues, container platforms, logging, and monitoring/alerting) supply the infrastructure for these systems. But infrastructure cannot answer a more fundamental question for an enterprise: how should the platform’s own static skeleton be structured?

    Inside a company, an agent platform almost inevitably goes through scope creep. In week one, a business team wants nothing more than a web chat box that can look up policy documents. By week three, the monitoring and ticketing teams want the entry point embedded in alert pages, automatically carrying the application name, cluster identifier, and ticket context. In week five, the release pipeline team wants to call the agent at change gates through an open API or a lightweight SDK to run risk assessments. By week seven, frontline developers push back on being forced out of their local development environment and ask to reuse internal controlled tools and code repositories directly inside their AI coding tools.

    If you take on each request by reflex and split them into four separate product lines, then create four or five disconnected entity tables in the admin console named after whatever concept is trending (“Q&A agent,” “retrieval agent,” “orchestration agent,” “tool service”), four types of incidents will surface within three months: the permission system fractures into three, gray release rules diverge, a single tool parameter change has to be replicated in four places, and token costs cannot be reconciled at month end. What actually determines whether a system can grow thick without growing chaotic is not a runtime trick but the domain modeling, version separation, module dependencies, and state data partitioning decided on day one. The four hard boundaries below address exactly these problems.

    Hard Boundary 1: One Agent Domain Model, No Tables by Form

    The most common mistake is adding a type enum to the first core table: agent_type = CHAT | RAG | WORKFLOW | MULTI_AGENT. It looks clean in a prototype, but it hits a wall within two weeks of real business use, because an enterprise assistant is inherently a composite: the same agent must answer policy questions from a knowledge base, trigger ticket creation after answering, and dispatch subtasks for complex questions.

    The right abstraction is to strip “form” out of the entity definition and treat it as capability assembly. The agent entity keeps only the stable core: identity, lifecycle, permission ownership, references to model and prompt configuration, and bindings to tools and knowledge sources. Q&A, retrieval, orchestration, and tool calling all appear as combinations of capabilities, not as different tables.

    1. # Illustration: capability assembly instead of type-based tables
    2. class Agent:
    3. id: str
    4. name: str
    5. owner: str
    6. lifecycle: str # DRAFT / GRAY / GA / OFFLINE
    7. capabilities: list[str] # ["qa", "retrieval", "tool_call", "orchestrate"]
    8. model_ref: str
    9. knowledge_refs: list[str]
    10. tool_refs: list[str]

    This eliminates four kinds of duplicate delivery: permissions need only one subject-resource model; gray release applies only to agent instances; tool parameters have a single definition; and cost accounting can be unified at the instance level. The test is simple: when you add a new interaction form, if no schema change and no new permission module are required, the abstraction holds.

    Hard Boundary 2: Three Non-Interfering Version Tracks

    An agent carries three kinds of change at once: prompt and model configuration, knowledge and tool bindings, and orchestration and flow logic. Their release cadences are completely different: prompts may change daily, knowledge weekly, and flows monthly after review. Sharing one version line means any small change triggers a full regression.

    Set up three tracks: a config track (prompts, model parameters), an asset track (knowledge chunks, tool registrations), and a flow track (orchestration steps and branches). Each track has its own independent version number, and an assembly manifest combines them into an executable instance at runtime. Gray release progresses at the instance level and can be targeted by user group, tenant, or entry source.

    1. # Illustration: assembly manifest
    2. agent_instance: refund_assistant
    3. config_version: cfg-2024-06-11
    4. asset_version: asset-2024-06-09
    5. flow_version: flow-1.3.0
    6. gray:
    7. strategy: tenant
    8. allow: ["tenant-a", "tenant-b"]

    The key engineering constraint is “rollback to any combination”: version numbers across the three tracks must be traceable and replayable, so when something goes wrong you can pinpoint whether the deviation came from configuration, assets, or flow, instead of vaguely rolling back the entire agent.

    Hard Boundary 3: Six One-Way Dependency Layers and a Zero-Framework Compile Gate

    Module decay usually starts with circular dependencies: the orchestration layer reads the persistence layer directly, and the tool layer calls the UI layer in reverse. To weld the boundaries in place architecturally, divide the system into six layers: API layer, orchestration layer, capability layer (Q&A/retrieval/tools), domain layer, state layer, and infrastructure layer, with dependencies pointing downward only.

    The gate should move to compile time rather than relying on documentation. For dependency rule validation, for example:

    1. # Illustration: compile-time dependency gate (pseudo-command)
    2. arch-lint --layers api,orchestrate,capability,domain,state,infra \
    3. --rule "deps_must_point_downward" \
    4. --fail-on-violation

    Also insist on zero framework intrusion: expose only common protocols and open APIs externally, so integrating business systems are not locked into a proprietary SDK. This way, pipeline gates, alert pages, and local development tools can all integrate in a uniform way instead of each maintaining a private client.

    Hard Boundary 4: Five-Level Core State IDs and a Dual Aggregate Root Data Foundation

    State confusion is the root cause of failed cost reconciliation. Define five levels of IDs: tenant, user, agent instance, session, and execution (a single task or subtask). All invocations, retrievals, tool executions, and token consumption hang under these five levels, so billing and auditing are naturally aggregatable.

    The data foundation uses dual aggregate roots: one aggregate root manages “definition” (agents, capabilities, version assembly), and the other manages “runtime” (sessions, executions, tool call records). The two are loosely linked by instance ID, which prevents high-frequency runtime writes from polluting definition data and prevents definition changes from breaking the traceability of historical execution records.

    1. tenant -> user -> agent_instance -> session -> execution
    2. | |
    3. definition_root runtime_root

    Implementation Order and Acceptance Checklist

    Proceed in four steps: first establish the single domain model and the five-level IDs, then split the three version tracks and the assembly manifest, then lock down the six-layer dependencies and the compile gate, and finally connect the common infrastructure (model services, object storage, message queues, logging, and monitoring). At acceptance time, answer four questions: does adding a new form require zero schema changes; can the three tracks roll back independently; can dependency violations be intercepted at compile time; and can monthly costs be reconciled precisely by instance and tenant. If the answer to all four is yes, the platform has a skeleton that can grow thick without growing chaotic.