# How to Build Your Own AI Agent Platform: A Zero-to-One Architecture Guide
This guide walks through four foundational architecture decisions for building an enterprise-grade AI agent platform: a single unified agent domain model, three decoupled version tracks for configuration, prompts, and knowledge, six-layer one-way dependencies enforced at compile time, and a five-tier state ID system with dual aggregate roots. Learn how to avoid the pitfalls that cause most agent platforms to spiral out of control within three months.
Why Do Most Agent Platforms Spiral Out of Control Within Three Months?
Building a working AI agent prototype isn’t hard. Combine a large model API, a prompt, and a simple chat interface, and you can have something running over a weekend. What’s genuinely hard is keeping the architecture clean, well-bounded, and extensible as the agent evolves within an enterprise over six months, a year, and beyond.
Any engineer who has maintained an enterprise platform for over a year knows this: what determines whether a system grows sturdier or turns into a mud pit is rarely a clever runtime trick. It’s the “static skeleton” you establish on day one—how domain entities are modeled, how version evolution is split into tracks, how module boundaries are enforced in code, and how runtime state is separated from configuration data.
Enterprise AI platforms almost always go through the same suffocating pattern of “requirement creep”:
- Week 1: The business team just wants an internal web chat window for querying policy documents and logs;
- Week 3: The monitoring and ticketing team shows up—can you embed a floating widget in the legacy system that automatically carries the app name, cluster ID, and ticket context from the current error page?
- Week 5: The release pipeline team makes a request—can you provide a zero-framework-intrusion SDK or open API so we can call the agent for risk assessment directly in change release gates?
- Week 7: Frontline developers ask: I spend most of my day in a local IDE writing code and debugging—can I connect to this agent directly from my local dev tools and reuse the company’s controlled ops tools and code repositories?
If you instinctively accept all four requests and spin them into four independent product lines—then, chasing trendy buzzwords, create four or five disconnected entity types in the admin backend (“Q&A Agent,” “Knowledge Base RAG Agent,” “Multi-Agent Orchestration Agent,” “MCP Tool Service”)—within three months you’ll find your permission system has fractured into three versions, your canary release rules are all over the place, changing a tool parameter requires syncing four codebases, and nobody can reconcile the monthly token cost report.
To avoid this fate, four hard boundaries must be established in the static skeleton:
- A single agent domain model—no inventing entities based on delivery form;
- Three non-interfering version tracks—configuration, prompts, and knowledge evolve independently;
- Six-layer one-way dependencies with a zero-framework compile gate—module boundaries welded shut at compile time;
- Five-tier core state IDs with dual aggregate roots—runtime state and configuration state physically separated.
Let’s break down the failure scenarios, architectural trade-offs, and reusable engineering solutions behind each of these four pillars.
Reject “Knowledge-Type Agents”: One Entity, Four Delivery Forms, Zero Duplication
Many teams, when designing the core table for an agent platform, immediately add a type enum field:
agent_type VARCHAR(32) NOT NULL -- CHAT | RAG | WORKFLOW | MULTI_AGENT
This categorization looks clean in a prototype. But two weeks into real business use, you hit a dead end: real enterprise assistants are inherently cross-type composites.
Take a common “production troubleshooting assistant.” When an employee asks “Why did the order service stutter last night?”, the agent needs to:
- First retrieve incident playbooks from the ops knowledge base (RAG capability);
- Then call internal APIs on the logging and monitoring platforms to pull exception stack traces (tool calling via the MCP protocol);
- If slow SQL is involved, connect to the database diagnostic service for execution plans (another tool call);
- Finally synthesize multi-step findings into remediation recommendations (workflow orchestration).
So what type do you assign? Mark it RAG and you lose tool calling. Mark it WORKFLOW and you lose knowledge retrieval. If you build a table per form, the same assistant must be stored in four tables, and permissions, canary rules, and billing all fragment.
The correct approach: an agent is one entity, and its form is merely a “distribution channel.”
The domain model of an agent should look roughly like this:
Agent (single aggregate root)├── Identity & permissions: agent_id, owner, visibility scope├── Capability assembly: model, prompts, knowledge base attachments, tool attachments├── Runtime policies: orchestration mode, context window strategy, fallback strategy└── Distribution channels: web widget / open API / SDK / IDE plugin (one-to-many)
The key insight: form is not an attribute of an agent—it’s an output port of the agent. The same agent entity can be published to a web chat window, a legacy system floating widget, an open API, and a local IDE plugin, and all four channels share the same permission system, the same canary rules, and the same cost ledger. The “four product lines” mentioned earlier are actually “one entity, four channels”—which eliminates the duplicated modeling problem at its root.
The underlying domain-driven design principle: model according to business essence, not delivery form. Delivery forms keep expanding as channels innovate; business essence remains relatively stable.
Three Version Tracks: Why Configuration, Prompts, and Knowledge Must Evolve Independently
Once you have a single entity, the second pitfall appears immediately: how do you manage versions?
Many teams package the agent as a single “monolithic configuration” and release it as a whole—change one word in a prompt or update one document in the knowledge base, and you have to release a complete new version. The result: the knowledge base needs dozens of playbook updates per day while prompts are tuned once a week. Tied together, either knowledge updates get slowed by the release process, or frequent releases for knowledge push unvalidated prompts into production.
The solution is to split contents with different evolution tempos into three non-interfering tracks:
| Track | Contents | Evolution Tempo | Release Strategy |
|---|---|---|---|
| Configuration track | Model parameters, orchestration policies, tool bindings | Weekly | Strict approval + full regression testing |
| Prompt track | System prompts, few-shot examples | Daily | A/B evaluation |
| Knowledge track | Knowledge base documents, index versions | Hourly | Incremental updates + quality sampling |
Each track has its own version number and rollback capability. When a runtime request comes in, the runtime locks a snapshot based on the triple of “configuration version + prompt version + knowledge version” and writes this triple in full into the session record. This delivers two critical benefits:
- Reproducible issues: When a bad answer surfaces in production, you can precisely reconstruct the combined state of all three tracks and bisect the problem—was it a prompt regression, knowledge contamination, or a configuration error?
- Canary-able changes: A new prompt version can be rolled out to just 5% of traffic, compared against the old version using an automated evaluation suite, then fully released once it passes.
Without this triple snapshot, debugging production issues is like debugging in a codebase without version control—you never know what was actually running.
Six-Layer One-Way Dependencies and the Zero-Framework Compile Gate: Welding Boundaries Shut at Compile Time
The most vulnerable part of an agent platform is module boundaries. Today, in the rush to ship, the execution layer directly imports an internal class from the control plane; tomorrow, someone stuffs a web framework annotation into the domain model. Six months later, no layer dares to change, because everything is entangled with everything else.
Our solution is two gates:
Gate one: six-layer one-way dependencies. The codebase is split into six modules with strictly one-way dependencies:
API layer → Application orchestration layer → Domain model layer → Domain service layer → Infrastructure layer → Storage & external adapter layer
Upper layers may call lower layers; lower layers must never be aware of upper layers; cross-layer calls are prohibited outright. The domain model layer sits at the core of the dependency chain and depends on no specific framework—which is exactly why the second gate exists.
Gate two: the zero-framework compile gate. The build script for the domain model layer explicitly declares: no compile-time dependencies on any web framework, ORM framework, or RPC framework are allowed. A check is added to the CI pipeline: if anyone introduces a framework dependency in the domain layer, the build fails immediately. An illustrative rule:
// Dependency whitelist for the domain module: only the standard library and a few pure utility librariesdependencies {allowed('java.*')disallowed('*-spring-*', '*-mybatis-*', '*-dubbo-*') // build fails on match}
The value of this gate: frameworks become obsolete; the domain does not. The web framework you use today may be replaced three years from now. If the domain model has been polluted with framework annotations, migration costs rise exponentially. But if the domain layer stays clean, swapping frameworks is merely mechanical work of replacing outer adapters. Moreover, for the upper-layer SDK to be truly “zero-framework-intrusion” for business teams, the domain layer itself must carry no framework DNA—otherwise, importing the SDK forces business teams to accept a whole chain of transitive dependencies, which is unacceptable in a codebase shared across multiple teams.
Five-Tier State IDs and Dual Aggregate Roots: Physically Separating Runtime State from Configuration State
The final pillar is the data layer. Agent platform data has a distinctive characteristic: the access frequency of configuration data and runtime data differs by three to four orders of magnitude.
- Configuration state: agent definitions, prompts, knowledge attachments—a few thousand records in total, updated infrequently, but every read demands strong consistency;
- Runtime state: sessions, messages, tool call records, token metering—tens of millions of writes per day, queried by session aggregation, tolerant of eventual consistency.
If you model both in the same database and the same tables, the massive runtime writes will drag down configuration read latency, and lock contention on configuration tables will in turn block runtime writes.
Our partitioning scheme uses dual aggregate roots:
- AgentDefinition aggregate root (configuration database): holds all static definitions of an agent—small and expensive, with read/write separation and strong consistency;
- Session aggregate root (runtime database): holds all runtime data—large and fast, sharded by time, archivable to cold storage.
Within the runtime state, five tiers of IDs link everything into a fully observable chain:
agent_id (which agent)└── session_id (which session)└── turn_id (which turn of the conversation)└── step_id (which execution step: retrieval / tool call / inference)└── span_id (which underlying call: model request / HTTP call)
With all five ID tiers propagated end-to-end, three things become possible simultaneously:
- Debugging: A bad answer can be traced upward from the span layer, pinpointing the exact parameters and outputs of a specific tool call;
- Billing: Token consumption is metered at the span level and aggregated at the agent level, so the cost ledger reconciles naturally;
- Auditing: Every tool call can answer “who, under what permissions, called what, and what was returned.”
Final Thoughts: Skeleton First—Build Thick, Not Messy
Reviewing the four pillars: the single domain model eliminates entity fragmentation; the three version tracks eliminate evolution that drags each other down; the six-layer dependencies and compile gate eliminate boundary erosion; the five-tier state IDs and dual aggregate roots eliminate hot and cold data trampling each other.
They share one trait—they are all day-one decisions, not runtime patches. An agent’s model capabilities will iterate month by month, and delivery channels will expand week by week. But as long as the four pillars of the static skeleton are in place, every layer of growth on top of the platform is accumulation, not refactoring.
For teams preparing to build their own agent platform, the recommended sequence is: first use a real composite scenario (such as a troubleshooting assistant) to validate whether the single entity model covers all forms; then build out the snapshot mechanism for the three version tracks; next add the dependency gate to your CI pipeline; and finally complete the physical separation of hot and cold data. The earlier the skeleton is set, the shallower the pits you’ll fall into later.
