How to Build an Evolvable AI Agent Platform

    This article explains how to design an AI agent platform that can evolve without structural collapse. It covers a single agent domain model that supports four delivery forms, three independent version tracks, six-layer one-way dependencies enforced by compile gates, and a five-level state identity model backed by dual aggregate roots. It also shares practical details on explicit context injection and contract-first tool governance.

    How to Build an Evolvable AI Agent Platform

    Introduction: Agent platforms usually fail at the first table

    Over the past year, AI agents have moved from demos into production. They are no longer just a Q&A window; they can retrieve information, call tools, break down tasks, and connect automation workflows as execution units. But when enterprises actually start building their own platforms, the most common outcome is not “not enough features” but “structural collapse.”

    A typical pattern of scope creep is something almost every team goes through:

    • Week 1: The business side only wants an internal web Q&A entry that can look up policy documents and search logs.
    • Week 3: The monitoring, alerting, and ticketing teams ask for an embedded floating entry that automatically carries the current page’s application name, cluster identifier, and ticket context when opened.
    • Week 5: R&D and release teams ask for an open interface or SDK with zero framework intrusion, so they can call the agent for risk assessment at release checkpoints.
    • Week 7: Frontline developers ask to reuse the platform’s controlled toolchains and code repository capabilities directly without leaving their local coding tools.

    If you follow inertia and split these four types of demands into four independent product lines, then pile up mutually disconnected entities such as “Q&A agents,” “retrieval agents,” “orchestration agents,” and “tool services” in the admin console, within three months you will inevitably see: a forked permission model, gray-release rules operating in silos, tool parameters that must be synchronized in four places after one change, and token costs at month-end that cannot be reconciled.

    This article does not list features. Instead, it unpacks the four hard boundaries of the static skeleton—a single agent domain model, three version tracks, six-layer one-way dependencies with compile gates, and five-level core state identities with a dual-aggregate-root data foundation—along with the pitfalls behind them, the trade-off logic, and the engineering solutions.

    1. Do not classify by “form”: how one entity supports four deliveries

    When many teams design the core main table, their first reaction is to add a type enum: agent_type = CHAT | RAG | WORKFLOW | MULTI_AGENT. This looks clean in the prototype stage, but it hits a wall within two weeks in real business: an enterprise assistant is inherently a composite. The same agent is Q&A in a web page, diagnostic orchestration in alerting, a risk-assessment service called in a pipeline, and a reusable toolset in a local tool.

    The root problem is mistaking “delivery form” for “domain identity.” Form is a projection, not an entity.

    The recommended approach is to define the agent as a stable entity and express forms through “capability switches + runtime assembly”:

    1. -- Example: stable entity + capability bits, not a type enum
    2. CREATE TABLE agent (
    3. agent_id BIGINT PRIMARY KEY,
    4. name VARCHAR(128) NOT NULL,
    5. model_profile JSON NOT NULL, -- Model and inference parameter profile
    6. capability JSON NOT NULL, -- retrieval/tool/plan/memory switches
    7. policy_ref BIGINT NOT NULL, -- Permission and data boundary reference
    8. state_id VARCHAR(64) NOT NULL -- Five-level state identity, see section 4
    9. );

    The four forms are just different assembly results of the same entity: the web form assembles sessions and retrieval; the alerting form assembles context injection and diagnostic orchestration; the interface form assembles stateless calls and quotas; the local-tool form assembles a controlled toolset and repository retrieval. The benefits are that permissions are maintained in only one set, gray release goes through only one channel, tool parameters are stored in only one copy, and costs can be aggregated uniformly by agent_id.

    2. Three version tracks: stop changes from stepping on each other

    After the single entity, the second pitfall is “all changes crammed onto one release line.” Prompts, tool contracts, and orchestration logic change at completely different frequencies; mixing them together will inevitably cause mutual blocking.

    It is recommended to split them into three non-interfering tracks:

    1. Content track: prompts, knowledge base indexes, and retrieval strategies. Changes are frequent and require minute-level activation, rollback, and A/B testing.
    2. Contract track: tool input/output schemas, permission declarations, and quotas. Changes require review, follow backward compatibility, and adopt an “add optional fields + version number” strategy.
    3. Runtime track: orchestration algorithms, concurrency and timeout policies, and runtime images. Changes are the slowest and go through normal gray releases.

    Each track has its own independent version number, and the runtime is assembled by a “track version triple.” Example:

    1. {
    2. "agent_id": 10086,
    3. "tracks": { "content": "c-37", "contract": "v2", "runtime": "r-12" },
    4. "rollout": { "bucket": "gray-5pct", "rule": "by_tenant_id" }
    5. }

    The key constraint is: the content track is not allowed to modify contracts, and the contract track is not allowed to implicitly change execution semantics. Once a boundary is crossed, rollback becomes a disaster.

    3. Six-layer one-way dependencies and zero-framework compile gates

    The third pitfall is dependency rot: the tool layer depends backward on the orchestration layer, and the orchestration layer directly assembles storage drivers, so in the end any change pulls the whole system.

    It is recommended to establish six-layer one-way dependencies (upper layers depend on lower layers; reverse dependencies are forbidden):

    1. Access layer: web, alert callbacks, open interfaces, and local tool protocol adapters;
    2. Session layer: context organization, multi-turn state, truncation, and summarization;
    3. Orchestration layer: task decomposition, plan execution, and failure retries;
    4. Capability layer: retrieval, tool calls, and memory read/write;
    5. Domain layer: agents, tool contracts, policies, and cost aggregation;
    6. Infrastructure layer: storage, message queues, logs, monitoring, and key management.

    The way to enforce this is a “compile gate” rather than a verbal agreement: add dependency checks in continuous integration, and fail immediately on reverse references or cross-layer direct connections.

    1. # Example: static validation of dependency direction (pseudo-command)
    2. depcheck --layers 6 --allow "api>session>plan>cap>domain>infra" --fail-on-reverse

    At the same time, stick to zero framework intrusion: expose only general protocol-style interfaces and lightweight clients externally, so business systems do not need to import platform-specific base classes. This way, release checkpoints, alerting systems, and local coding tools can all integrate at minimal cost.

    4. Five-level state identities and a dual-aggregate-root data foundation

    The fourth pitfall is failing to separate state from the data backbone: sessions, tasks, tool calls, costs, and audits mixed in one wide table make both queries and settlement slow.

    It is recommended to introduce five-level core state identities to form a traceable chain:

    tenant → agent → session → task → tool_call

    Each level holds only its own state machine and lifecycle; upper levels aggregate lower levels through identities, and cross-level writes are forbidden. The data foundation uses dual aggregate roots:

    • Configuration aggregate root: agent definitions, capability switches, contract versions, and policy references, emphasizing consistency and auditability;
    • Runtime aggregate root: sessions, tasks, call records, and token and latency metering, emphasizing high throughput and partitionability.

    The two types of aggregate roots are linked by identities with separate reads and writes. Cost reconciliation is summarized at two levels, tool_call and task, and can naturally trace back to agent_id and the tenant, avoiding an “unaccountable” month-end.

    5. Two practical details: context injection and tool governance

    Context injection should be “explicitly contracted.” In alerting scenarios, carry the application name, cluster identifier, and ticket number; do not rely on page scraping, but have the access layer inject them according to declared fields, and reject when fields are missing, to avoid dirty context causing misjudgment.

    Tool governance should be “contract first + least privilege.” Each tool declares its input schema, timeout, idempotency, required permissions, and quota; validate parameters and make policy decisions before the call, and write an audit record after the call. Example:

    1. {
    2. "tool": "log_query",
    3. "input_schema": { "app": "string", "cluster": "string", "range": "string" },
    4. "timeout_ms": 3000,
    5. "idempotent": true,
    6. "scopes": ["log:read"],
    7. "quota": { "qps": 20 }
    8. }

    Conclusion: Build it thick, not messy

    The long-term value of an agent platform does not depend on some clever trick, but on the static skeleton from day one. A single domain model eliminates entity duplication, three version tracks isolate change rhythms, six-layer one-way dependencies with compile gates prevent rot, and five-level state identities with dual aggregate roots make tracing and settlement clear. Baidu AI Cloud also emphasizes this “boundaries first” engineering view in its related platform practices. Get the skeleton right first, and afterward, whether you integrate web, alerting, pipelines, or local coding tools, it is just assembly, not a rewrite.