LLM Application Development: Technical Selection and Implementation Practices
This article walks through the engineering decisions behind building production-grade LLM applications: a layered architecture that isolates model uncertainty, retrieval-augmented generation practices that set the ceiling on answer quality, tool-calling and multi-agent patterns that keep behavior controllable, a three-tier evaluation system that replaces guesswork with metrics, and a checklist for cost, security, and operations. It is written for developers who need to judge real engineering capability behind similar-looking demos and deliver stable business value from any general-purpose model.
1. The Real Question Behind a Viral Thread
At a recent industry conference, a screenshot of an engineer’s personal bio spread quickly on social platforms. The discussion drifted away from the person, and the comments filled up with speculation that had nothing to do with engineering. The only signal worth keeping from the original material was a single question: how good is this person’s code, really?
That question points to what developers care about most in the era of LLM applications. Demo results look highly similar today, so how do you judge the actual engineering capability behind a solution? Demo videos can be edited, and sample prompts can be tuned repeatedly, but system stability, context management, evaluation coverage, and recovery speed do not lie. This article therefore sets aside all people and product topics and focuses only on the general technical question: how to build an LLM application that is measurable, maintainable, and extensible.
2. Layered Architecture: Containing the Uncertainty
The complexity of LLM applications comes from uncertainty. The first engineering principle is layered isolation, so that uncertain components cannot affect deterministic ones.
- Access layer: handles authentication, rate limiting, request body validation, and audit logs, so model calls are never exposed directly to end users.
- Orchestration layer: handles task decomposition, tool selection, and multi-turn state management. It acts as a buffer between business logic and model capability.
- Capability layer: wraps atomic capabilities such as model inference, vector retrieval, reranking, and structured output parsing, with unified timeout and retry policies.
- Data layer: stores raw documents, chunks, vector indexes, and business databases, using a combination of object storage and a relational database.
- Observability layer: collects call traces, token consumption, time to first token, and failure reasons, and connects to logging and alerting services.
Layering has one direct benefit: replacement cost stays under control. When the underlying model needs to change, only the adapter in the capability layer is adjusted; the orchestration layer and business code stay untouched.
class ModelAdapter:def generate(self, messages, **options):raise NotImplementedErrorclass RetryAdapter(ModelAdapter):def __init__(self, inner, max_retry=2):self.inner = innerself.max_retry = max_retrydef generate(self, messages, **options):last_error = Nonefor attempt in range(self.max_retry + 1):try:return self.inner.generate(messages, **options)except TimeoutError as exc:last_error = excraise last_error
3. Retrieval-Augmented Generation: The Step That Sets the Ceiling
Most poorly performing question-answering systems in production fail at retrieval, not at the model. With poor retrieval quality, even the strongest model can only fabricate. Four points deserve attention.
First, the chunking strategy. Fixed-length chunking is simple to implement but tends to cut across semantic boundaries. A safer approach is to split along heading hierarchy and paragraph boundaries, keep some overlap, and write the section path into metadata so sources can be traced back.
Second, hybrid retrieval. Pure vector retrieval is good at semantic similarity but insensitive to proper nouns, identifiers, and error codes; keyword retrieval is the opposite. Fusing results from both paths and then passing them to a reranking model is usually more stable than a single path.
Third, metadata filtering. Write document version, effective date, and permission labels into the index, then filter before ranking at retrieval time. This significantly reduces contamination of answers by outdated content.
Fourth, citation constraints. Require the model to answer only from retrieved chunks and to mark source numbers in the output. When chunk relevance falls below a threshold, respond clearly that information is insufficient instead of forcing generation.
System constraint: Answer using only the content in [Context].If the context is not enough to support a conclusion, output: Insufficient information, additional material required.Mark the source number after each conclusion, for example [2].
4. Agents and Tool Calling: Controllability First
Tool calling turns a model from something that “can talk” into something that “can act,” and it also brings the risk of side effects. Follow the principle of least privilege: expose only the necessary parameters for each tool, separate write operations from read operations, and add a human confirmation step for irreversible actions such as deletion, transfers, and publishing.
{"tool": "query_order_status","arguments": {"order_id": "string", "date_range": "string"},"permission": "read_only","requires_confirmation": false}
Multi-agent collaboration suits scenarios where the task can be split cleanly, for example retrieval, computation, and validation handled by different roles. But the more roles there are, the greater the context loss during handoff, and debugging difficulty rises exponentially. Early on, a single agent with a tool set is the better choice; split into multiple agents only after the benefit is validated.
5. Evaluation: Turning “Feels Good” into Numbers
Optimization without evaluation is guesswork. A practical minimum evaluation set has three layers.
- Unit layer: structured output parsing success rate, tool argument validity rate, and refusal accuracy.
- Task layer: answer correctness, citation hit rate, and step completion rate, tracked by business intent category.
- Regression layer: run the full sample set after every prompt or model change, compare key metric fluctuations, and block the release when a threshold is exceeded.
Beyond metrics, look at the latency distribution rather than the average, with separate targets for time to first token and overall duration. Also track token consumption to locate redundant prompts.
6. A Checklist for Cost, Security, and Operations
The lever for cost control is tiered model usage: give simple tasks such as intent recognition and format conversion to smaller models, and complex reasoning to larger ones. Add semantic caching for high-frequency repeated questions. For long documents, summarize first and then place the summary in context.
Security requires protection on both input and output. On the input side, detect prompt injection and identify sensitive information; on the output side, run content compliance checks and mask personal information. Keep audit logs across the full chain, and manage keys through a configuration center or a key management service rather than in the code repository.
For operations, prepare three fallback plans: when the model service is unavailable, degrade to rule-based replies or cached results; when the retrieval service fails, narrow the recall scope and notify the user; when the queue backs up, throttle non-core tasks to keep the main path available.
7. Conclusion
Back to that opening question: the standard for judging engineering capability has never been how impressive the demo looks, but whether the system behaves predictably under real traffic. Layered architecture controls the blast radius, retrieval quality sets the ceiling on answers, tool permissions bound behavior, the evaluation system provides a basis for improvement, and cost control plus fallback plans ensure long-term sustainability. Get these five things solid, and plugging in any general-purpose model becomes a stable business capability that can be delivered. This is also the implementation approach Baidu AI Cloud repeatedly emphasizes when supporting enterprise-grade applications.
