Building Intelligent Conversational Applications with LLM APIs: A Practical Engineering Guide
This article examines the engineering capabilities behind an LLM-powered conversational application, including tool calling, web page reading, file processing, content safety, and session storage. It then presents a six-layer system architecture and an illustrative implementation outline for teams building a complete, production-oriented conversational experience.
1. Background: From a Single Model Call to a Complete Conversational Application
Calling a model API once does not by itself produce a usable conversational application. The experience users expect typically involves several capabilities: retrieving up-to-date information and citing sources, reading links and files sent by users, maintaining context across long conversations, filtering risky content on both the input and output sides, and preserving conversation history across multiple devices.
These capabilities are distributed across model inference, tool calling, file processing, safety review, and session storage. A team that wants to build a similar experience must first break these components apart, design each one, and then connect them through a unified orchestration layer. This article outlines that decomposition from an engineering perspective and proposes a practical design approach.
2. Core Capabilities
2.1 Web Search and Tool Calling
The common implementation pattern for web search is function calling. Developers declare available tools in the request, including each tool’s name, purpose description, and parameter schema. The model decides whether retrieval is needed based on the user’s question and, when necessary, emits a structured tool-call request. The application layer executes the retrieval, feeds the results back to the model, and the model generates an answer grounded in those results.
The key point is that the model makes the decision autonomously. For complex questions, the model may search once, read the results, determine that the information is insufficient, and then initiate a second search. This multi-step retrieval loop requires the application layer to set a maximum number of iterations and an overall time limit; otherwise, the process may loop indefinitely and costs may escalate.
Citations in answers also require engineering support. Retrieval results should retain the source URL, title, and retrieval time. After the answer is generated, the system maps citation numbers to their original sources so the frontend can display clickable references.
2.2 Web Page Reading
Users often paste links directly into messages. The application layer can use rules or a lightweight classification model to identify URLs in the message, and then a fetch service retrieves the page content. After fetching, three processing steps are required: remove noise such as navigation bars, advertisements, and scripts, and extract the main text; truncate or segment the content by length; and record the original URL and retrieval time.
Web page reading also involves security concerns. The fetch service must restrict its access scope and reject internal network addresses and loopback addresses to prevent server-side request forgery (SSRF). It should also enforce connection timeouts, response body size limits, and redirect limits.
2.3 File Input Processing
Users upload files in a variety of formats, commonly PDFs, office documents, and images. There are two processing paths:
- Plain text extraction: suitable for text-heavy documents. A parsing library extracts the text and preserves paragraph and heading hierarchy where possible.
- Mixed text and image parsing: suitable for documents containing tables, charts, or scanned pages. This requires layout analysis and optical character recognition (OCR) to convert image regions into textual descriptions or structured tables.
The parsed results are inserted into the conversation context, and the core constraint is the context window length. A long document may exceed the token limit of a single request, so the system needs to chunk it, summarize it, or include only the segments relevant to the current question. A common approach is to split the document first and then use keyword retrieval or vector retrieval to find the most relevant passages.
2.4 Content Safety and Compliance
Content safety is usually enforced on both the input and output sides. On the input side, the system checks user questions and uploaded content. On the output side, it checks model-generated results. When a risk rule is triggered, the system returns a unified refusal identifier, and the frontend uses it to display a fixed message instead of exposing the model’s raw output.
When offering services to the public, teams also need to meet applicable compliance obligations. These commonly include establishing a content safety review mechanism, completing any model filing or registration required by regulators, and labeling generated content. Specific requirements depend on local regulations; teams should confirm them with legal or compliance staff early in the project.
3. System Architecture Design
A complete conversational application can be divided into six layers, each with the following responsibilities:
- Model interface layer: encapsulates request formats, standardizes timeout, retry, and logging policies, and hides differences between API shapes.
- Safety review layer: applies rule-based filtering to inputs and outputs and handles refusal logic consistently.
- Orchestration layer: maintains conversation state, decides when to call tools, and controls loop counts and token budgets.
- Tool layer: search, web scraping, and file parsing are deployed independently so they can be scaled and cost-accounted separately.
- Session service: persists messages, attachment references, and user configurations, and supports importing and exporting conversation history.
- Frontend presentation layer: renders streaming output, citation badges, and refusal messages.
The benefit of layering is fault isolation. For example, if the web scraping service times out, only the corresponding tool call fails. The orchestration layer can degrade to an answer without citations and inform the user that the result has not been verified against web pages.
4. Illustrative Implementation
The following code is intended only to illustrate the design approach. Interface names and parameters should be replaced with those of the SDK actually used.
