Large Model Application Development in Practice: Framework and Model Coordination

    This article explains how to build large model applications with a two-layer structure that pairs an application development framework with a foundation model service. It covers the core engineering challenges, a minimal working pipeline, prompt and chat templates, example selectors, output parsing, retrieval-augmented generation, orchestration, and production deployment practices, with practical code examples and recommendations for moving from a prototype to a maintainable system.

    1. Why a Two-Layer Structure of Framework Plus Model

    The core challenge in large model application development is the gap between the general capabilities of a model and the deterministic requirements of a business. Models are good at language understanding, generation, and reasoning, but they do not know your private data, business rules, or permission boundaries. Business systems need stable, auditable, and extensible interfaces, but they cannot train or fine-tune large models. Putting the two together produces the two-layer structure widely used in the industry: an application development framework on top, responsible for orchestration, data access, state management, and service exposure; and a foundation model service underneath, responsible for semantic understanding and content generation.

    This layering brings three direct benefits. First, decoupling: the model can be replaced, upgraded, or switched through a canary release while the business orchestration logic stays stable. Second, composability: capabilities such as prompt templates, retrievers, parsers, and tool calls can be assembled like building blocks for fast experimentation. Third, governance: logging, monitoring, rate limiting, and cost control can be consolidated in the framework layer instead of being scattered across calling code.

    It is important to note that a framework is not a silver bullet. It reduces engineering complexity; it does not remove the dependence on prompt design, data quality, and evaluation systems. What truly determines the upper limit of an application is still the data, the scenario definition, and the iteration mechanism.

    2. The Basics: From Understanding the Principles to Your First Runnable Pipeline

    2.1 The Relationship Between Data and Models

    The capabilities of a large model come from pre-training on large-scale corpora and subsequent alignment training. Understanding this explains two common phenomena: a model performs well on general knowledge within its training distribution but tends to “fabricate” content for private or time-sensitive information; and model output is probabilistic, so repeated calls with the same input may produce different results. Engineering must therefore assume that output is not fully deterministic and add validation and fallbacks around it.

    2.2 A Minimal Viable Pipeline

    The first program does not need to be complex. The goal is to complete the loop of “input - model - output” and observe the raw response structure. Example code:

    1. from app_framework.chat_models import ChatOpenAI
    2. from app_framework.schema import HumanMessage
    3. chat = ChatOpenAI(model="deepseek-chat", temperature=0.7)
    4. resp = chat.invoke([HumanMessage(content="Explain the value of retrieval-augmented generation in three sentences")])
    5. print(resp.content)

    Once it runs, immediately add three things: put the key in an environment variable or a key management service, add timeouts and retries to the call, and write requests and responses to logs. Good engineering habits should be established from the start.

    3. Data Augmentation: Giving the Model Something to Say

    3.1 Prompt Templates and Chat Templates

    Hard-coded strings cannot be reused. Prompt templates separate variables from instructions, allowing the same logic to serve different businesses. Chat templates distinguish roles such as system, user, and assistant, making the context boundaries of multi-turn conversations clear. The system prompt should carry role definition, output constraints, and safety boundaries, while the user prompt carries the specific task.

    1. from app_framework.prompts import ChatPromptTemplate
    2. prompt = ChatPromptTemplate.from_messages([
    3. ("system", "You are a rigorous technical documentation assistant. Answer only based on the given material, and clearly state when information is missing."),
    4. ("human", "Material: {context}\nQuestion: {question}"),
    5. ])
    6. chain = prompt | chat

    3.2 Example Selectors

    Few-shot examples can significantly improve format stability, but more examples are not always better. An example selector dynamically picks the most similar examples based on the current input, balancing effectiveness against context length cost. In practice, it is recommended that examples cover typical questions, edge-case questions, and refusal scenarios, and that they be supplemented regularly with real failure samples.

    4. Output Parsing: Turning Natural Language into Executable Data

    Model output must be structured before it can enter a business process. An output parser converts text into objects, lists, or enums, and provides repair hints on failure, forming a loop of “generate - validate - retry.”

    1. from app_framework.output_parsers import PydanticOutputParser
    2. from pydantic import BaseModel, Field
    3. class Ticket(BaseModel):
    4. title: str = Field(description="Issue title")
    5. level: str = Field(description="Urgency: high/medium/low")
    6. parser = PydanticOutputParser(pydantic_object=Ticket)
    7. # Inject parser.get_format_instructions() into the prompt, and pass the error back to the model for a retry when parsing fails

    There are two key practices: first, keep fields few and clear, and avoid extracting too many attributes at once; second, parsing failures must be observable, so track the failure rate and use it to drive iteration on prompts and examples.

    5. Retrieval-Augmented Generation: Addressing Freshness and Private Knowledge

    The value of retrieval-augmented generation is externalizing “memory.” The process has two parts: offline indexing and online retrieval. The offline stage handles document parsing, chunking, vectorization, and metadata annotation. The online stage first performs intent rewriting and multi-path recall, then reranks and assembles the context, and finally passes it to the model to generate an answer with sources.

    Engineering points include: chunk size and overlap should match the document structure; metadata (source, time, permission labels) must be passed along with each chunk for filtering and citation; when recall is insufficient, allow the model to explicitly answer that there is not enough material instead of forcing fabrication; and validate citations on the answer to ensure every conclusion can be traced back.

    6. Orchestration and Integration: From Chains to Agents

    Chains are suitable for fixed processes, while agents are suitable for tasks with uncertain paths. The criterion is whether the branches can be enumerated: use a chain when they can, and introduce tool calls and a planning loop when they cannot. In either case, set a maximum number of steps, a timeout, and a budget cap to avoid infinite loops and cost overruns.

    For the service stage, encapsulate the orchestration logic behind a unified interface, deploy with a container platform, collect pipeline information with a logging service, and track latency and failure rates with monitoring and alerting. On the model side, multi-model routing can be used: simple requests go to a lightweight model and complex requests go to a more capable model, balancing effectiveness and cost.

    7. Implementation Recommendations

    Start narrow and then broaden: pick a high-frequency, evaluable scenario and close the loop. Build an offline evaluation set and a manual sampling mechanism, and use data to drive prompt and retrieval optimization. Move safety boundaries forward by handling input filtering, permission isolation, and sensitive information masking. Following this path, large model applications can move from a demo to a maintainable production system.