Integrating Web Search and Multimodal Capabilities into Applications: An Engineering Practice
This article explains how developers can add web search, web page reading, document and image parsing, and speech input and output to an application. It covers when each capability fits, how to enable tools on demand, how to build a frontend on an open-source interface with a backend proxy, how to migrate chat history with data governance, how to manage API keys, how to choose models, and how to roll out the feature in stages.
1. Background: Breaking Down Conversational Capabilities
Many teams first encounter large language models through a web or mobile chat interface. A user types a question, the model replies, and the process looks simple. For developers, the more valuable parts sit behind that interface. Can the model retrieve the latest information? Can it read a link the user provides? Can it understand uploaded documents and images? Can it understand speech and answer with speech? These capabilities used to be tied to the interface. Now they are increasingly offered as APIs, so applications can combine them as modules.
Seeing this helps shift the question from “Can we build a chat page?” to “Which capabilities should our business use, how should we integrate them, and what are the costs and risks?”
2. Capability Breakdown and Use Cases
2.1 Web Search
Model training data has a cutoff date, so the model cannot cover events that happened afterward. Web search lets the model call search results before answering, which adds time-sensitive information. It suits news summaries, price and policy queries, and technology version comparisons. Two points matter. First, search results should cite their sources, and users should be able to verify them. Second, high-risk areas such as healthcare, law, and finance should include a human review step. Model output should not be treated as a final conclusion.
2.2 Web Page Reading
Users often paste links directly. The server needs to fetch the page, extract the main text, remove navigation bars and ads, and pass the cleaned text to the model. This step has to handle timeouts, redirects, dynamically rendered pages, and copyright restrictions. Fetching and cleaning should happen in your own service. Set domain allowlists or blocklists so that server-side requests cannot be abused to probe internal network addresses.
2.3 Document and Image Parsing
PDFs, tables, scanned files, and screenshots are the main inputs in enterprise scenarios. Parsing quality directly determines the quality of later answers. When processing tables, keep the row and column structure, because merging cells can shift meaning. For scanned files, first determine whether the document is image-based, then decide whether optical character recognition (OCR) is needed. Process large files page by page, and attach a page number to each segment so that answers can cite the original text.
2.4 Speech Input and Output
Speech recognition converts audio to text, and speech synthesis converts responses to audio. Combining them can support voice assistants, meeting minutes, and accessibility reading features. Engineering concerns include sampling rate and encoding format, end-to-end latency, splitting long audio, and how the interface updates during streaming responses.
3. Integration: Enable on Demand, Not All at Once
More capabilities mean more complex requests, with higher cost and latency. Maintain a capability list at the application layer, and decide which tools each request enables based on user intent. For example, ordinary chat does not need web search. Parsing is enabled only after a user uploads a file, and speech synthesis is called only when the user clicks the read-aloud button.
This design has three benefits. First, costs stay controlled, because each call pays only for the capabilities it actually uses. Second, results are traceable, because logs record which tool each step called. Third, faults are isolated. If one capability is temporarily unavailable, the core conversation can continue.
4. Sample Code
The code below shows structure only. Field names and functions are illustrative. For actual calls, follow the official documentation of the service you choose.
def build_request(user_input, attachments, want_voice):tools = []if needs_fresh_info(user_input):tools.append("web_search")if any(a.kind in ("pdf", "image") for a in attachments):tools.append("document_parse")if want_voice:tools.append("speech_output")return {"input": user_input, "tools": tools}def handle_turn(session, user_input, attachments=None, want_voice=False):request = build_request(user_input, attachments or [], want_voice)response = call_model_service(session.api_key, request)log_tool_usage(session.id, response.tool_calls)return response
This structure separates the decision about whether a tool is needed from the request itself. The decision logic can be tested on its own, and replacing the rules does not affect the calling layer.
5. Frontend Reuse: Building Quickly on an Open-Source Interface
If a team only needs a working chat interface, reusing an open-source frontend saves more time than building from scratch. A common approach is to download the static pages, change the service address in the configuration, and deploy them as a static site locally or on an internal network. These pages are usually pure frontend implementations, where users enter their own keys. This approach suits prototypes and internal demos.
Production use requires changes. A pure frontend page exposes the key in the browser environment, so add a backend proxy. The server stores the key, and the frontend requests only your own API. Custom development should focus on three areas. First, the message rendering module should support code highlighting and tables. Second, the streaming output module should handle interruption and retry correctly. Third, the display of tool call status should show users whether the model is searching the web or parsing a file.
6. Chat History Migration and Data Governance
Many users want to bring earlier conversations into a new environment. Migration usually has three steps: export and archive, parse the message structure, and restore context. During parsing, check each message’s role marker, timestamp, and attachment references. For missing fields, define a clear default handling policy. The restored context is limited by the model’s context window, so select content by time or relevance instead of loading everything.
Data governance matters just as much. Chat records may contain personal information and business secrets. Anonymize them before migration, encrypt them in storage, and set a retention period. When a user deletes records, remove the matching data from caches, indexes, and backups as well.
7. Security and Key Management
Keys directly control access costs, and a leak can have serious consequences. Store keys only in environment variables or a key management service, never in code or logs. Use separate keys for development, testing, and production. Set usage alerts for each key, and define a regular rotation plan.
Treat links and files that users submit as untrusted data. Validate type and size before parsing, so that malicious files cannot consume excessive resources. If model output contains executable content, escape it before display to prevent issues such as cross-site scripting.
8. Model Capability Boundaries and Selection
Model versions differ in tool support, context length, response speed, and cost. Do not assume every model supports every capability. Before integrating, check the documentation item by item to confirm that each tool is available on the target model. If a high-performance version does not yet offer the same tool set, use a mixed strategy. Send simple tasks to a model that supports the full toolset, and send complex reasoning to a more capable model with limited features. Implement the routing at the application layer.
9. Recommended Rollout Steps
Step 1: Map out business scenarios and list the three to four capabilities you truly need. Avoid integrating everything at once.
Step 2: Build a backend proxy and capability routing, and complete key isolation.
Step 3: Run a small-scale evaluation with real data. Record answer accuracy, response latency, and cost per call.
Step 4: Open the feature to users gradually, collect feedback, and refine your tool-calling strategy.
Following this order lets a team gain the core capabilities of a conversational product while keeping control over cost and data, and while keeping risk manageable.
