AI Agent Architecture for Building Complex Systems: From Natural Language to Strong Constraints

    This article explains why large AI Agents drift off course when building complex systems, and how architecture-first practices fix the problem. It covers freezing requirements into structured contracts, splitting work into small-context task packages, running agents in a self-checking loop, externalizing memory into repository files, validating multi-source data, and delivering visualizations incrementally. The takeaway: success depends less on model capability and more on constraint design.

    1. The Problem: Why Bigger Goals Make AI Drift

    Using an AI Agent that can run autonomously to build an economic monitoring system—covering multi-source data collection, metric computation, and visualization—is a solid stress test. These systems share a few defining traits: many metric dimensions (hundreds), broad market coverage (equities, bonds, commodities, gold, and more), three to five years of daily series for each metric, and heterogeneous sources with inconsistent definitions. The resulting data volume far exceeds what a mainstream large model can hold in a single context window.

    The core conflict here is not that the model is not smart enough. It is that the solution space is too large. When the requirement is a single sentence of natural language, the number of implementations that satisfy it is nearly infinite. Every generation lands somewhere different in that space, which produces “locally correct, globally off-track” results: inconsistent field naming, two calculation logics for similar metrics, and page components whose assumptions do not match the data interfaces. Using prompts alone to constrain a solution space this large is essentially formal constraint-writing in natural language, and the success rate is low.

    A more practical conclusion follows: AI today is not enough for someone with no programming experience to independently deliver complex software, and less experienced developers can lose control just as easily. The gap is not “can you write code” but can you design constraints for the system.

    2. Architecture First: Compressing Natural Language into Strong Constraints

    For an Agent to produce stable output, requirements must be settled into unambiguous structured contracts before the first line of code is generated. Freeze at least these six categories:

    1. Data model: table/collection boundaries, field naming conventions, primary keys and indexes, and time alignment (unified time zone, unified trading calendar, missing-value semantics).
    2. Mappings: mapping tables from raw source fields to standard fields, plus consistent conventions for units, adjustment methods, and percentages versus decimals.
    3. Interface contracts: input and output structures for every data access and metric computation entry point—define the contract before the implementation.
    4. Components and page structure: page sections, component responsibilities, components fetching data only through contracts, and no business logic in the view layer.
    5. Adaptation and update strategy: incremental updates, backfill windows, retry on failure, and idempotent write rules.
    6. Test isolation: separate test pages from production pages and keep test data independent so the main pipeline stays clean.

    A contract definition can be very plain, but it must be unique:

    1. metric(metric_code, name, market, category, unit, source_id, freq)
    2. daily_quote(metric_code, trade_date, value, adjusted_flag)
    3. source_mapping(source_id, raw_field, metric_code, transform_rule)
    4. ingest_job(job_id, metric_code, window_start, window_end, state, retry_count)

    Once the contract is frozen, the infinite solution space becomes a finite fill-in-the-blank exercise. Each Agent task only completes one module inside a fixed structure, and the error rate drops sharply.

    3. Context Budget: Modularity Is the Only Way to Make AI Understand

    A complex system must be split so that a single conversation context stays small enough. Three practical split dimensions: by metric family (equities, rates, commodities, precious metals), by data layer (ingestion, standardization, computation, presentation), and by deliverable (one interface + one component + one set of tests).

    Each task package should contain four fixed sections: the contract excerpt, input/output samples, acceptance criteria, and forbidden actions. Forbidden actions are often more effective than requirements—for example, “do not add an unregistered metric_code,” “do not issue data requests inside a component,” and “do not modify frozen field names.”

    A simplified task package template:

    1. {
    2. "scope": "ingest.daily_quote.incremental",
    3. "contract_ref": "daily_quote@v1",
    4. "input_sample": [{"metric_code":"CN_10Y_YIELD","trade_date":"2025-01-02","value":1.68}],
    5. "acceptance": ["idempotent write", "identical results on repeated runs", "retryable on failure"],
    6. "forbidden": ["new fields", "changing naming conventions", "cross-layer calls"]
    7. }

    4. Autonomous Operation: Batched Execution and a Self-Checking Loop

    Conventional conversational AI tools usually lack two capabilities: automatically splitting a large task into batches and advancing them in order, and repeatedly checking and revising without human intervention. A continuously running Agent fits this kind of engineering because of the closed loop:

    1. read contract -> generate minimal implementation -> run tests -> parse errors -> targeted fix -> regression -> commit

    Supporting engineering constraints include persistent task queues (recoverable progress), rollback for every change, centralized log collection, and failed tasks entering a dead-letter queue instead of blocking everything. These are general engineering practices, independent of any specific cloud product. On the cloud, this typically means object storage for datasets and artifacts, a message queue for task distribution, a container platform for executors, and logging plus monitoring and alerting for observability.

    5. Memory and Compounding: Turning Volatile Context into Accumulated Assets

    Built-in Agent memory is currently better at recalling fixed facts than at understanding newly introduced business logic, and early constraints are easily buried in long workflows. The solution is externalized memory: write long-lived knowledge into repository files instead of leaving it in the conversation.

    • contract/: data and interface contracts, version controlled;
    • rules/: naming conventions, unit conventions, forbidden actions;
    • progress.md: completed metrics, pending metrics, known defects;
    • playbook/: repeatable collection and verification steps for a given data source.

    The test for whether work has compounding value is “will later tasks reference it repeatedly.” Contracts, mapping tables, validation rules, and ingestion script templates are high-compounding assets and should be fixed first; one-off page tweaks do not need to be preserved. After each batch, write back to progress.md so the next batch of Agents gets context from files rather than conversation history.

    6. Data Trust: Verification Design for Heterogeneous Multi-Source Data

    The value of a metrics system depends on data quality. Practical validation has four layers: format validation (type, unit, time zone), range validation (business-plausible intervals), consistency validation (cross-comparing the same metric across sources and checking continuity against adjacent dates), and definition validation (adjustment, settlement time, holidays). Anomalous data is not silently dropped; it is flagged with a status and routed to a manual review queue. Every correction keeps the original value so it stays traceable.

    7. Visualization and Validation: Deliver in Small Steps

    For the presentation layer, start with a minimal usable component—for example, Bollinger bands (middle band plus upper and lower bands) and an annual average reference line—then expand gradually. Pair each component with its own test page and fixed sample data so “component correctness” and “data correctness” are verified separately. Regression tests cover contract compatibility, and any field change must bump the version explicitly.

    8. Conclusion

    Whether an AI Agent succeeds at building a complex system depends mainly not on model capability but on the developer’s architecture and constraint design: compress requirements into contracts, compress tasks into small contexts, let an autonomously running Agent handle batched execution and self-checking, and externalize high-compounding knowledge into accumulated files. With this approach, a system with hundreds of metrics across markets and sources can have a usable skeleton in a short time and converge steadily through later iterations.