AI Application Architecture in the Era of Accessible Large Models
This article examines the engineering practices behind building production-grade AI applications as large models become cheaper and more accessible. It explains why the core challenge has shifted from calling a model to designing stable, controllable, and cost-predictable systems, and walks through requirement layering, a five-layer reference architecture, retrieval-augmented generation, tool calling and agent orchestration, evaluation, security, and cost governance. Includes sample code and a phased rollout path for teams moving from prototype to production on general-purpose cloud capabilities.
When large model capabilities become available at lower cost and with higher accessibility, application forms such as AI browsers, AI search, AI assistants, agents, and chatbots emerge rapidly. For developers and enterprises, the real challenge has shifted from “whether we can call a model” to “how to build AI application systems that are stable, controllable, scalable, and cost-predictable.” From a neutral technical perspective, this article systematically reviews the engineering essentials behind this wave of AI application accessibility, covering requirement breakdown, layered architecture, retrieval-augmented generation, tool calling and agent orchestration, evaluation systems, security and cost governance. It also provides practical sample code to help teams move from prototype to production on top of general-purpose cloud capabilities.
1. What Accessibility Really Changes: From Model Scarcity to Engineering Scarcity
In the past, the biggest barrier to building a usable conversational application was model capability itself. Once model services became available on demand, like water and electricity, the bottleneck moved quickly to the engineering side. Three clear changes can be observed.
First, application forms are moving from single-turn Q&A to multi-turn tasks. Users no longer settle for “answering a question”; they want the system to “get the work done,” such as organizing materials, comparing information, generating structured results, and triggering follow-up actions. This requires state management, task decomposition, and external tool calling.
Second, evaluation criteria are shifting from “does the answer sound human” to “is the result correct and reliable.” Enterprise scenarios care more about factual consistency, traceable citations, recoverable failures, and stable response latency than about polished language style.
Third, the cost structure is changing from a one-time investment to ongoing operations. Inference calls, retrieval, vectorization, logging, and monitoring all generate recurring expenses. Without budget and quota design, costs can easily spiral out of control after launch.
The essence of accessibility, therefore, is moving the focus of competition from “which model to integrate” to “who can reliably embed a model into business processes.”
2. Layer Requirements First: Do Not Hand Every Problem to the Model
The first step in engineering is deciding which parts should be handled by the model and which should be handled by deterministic code. It is recommended to divide functionality into three layers:
- Deterministic layer: permission checks, data queries, numerical computation, and state transitions must be guaranteed by code and databases;
- Semantic layer: intent recognition, summarization, rewriting, classification, and extraction are suitable for the model;
- Orchestration layer: task planning, tool selection, failure retries, and human takeover are handled jointly by agent frameworks and business rules.
A common mistake is to let the model “mentally compute” calculations and queries, which introduces unverifiable hallucinations. A safer approach is to have the model output a structured call intent, with the backend executing it and filling in the result. An example:
{"intent": "query_order_status","arguments": { "user_id": "u_1024", "order_id": "o_88231" },"confidence": 0.86}
The backend only accepts intents and parameter schemas on a whitelist, and after execution passes the result back to the model as context to compose a natural language reply. This “model proposes, code executes” pattern is the foundation for maintaining control.
3. Reference Architecture: Five Layers Supporting AI Applications
A reusable layered architecture typically includes the following parts, and each layer can be implemented with general-purpose cloud capabilities such as object storage, message queues, container platforms, logging services, and monitoring and alerting.
- Access layer: handles session entry points, authentication, rate limiting, and canary releases. It is recommended to abstract different entry points (web, mobile, internal systems) into a unified session gateway for consistent governance.
- Orchestration layer: session state machines and task graphs. Multi-turn conversations need to retain short-term memory and task slots, while long-running tasks are converted into asynchronous jobs and decoupled through message queues to avoid request timeouts.
- Capability layer: model inference, vectorization, reranking, and content safety filtering. The capability layer should be encapsulated with an adapter pattern so that models or vector services can be replaced without affecting upper-layer logic.
- Data layer: raw documents, chunks, vector indexes, business databases, and caches. Raw content is stored in object storage, metadata and permission labels are stored in a relational database, and vector indexes are deployed independently so they can be rebuilt.
- Observability layer: tracing, call logs, quality metrics, and cost dashboards. An AI application without an observability layer cannot go into production.
Layers communicate through explicit contracts, avoiding high-risk coupling such as “the model directly accessing the database.”
4. Retrieval-Augmented Generation: Making “Trustworthy” an Engineering Metric
The key difference between AI search and AI assistants lies in trustworthiness, and retrieval-augmented generation is currently the most common implementation path. To turn it into an engineering metric, four areas need attention.
First, chunking strategy. Splitting along semantic boundaries works better than fixed character counts; titles, paragraphs, and lists should retain structural information, and each chunk should be tagged with source, update time, and permission labels.
Second, hybrid retrieval. Vector retrieval alone is insensitive to proper nouns and identifiers, so it is recommended to run keyword retrieval and vector retrieval in parallel and then fuse the results with a reranking model, which can significantly reduce “answering the wrong question.”
Third, citations and constraints. Require the model to answer only based on retrieved chunks and to include chunk IDs in the output; when retrieval confidence falls below a threshold, explicitly reply that information is insufficient rather than improvising.
Fourth, index rebuilding. When documents are updated frequently, chunking and vectorization should run as an asynchronous pipeline, with indexes managed by version numbers to support canary switching and fast rollback.
def build_context(query, top_k=6, threshold=0.35):hits = hybrid_search(query, top_k=top_k) # keyword + vectorhits = rerank(query, hits)[:top_k] # rerankingkept = [h for h in hits if h.score >= threshold]if not kept:return None, [] # trigger the "insufficient information" branchcontext = "\n".join(f"[{h.id}] {h.text}" for h in kept)return context, [h.id for h in kept]
5. Tool Calling and Agent Orchestration: Controllability Over Freedom
Agents can “get the work done” because of tool calling. Engineering should follow the principles of least privilege and auditability: each tool declares its input schema, timeout, idempotency, and side-effect level; write operations must go through confirmation or secondary validation; and all calls are logged for traceability.
For orchestration, it is recommended to use an explicit task graph rather than a fully autonomous loop. An explicit task graph breaks the flow into nodes and edges, making it easy to set retries, parallelism, and human intervention points; autonomous loops suit exploratory tasks but must set a maximum number of steps and a budget cap to prevent unlimited calls.
task: monthly_reportnodes:- fetch_data: { tool: sql_query, timeout: 8s, retry: 2 }- analyze: { model: chat, max_tokens: 2048 }- render: { tool: doc_render, side_effect: write, need_confirm: true }edges:fetch_data -> analyze -> renderlimits:max_steps: 12budget_tokens: 60000
6. Evaluation Systems: No Iteration Without Offline Evaluation
The quality of AI applications must be quantified. It is recommended to build three levels of evaluation: unit-level (prompt template and parsing accuracy), task-level (end-to-end completion rate and citation accuracy), and online-level (user feedback, retention, and latency percentiles). Evaluation sets should come from real, de-identified samples and continuously add failure cases to form a regression baseline. Any prompt or model change must pass the regression suite to avoid “fixing one scenario and breaking three others.”
7. Security, Cost, and Capacity Governance
For security, two-way filtering of inputs and outputs, de-identification of sensitive information, and unauthorized access checks are all essential; retrieval results must be filtered again according to user permissions to prevent “index-level privilege escalation.”
For cost, establish quotas and budget alerts by business line, separate interactive from batch traffic, route batch processing through asynchronous queues, and run it off-peak; introducing a semantic cache for high-frequency repeated questions can noticeably reduce repeated inference overhead.
For capacity, inference and vectorization services should support elastic scaling, with monitoring and alerting thresholds set for latency and error rates; critical paths should have fallback strategies, such as falling back to a pure model answer when retrieval is unavailable while clearly indicating uncertainty.
8. Recommended Rollout Path
In the first phase, build a closed loop in a narrow scenario, choose a single business with clear metrics, and validate value in two to three weeks. In the second phase, complete retrieval, evaluation, and observability, turning accuracy and cost into numbers on a dashboard. In the third phase, expand tool and agent capabilities and gradually open up write operations. General-purpose cloud product categories offered by Baidu AI Cloud, such as container platforms, object storage, message queues, logging services, and monitoring and alerting, can serve as the foundation for the architecture above, allowing teams to focus on business semantics and evaluation systems rather than rebuilding infrastructure.
Accessibility truly rewards teams that lock uncertainty inside an engineering cage: models can be replaced, but architecture and evaluation assets will keep appreciating.
