Building Complete Intelligent Applications with LLM APIs: Architecture, Orchestration, and Engineering Practices
This article describes a practical path for building a complete intelligent application on top of LLM APIs, covering the shift from built-in app features to API-level capabilities, a four-layer system architecture, orchestration and tool invocation, security and cost controls, observability, evaluation, and common pitfalls.
I. From Application Features to API-Level Capabilities
In the past, capabilities such as web search, deep reasoning, and file understanding were mostly available inside finished chat applications. Developers who wanted the same experience had to assemble multiple services themselves and handle retrieval results, document parsing, and multi-turn context.
A notable recent change is that some model providers expose these capabilities directly as API parameters. Developers only need to enable the corresponding options in a request, and the model can complete retrieval, reading, and reasoning in a single call. At the same time, capabilities such as search, web page scraping, OCR, speech recognition, and speech synthesis are also offered as standalone APIs that can be invoked individually or combined into workflows.
This changes the starting point of application development. Developers no longer need to implement every capability from scratch; instead, they can focus on three things: how to decompose tasks, how to verify results, and how to design the user experience.
II. Breaking Down Core Capabilities
Before designing a system, it is necessary to classify the capabilities. Different capabilities have different inputs, outputs, and risks.
2.1 Web Search
Web search lets the model obtain external information before answering. It is suitable for time-sensitive questions such as news, prices, policies, and version changes.
From an engineering perspective, three points need attention. First, search results should retain source URLs and publication times for later verification. Second, search results consume context length, so the number of returned items should be limited and the results should be summarized. Third, the model may treat search results as definite facts and output them directly, so cross-validation steps should be added for key data.
2.2 Deep Reasoning
Deep reasoning is suitable for mathematical computation, multi-step logical judgment, and complex planning. The output latency for these tasks is usually longer, and the cost is also higher.
It is advisable to make calls at different levels according to task difficulty. Simple questions can use the normal mode directly, while complex tasks can enable reasoning mode. This controls latency and avoids wasting resources in simple scenarios.
2.3 File and Link Understanding
File input and link reading let the model read materials provided by users, such as contracts, reports, web page content, and tables.
When processing such content, format validation and size limits should be performed first, followed by text extraction. Long documents need to be segmented or chunked, and prompts should explicitly require the model to mark the paragraph locations of citations. For files containing personal information or trade secrets, de-identification should be completed before upload.
2.4 Standalone Tool APIs
Standalone tool APIs form the execution layer of the system. Common examples include the following:
- Search API: returns a list of candidate web pages, suitable for recall.
- Web scraping API: fetches the body content of a specified page; it needs to handle dynamic rendering and access restrictions.
- OCR API: extracts text from images or scanned documents; attention should be paid to layout restoration and table recognition.
- Speech recognition API: converts audio to text, suitable for meeting notes and voice input.
- Speech synthesis API: converts text to speech, suitable for announcements and accessibility scenarios.
The advantage of standalone APIs is controllability. Developers can decide the call order, caching strategy, and failure fallback, instead of leaving all logic to the model to decide on its own.
III. System Architecture Design
A complete intelligent application can usually be divided into four layers.
The interaction layer receives user input, including text, voice, images, and files, and presents results as text, voice, or structured cards.
The orchestration layer is the core of the system. It determines user intent, decides whether retrieval, reasoning, or tool calls are needed, and manages call order and timeouts. The orchestration layer usually maintains task state, recording the input, output, and latency of each step.
The capability layer wraps model APIs and various tool APIs. Upper layers see only unified capability definitions, while underlying provider, version, and parameter details are isolated in adapters. Switching services then requires only adapter changes.
The state and storage layer stores conversation history, user-uploaded files, retrieval caches, and audit logs. Conversation history needs a retention period, and data beyond that period should be automatically cleaned up.
The benefit of layering is clear responsibility. If any layer has a problem, it can be replaced or degraded independently without affecting other parts.
IV. Illustrative Implementation
The following code shows the basic structure of orchestration logic. Function names and parameters are illustrative; actual API names and parameters should follow the documentation of the service used.
from dataclasses import dataclass, field@dataclassclass Task:user_input: strfiles: list = field(default_factory=list)need_search: bool = Falseneed_reasoning: bool = Falsedef classify(task: Task) -> dict:"""Determine which capabilities to enable based on the input."""text = task.user_inputreturn {"search": task.need_search or any(k in text for k in ["最新", "今天", "最近"]),"reasoning": task.need_reasoning or len(text) > 300,"files": bool(task.files),}def run(task: Task, model_client, tools: dict) -> str:plan = classify(task)context = []if plan["files"]:for f in task.files:context.append(tools["extract_text"](f, max_chars=20000))if plan["search"]:hits = tools["search"](task.user_input, top_k=5)context.extend(tools["fetch_summary"](h["url"]) for h in hits)prompt = build_prompt(task.user_input, context, cite_sources=True)return model_client.chat(prompt, reasoning=plan["reasoning"], timeout=60)
This code reflects three principles. First, capability enablement is decided by the orchestration layer, not entirely by the model. Second, each step has explicit quantity limits and timeout settings. Third, retrieval results require the model to mark sources for later verification.
V. Engineering Implementation Essentials
5.1 Authentication and Key Management
API keys should be stored in environment variables or a key management service, not written into code or logs. Different capabilities should be assigned independent keys with least privilege. Keys need to be rotated regularly and revoked quickly if leaked.
5.2 Timeouts, Retries, and Fallbacks
External APIs can fluctuate, so timeouts are mandatory. Retries should use exponential backoff and a maximum number of attempts to avoid amplifying failures. When search or speech services are unavailable, the system should fall back to answering only based on existing information and clearly inform the user that results may be incomplete.
5.3 Cost and Quota
Billing models for web search, deep reasoning, and speech processing are usually different. It is advisable to record the call type, latency, and usage at the orchestration layer, and to track costs by user or by feature. Adding caching for high-frequency requests and reusing results for identical queries can significantly reduce overhead.
5.4 Data Security and Privacy
User-uploaded files and voice may contain sensitive information. Follow the principle of data minimization: upload only the content needed to complete the task. Use encrypted channels for transmission and encrypt sensitive fields at rest. If there are compliance requirements, specify the data storage location and retention period.
5.5 Content Quality and Safety
Model output may contain factual errors or inappropriate content. Add rule-based validation before output, and verify key information such as numbers, dates, and names. For answers in high-risk domains such as healthcare, legal, and finance, prompt users to consult professionals.
5.6 Observability
Each request should log a complete call chain, including the intent classification result, tool call order, latency of each step, and error codes. These data are the primary basis for troubleshooting and prompt optimization. It is advisable to set alerts for key metrics such as failure rate, average latency, and cost per request.
VI. Evaluation and Iteration
After an intelligent application is launched, continuous evaluation is needed. A fixed set of test samples can be built to cover common questions, edge cases, and high-risk questions. After each prompt change, model version switch, or retrieval parameter adjustment, re-run the test set and compare accuracy, citation completeness, and response time.
Human evaluation is equally important. Sample-check whether answers are faithful to retrieval results, whether key information is missing, and whether there is over-inference. Evaluation results should feed back into orchestration rules and prompts to form a closed loop.
VII. Common Misconceptions
Misconception 1: Leaving all capabilities to the model to decide automatically. The model may call tools excessively, increasing latency and cost, or it may call search when not needed. Critical flows should still be controlled by orchestration rules.
Misconception 2: Believing that enabling capability parameters delivers a complete product experience. APIs only provide capabilities; product experience also depends on UI design, session management, error messaging, and access control.
Misconception 3: Neglecting result verification. Search results and file content may be inaccurate, and model statements may go beyond the original text. Source citation and key data validation cannot be omitted.
Misconception 4: Pursuing a one-to-one replica too early. Replicating a mature product’s UI and features is easy, but the real value lies in clarifying the needs of your own scenario. Start with the two or three most core capabilities, validate the results, and then expand gradually.
VIII. Conclusion
The combination of LLM APIs and standalone tool APIs lowers the barrier to building intelligent applications. Developers’ focus has shifted from implementing individual features to system design. A reasonable layered architecture, clear capability orchestration, strict security controls, and continuous evaluation and iteration determine whether an application can serve users reliably.
