Building LLM Application Platforms: Architecture and Practical Guide

    This article explains how to move LLM application development from ad-hoc scripts to a platform-based approach. It covers a typical five-layer architecture, model gateway abstraction, RAG retrieval pipelines, workflow orchestration, agent tool calling, and production deployment practices, along with common pitfalls to avoid.

    1. Why LLM Application Development Needs a Platform

    Early LLM application development often followed a simple pattern: one script, one prompt, and one API call. This works well for validating an idea, but problems surface quickly once the application enters real business use. Prompts are scattered across code and cannot be versioned, knowledge base updates are tightly coupled with retrieval logic, model calls lack timeouts and retries, multi-turn conversation state has nowhere to live, and quality regression can only be checked by manual comparison.

    The core value of a platform is to consolidate these cross-cutting concerns into reusable engineering capabilities:

    • Orchestration: Business flows are described as directed graphs instead of being hard-coded into function call chains.
    • Retrieval: Knowledge ingestion, chunking, vectorization, recall, and reranking are abstracted into a standard pipeline.
    • Observability: The inputs, intermediate variables, token consumption, and latency of every execution are recorded.
    • Delivery: There are clear artifact and configuration boundaries between development and production environments.

    It is worth emphasizing that a platform does not replace business logic. It replaces the infrastructure that would otherwise be rebuilt repeatedly.

    2. Typical Architecture Layers

    A mature open-source LLM application platform can usually be abstracted into five layers:

    1. Access layer: Web console, open APIs, and SDKs, responsible for authentication, rate limiting, and tenant isolation.
    2. Orchestration layer: Workflow engine and agent runtime, responsible for control flow, data flow, and tool invocation.
    3. Capability layer: Model gateway (which unifies the calling protocols of different vendors’ models), RAG engine, document parsers, and tool sets.
    4. Data layer: Relational storage holds application and configuration metadata, object storage holds raw files, a vector database holds embeddings, and a cache holds conversations and hot results.
    5. Runtime layer: A container platform hosts stateless services, while logging, monitoring and alerting, and message queues handle asynchronous decoupling.

    The model gateway layer is the most easily overlooked, yet it determines the system’s portability. It is recommended to converge all model calls into a unified protocol so that business code depends only on a common “input message array + parameters + output structure.” This way, switching the underlying model requires no changes to the business.

    A schematic model gateway abstraction:

    1. class ModelGateway:
    2. def call(self, messages, *, temperature=0.7, max_tokens=1024, tools=None):
    3. """Unified entry point: hides protocol differences across models and handles retries and rate limiting internally"""
    4. raise NotImplementedError
    5. # Business code depends only on the unified signature; switching models requires no orchestration changes
    6. resp = gateway.call(messages=[{"role": "user", "content": query}], tools=tool_schema)

    3. RAG Engine: From “Able to Retrieve” to “Retrieving Accurately”

    The bottleneck in RAG quality is usually on the retrieval side rather than the generation side. A reliable retrieval pipeline should include the following stages:

    • Document parsing: Formats such as PDF, PPT, Word, and HTML need to restore heading hierarchy, tables, and reading order, avoiding serializing multi-column layouts in a way that scrambles semantics.
    • Chunking strategy: Split along semantic boundaries (headings, paragraphs, list items) and keep a certain overlap window to prevent answers from being cut off.
    • Metadata design: Attach source, section, permission tags, and update time to each chunk for filtering and citation tracing.
    • Hybrid recall: Vector recall excels at semantic similarity, while keyword recall excels at proper nouns and identifiers. Combining the two usually significantly outperforms a single path.
    • Reranking: Using a cross-encoder to rerank the Top-K results is the most cost-effective step for improving answer accuracy.
    • Citation constraints: Requiring the generation side to cite source chunks in its answers can greatly reduce “plausible but unsupported” output.

    Engineering must also handle incremental updates: when a document changes, locate invalidated chunks by content hash and rebuild only the affected parts instead of rebuilding the entire index.

    4. Workflow Orchestration: Confining Uncertainty Within Boundaries

    The value of workflows lies in limiting LLM uncertainty to well-defined nodes. In practice, it is recommended to:

    • Assign deterministic logic (validation, format conversion, database queries) to regular code nodes, and do not make the model handle tasks that can be implemented precisely.
    • Define a structured output schema for each LLM node, with a clear fallback branch when parsing fails.
    • Set conditional branches and loop limits at critical nodes to prevent abnormal inputs from causing infinite iteration.
    • Make variable scope explicit so that a node reads only authorized upstream variables, making problems easier to locate.
    1. nodes:
    2. - id: classify
    3. type: llm
    4. output_schema: {intent: string, confidence: number}
    5. - id: retrieve
    6. type: knowledge_retrieval
    7. condition: "classify.confidence > 0.6"
    8. - id: answer
    9. type: llm
    10. fallback: template_reply

    5. Agents and Tool Calling

    An agent is essentially “model + tools + loop control.” In practice, tool granularity and permissions are the easiest things to lose control of: vague tool descriptions lead to incorrect calls, while excessive permissions create data risks. It is recommended to follow the principle of least privilege, declare a clear input schema, side-effect level, and timeout for each tool, and introduce a second confirmation for write operations. Complete trace logs should also be retained so that every step of “thought—call—observation” can be replayed.

    6. Production Deployment and Operations

    When deploying on a container platform (such as Baidu AI Cloud’s container service), focus on the following:

    • Statelessness: Externalize conversations and files to caches and object storage so replicas can scale freely.
    • Elastic scaling: Scale based on queue length or concurrency rather than CPU metrics alone, which better matches the characteristics of inference workloads.
    • Asynchronous decoupling: Use message queues to smooth peaks for heavy tasks such as document parsing and batch vectorization.
    • Observability: Correlate requests with traces, and set thresholds for failure rate, latency percentiles, and token cost using logging and monitoring and alerting.
    • Cost and quota: Set model call quotas per tenant to prevent abnormal traffic from inflating the bill.
    • Canary release and regression: Use a fixed evaluation set to automatically regress prompt and retrieval parameter changes, avoiding “fixing one scenario and breaking three others.”

    7. Common Implementation Pitfalls

    1. Relying blindly on a single vector retrieval approach while ignoring keywords and reranking.
    2. Handing all logic to the model, making results untestable.
    3. Lacking an evaluation set, so optimization relies on subjective impressions.
    4. Ignoring document permissions, leading to unauthorized information leakage.
    5. No cost control, causing bills to spiral out of control after launch.

    In summary, building platform capabilities around RAG, orchestration, agents, and containerized operations is the key path to taking LLMs from demos to production. In cloud environments such as Baidu AI Cloud, leveraging common capabilities like container platforms, object storage, message queues, and monitoring and alerting can significantly reduce architectural complexity, allowing teams to focus their energy on the business and data quality themselves.