Architecture and Development Practices for a Large Model Open Platform

    This article explains how to design and build an open platform layer for large language models (LLMs) that turns research prototypes into production systems. It covers a four-layer architecture (access, capability, orchestration, and governance), task-first model selection, contract design with structured output and fallback paths, versioned prompt templates, retrieval-augmented generation (RAG), tool calling and agent orchestration with explicit state machines, a three-tier evaluation system, cost and latency optimization, security and tenant isolation, and a phased rollout plan. The core takeaway is to treat the model as a replaceable component and to build engineering certainty on contracts, evaluation, and governance.

    1. Why an “Open Platform” Layer Is Needed

    When large models move from research prototypes to production systems, the biggest obstacle is not the model itself but the engineering gap between the model and business logic. The value of an open platform is to consolidate cross-cutting concerns that are unrelated to business but essential in production—authentication, quotas, routing, rate limiting, logging, and metering—behind a unified entry point, so developers only deal with the input-output contract.

    A mature layered structure can usually be abstracted into four layers:

    1. Access layer: unified authentication, key management, tenant isolation, quotas, and rate limiting.
    2. Capability layer: atomic capabilities such as text generation, vector representation, multimodal understanding, structured extraction, and function calling.
    3. Orchestration layer: prompt template management, retrieval augmentation, tool calling, multi-step task flows, and state management.
    4. Governance layer: logging and tracing, quality evaluation, cost accounting, content safety, and auditing.

    The point of this layering is replaceability. Models iterate quickly, and if business code is tightly coupled to the details of a specific model call, migration costs become prohibitive. Engineering practice should therefore treat the model as a pluggable dependency and isolate differences through an adapter layer.

    2. Scenario Selection Before Integration: Define the Task First, Then Choose the Model

    A common mistake is to start with the most “powerful” model and work backward to the business case. A more reliable order is to classify the task first:

    • Generation: summarization, rewriting, marketing copy, code assistance. Focus on fluency and instruction following.
    • Understanding: classification, extraction, intent recognition, sentiment detection. Focus on stability and output format consistency.
    • Reasoning: multi-step analysis, option comparison, mathematical and logical derivation. Focus on long-chain consistency.
    • Retrieval Q&A: knowledge base question answering, customer support assistance. Focus on factual accuracy and traceable citations.

    Selection should be based on an evaluation matrix with dimensions including task accuracy, output format compliance rate, time to first token, cost per token, whether the context window fits the material size, and support for structured output and tool calling. Selection without evaluation data is guesswork.

    3. Contract Design: Confining Uncertainty

    Model output is inherently probabilistic, and the first engineering task is to reduce its degrees of freedom.

    First, use a system instruction to fix the role, boundaries, and output specification, and define how to answer when the answer is unknown. Second, require structured output wherever possible so downstream systems can parse it directly. Illustrative code:

    1. import json
    2. SYSTEM = """You are a ticket classification assistant.
    3. Output JSON only, no explanations.
    4. Fields: {"category": one of ["billing","bug","feature","other"], "confidence": 0.0-1.0}
    5. When uncertain, set category to other."""
    6. def classify(user_text: str, model_client) -> dict:
    7. resp = model_client.chat(
    8. system=SYSTEM,
    9. user=user_text,
    10. temperature=0, # disable randomness for classification tasks
    11. max_output_tokens=256,
    12. )
    13. try:
    14. return json.loads(resp.text)
    15. except json.JSONDecodeError:
    16. return {"category": "other", "confidence": 0.0}

    Third, sampling parameters such as temperature should be tiered by task: close to 0 for classification and extraction, moderately higher for creative generation. Fourth, design a fallback path for parsing failures instead of letting exceptions bubble up to the user.

    4. Making Prompt Engineering Maintainable

    Prompts should not be scattered across code strings. The recommended approach is templating plus versioning: store templates in configuration or a configuration center, including variable placeholders, version numbers, and change logs; before release, run a fixed regression set and compare whether key metrics have degraded. This decouples prompt iteration from code releases, and rollback only requires switching versions.

    A practical template structure has five sections: task objective, input material, constraints and prohibitions, output format, and examples. Few-shot examples should cover edge cases, especially “insufficient material” and “conflicting information”; otherwise the model tends to force an answer.

    5. Retrieval Augmentation: Addressing Factual Accuracy and Freshness

    Parametric knowledge cannot cover enterprise private data, and retrieval-augmented generation (RAG) has become the standard solution. The full pipeline is: document parsing → chunking → vectorization → indexing → retrieval → reranking → context assembly → generation with citations.

    Engineering points that are often overlooked:

    • Chunking strategy should match document structure; splitting by heading hierarchy usually works better than fixed character counts.
    • Hybrid retrieval (keyword plus vector) is noticeably more stable for queries involving proper nouns, IDs, and model numbers.
    • The reranking stage can significantly improve the signal-to-noise ratio of the context and avoid filling the window with irrelevant fragments.
    • More context is not always better; excessive length dilutes key information and raises costs.
    • Citation source fields must be preserved so answers are verifiable, which is a hard requirement in enterprise scenarios.

    6. Tool Calling and Agent Orchestration

    When a task needs to access databases, query orders, or call internal APIs, tool calling (function calling) is the core mechanism. Design principles: tool descriptions should be as precise as API documentation, parameters should be constrained with strongly typed schemas, permissions should follow least privilege, and write operations require a second confirmation.

    For multi-step tasks, introduce an explicit state machine rather than relying on the model to “remember” the flow:

    1. States: collect parameters -> validate -> execute query -> summarize -> user confirmation -> submit
    2. Constraints: only whitelisted tools may be called at each step; retry limit of 2; timeout falls back to human handling

    Observability is especially critical at this stage. Log a summary of each tool call’s inputs, elapsed time, return code, and retry count to form a complete trace, making it easier to determine whether the issue is a model decision error or an API failure.

    7. Evaluation System: No Measurement, No Improvement

    A three-tier evaluation approach is recommended:

    1. Unit level: fixed input-output pairs to check format compliance rate and key field accuracy, integrated into CI and run automatically on every prompt or model change.
    2. Scenario level: build a regression set from real, anonymized samples, scored manually or by rules, tracking the overall pass rate trend.
    3. Online level: canary releases that collect user feedback, retry rate, and human handoff rate, cross-validated against offline metrics.

    For classification tasks, use accuracy and a confusion matrix; for generation tasks, use pairwise comparison plus manual spot checks to avoid being misled by a single automated metric. The evaluation set should continuously incorporate failure cases found in production, forming a closed loop.

    8. Cost, Latency, and Stability Governance

    Cost is determined jointly by input tokens, output tokens, and call volume. Effective measures include context trimming and summary compression, semantic caching (reusing results for similar requests), tiered routing with a small model first and escalation to a large model for difficult samples, and off-peak scheduling of batch tasks.

    Latency optimization balances time to first token against total duration; streaming responses can improve perceived performance for long outputs. For stability, implement exponential backoff retries, multi-availability-zone failover, rate limiting, and degradation switches; when the upstream is unavailable, fall back to rules or cached results to keep the business running.

    9. Security, Compliance, and Tenant Isolation

    Content safety should filter in both directions: block injection and privilege-escalation instructions on the input side, and check for sensitive information and compliance on the output side. Keys should be managed centrally by a key management service and rotated regularly, never hard-coded. Multi-tenant scenarios require isolation at the storage and logging layers, masking of sensitive fields in logs, and clearly defined retention periods and audit policies.

    Phase one is single-point validation: pick a high-frequency scenario with clear boundaries and high fault tolerance, and get the access layer, structured output, and basic evaluation working end to end. Phase two adds retrieval and tool calling, connecting real business data and internal systems. Phase three builds the governance system: cost accounting dashboards, tracing, canary and degradation, and evaluation automation.

    In general engineering practice on cloud platforms such as Baidu AI Cloud, the capabilities above are typically delivered by combining common categories such as object storage, message queues, container platforms, logging services, and monitoring and alerting, and teams can use these to build a technical foundation that matches their own business. The core conclusion is a single sentence: treat the model as a replaceable component and build engineering certainty on contracts, evaluation, and governance, so intelligent applications can move from demo to production.