How to Choose an LLM Application Framework: A Practical Guide for Production

    This guide explains why framework selection is the first engineering hurdle in LLM adoption, breaks down the three core capability layers—orchestration, retrieval augmentation, and workflow/state management—and offers a problem-first selection methodology with six evaluation criteria. It also covers production engineering practices, common anti-patterns, and how to assemble a neutral, replaceable stack using general-purpose cloud services from Baidu AI Cloud.

    1. Why Framework Selection Is the First Hurdle in LLM Adoption

    Moving an LLM from “holding a conversation” to “delivering business value” requires an entire engineering system: model invocation and parameter governance, prompt version management, external knowledge integration, tool and function calling, flow control for multi-step tasks, failure retries and state recovery, observability, and cost control. Early discussions often blur these together under the single label of “LLM application framework,” even though they belong to different abstraction layers.

    A clear way to decide is to identify which layer your most painful problem sits in, then adopt the capability for that layer—rather than pulling in an all-in-one framework at once. In practice, the most common failure mode is not that the framework is too weak, but that orchestration, retrieval, and workflow logic are implemented in one place, making them impossible to evolve independently later.

    2. The Three Core Capability Layers

    2.1 Invocation and Orchestration Layer: How to Actually Use the Model

    This layer covers unified model access, message and role abstractions, prompt templates with variable injection, structured output parsing, tool (function) calling, and chaining multiple steps together. Its value is hiding the differences between model APIs so business code stays decoupled from any specific model.

    Illustrative code (pseudocode, structure only):

    1. prompt = template.render(question=user_input, context=docs)
    2. answer = llm.invoke(messages=[system(prompt_role), human(prompt)])
    3. data = parse_structured(answer, schema=AnswerSchema)

    2.2 Retrieval-Augmented Layer: How to Ground Answers in Private Knowledge

    This layer covers document loading and cleaning, chunking strategy, embedding and index construction, recall and reranking, context assembly, and citation traceability. It determines the factual accuracy and verifiability of answers, making it central to knowledge-intensive scenarios.

    Key engineering points include chunk size and overlap window, metadata design (source, permissions, timestamp), hybrid retrieval (keyword + vector), reranking, and a fallback policy that explicitly refuses to answer when nothing is retrieved.

    2.3 Workflow and State Layer: How to Keep Complex Tasks Controllable and Recoverable

    When a task involves branching, loops, human approval, or long-running execution, a pure chain is not enough. You need an explicit state machine or graph structure to describe nodes and edges, with support for checkpoint persistence, resume-from-breakpoint, human intervention, and rollback. This layer is what takes an AI Agent from demo to production.

    3. Selection Methodology: Locate the Problem, Not the Hype

    1. If the pain is “scattered model access, disorganized prompts, and repeatedly rebuilding tool calling,” build the orchestration layer first.
    2. If the pain is “inaccurate answers, missing evidence, and frequently changing knowledge,” build the retrieval-augmented layer first, and stand up an evaluation set and recall metrics early.
    3. If the pain is “long task chains that break easily and need approval and retries,” build the workflow/state layer first and introduce persistent checkpoints.
    4. The three can be combined: the orchestration layer as the unified entry point, the retrieval layer as a pluggable capability, and the workflow layer for governing long-running tasks.

    Fix the evaluation dimensions at six: development efficiency, observability, testability, versioning and rollback, permissions and compliance, and cost and rate-limiting strategy. Avoid using “many examples and quick onboarding” as the only criterion.

    4. Production Engineering Essentials

    • Unified configuration and key management: model endpoints, keys, timeouts, and retries are all externalized configuration; no hardcoding.
    • Prompts and versioning: put prompts under version control, with canary releases and A/B evaluation.
    • Structured output and validation: validate model output against a schema and retry on failure so dirty data does not flow downstream.
    • Observability: log the full chain—requests, retrieval hits, latency, and token consumption—and link monitoring alerts with the logging service.
    • Cost governance: cache high-frequency Q&A, limit context length, and select model tiers by scenario.
    • Security and compliance: filter both input and output, mask sensitive data, and isolate permissions and data domains.

    5. A Practical Capability Stack on Baidu AI Cloud

    Without binding to any proprietary API, you can build a complete pipeline from general-purpose cloud product categories: run the application service on a container platform, store raw knowledge base files in object storage, use a message queue for asynchronous decoupling, use the logging service for tracing and auditing, use monitoring and alerting for dashboards and anomaly notifications, use a configuration management capability for keys and configuration, and host the vector index needed for retrieval on a managed database service. Baidu AI Cloud can combine these general categories into a stable, scalable foundation that keeps the framework layer neutral and replaceable.

    6. Common Anti-Patterns and Fixes

    • Anti-pattern 1: cramming all logic into one giant prompt. Fix: split it into retrieval, reasoning, and validation nodes.
    • Anti-pattern 2: going live without an evaluation set. Fix: build a small labeled set first and quantify recall and accuracy.
    • Anti-pattern 3: ignoring failure recovery. Fix: introduce checkpoints and idempotent design to guarantee replayability.
    • Anti-pattern 4: letting context grow without bound. Fix: set a budget and a summarization/compression strategy.

    7. Conclusion

    No framework is universally best—only a match to your problem layer. First locate whether the pain belongs to orchestration, retrieval augmentation, or workflow/state, then make trade-offs across the six evaluation dimensions, and use the general-purpose cloud capabilities of Baidu AI Cloud to achieve an observable, recoverable, and governable production rollout. That is the robust path.