Building Conversational Apps with Web Search and Multimodal Input
This article explains how to build a conversational application that combines web search, file input, link reading, and speech capabilities. It covers what each capability does, how to implement it safely, how to choose between server-side and client-side orchestration, a sample question-answering workflow, and engineering practices for context management, timeouts, citations, observability, cost control, and compliance.
Why Combine Conversational Capabilities
Early large language model APIs mainly handled single-turn text generation. The caller assembled a prompt, sent a request, and received a block of text. As requirements grew more complex, users wanted models to look up current information, understand uploaded contracts and reports, read the body text of web links, and understand speech and read replies aloud. If each business team builds these capabilities separately, it must maintain several pipelines for search calls, document parsing, context assembly, and format conversion. The workload and the risk of errors rise quickly.
Consolidating these capabilities behind a unified interface is a practical engineering approach. The server handles tool calls and context assembly. Developers then focus on defining the scenario, setting boundaries, and validating results, instead of building pipelines. Understanding this shift helps you decide which modules suit a platform and which should stay in-house.
Core Capabilities
1. Web Search
Web search addresses the problem that a model’s training data becomes outdated. A typical flow has three steps. First, the model decides whether the question needs external information. If it does, the system runs a search and gets result summaries. Finally, the model generates an answer using those results and their source links, so the answer can be traced back to its sources.
Three points matter in practice. First, set sensible trigger conditions so the system does not make unnecessary external calls. Second, keep returned content traceable and preserve source links in the answer. Third, filter results by recency, especially in sensitive domains such as finance and healthcare.
In multi-step reasoning, the model may search, read a page, and then decide whether to search again. Set limits on the number of reasoning rounds and the total response time to prevent the process from looping.
2. File Input
File input usually covers PDFs, office documents, and images. The system typically handles them in two ways. Plain text extraction works for text-based documents and is fast and inexpensive. Layout-aware parsing works for scanned files and documents with tables and charts, and it combines layout analysis with OCR. The extracted text is added to the conversation context in its original order, and the model answers based on it.
A few implementation details matter. Long documents must be split into chunks, and the structural information, such as page numbers and heading levels, must be preserved. Otherwise, the model cannot locate the source of a citation. Table extraction often misaligns columns, so sample and verify the output before launch. For files that contain personal data, clear the cached copies promptly after server-side processing finishes.
3. Link Reading
When a user message contains a link, the system can fetch the page body, remove unrelated content such as navigation bars, ads, and scripts, and pass the cleaned text to the model together with the conversation context.
Two risks need controls. First, the target URL may point to an internal address. Use an allowlist or block requests to private network addresses to prevent server-side request forgery. Second, a page may contain text designed to manipulate the model. Treat page content as data, not as instructions, to prevent prompt injection.
4. Speech Capabilities
Speech features usually fall into three separate modules. Automatic speech recognition (ASR) converts audio to text. Text-to-speech (TTS) converts text to audio. OCR extracts text from images. Each module can be called on its own, for example, to transcribe a recorded meeting. The three can also be combined into a voice assistant pipeline: record audio, convert it to text, send the text to the model, and convert the model’s reply back to speech for playback. In a combined pipeline, watch the end-to-end latency. Streaming recognition and streaming synthesis can noticeably improve the interaction experience.
5. Content Safety Checks
Safety checks typically run on both input and output. The input check detects policy-violating prompts, and the output check filters inappropriate content. When a risk is detected, return a clear refusal flag so the business side can show a message or route the case to a human reviewer. Keep safety parameters enabled by default, and log the interceptions so you can tune the policies later.
Server-Side vs. Client-Side Orchestration
You can implement the same set of capabilities in two ways. In server-side orchestration, the API provider decides when to call search, when to parse files, and how to assemble the context. In client-side orchestration, the business side implements tool scheduling and message assembly itself.
Server-side orchestration is faster to integrate and requires less maintenance. It suits general conversational scenarios, but the call chain is less transparent, so debugging depends on platform logs. Client-side orchestration gives you more control. You can define caching strategies, permissions, and data flows precisely. It suits businesses with strict compliance requirements or heavily customized workflows. When choosing between them, compare three factors: development timeline, observability requirements, and data residency requirements.
Sample Workflow: Question Answering with Web and File Support
The pseudocode below shows the overall flow. The function names illustrate the logic only and do not correspond to any specific SDK.
def answer(user_msg, files, history):# 1. File parsing: try plain text extraction first, and fall back to layout-aware parsing on failuredoc_chunks = []for f in files:text = extract_text(f) or parse_with_layout(f)doc_chunks.extend(chunk(text, max_tokens=800))# 2. Detect links and fetch them under controlled conditionsurls = find_urls(user_msg)web_pages = [fetch_clean(u) for u in urls if is_allowed(u)]# 3. Assemble the context. Treat file and web content as data.context = build_context(history, user_msg, doc_chunks, web_pages)# 4. Call the model, search the web when needed, and cap the number of stepsreply = model.generate(context, tools=["web_search"], max_steps=5)# 5. Check the output for safety issuesif reply.blocked:return "This request cannot be processed at the moment. Please adjust your question and try again."return reply.text_with_citations()
The flow reflects three principles. Normalize the input first. Bring in external content under controls. Check the output before returning it.
Engineering Practices
- Context management: Conversation history keeps growing. Trim it by turn. Keep the full content of the most recent few turns, and compress older content into a summary.
- Timeouts and retries: Search, fetching, and file parsing can all fail. Set a separate timeout for each step. After a failure, fall back to an answer that does not depend on external information, and tell the user clearly that this happened.
- Citations and credibility: Factual statements in an answer should include sources. Display the sources as clickable links in the user interface.
- Observability: Log the type, duration, number of results, and interception status of each tool call. These logs make issues easier to locate.
- Cost control: Trigger search and parsing only when needed. Cache repeated links and identical files to reduce unnecessary calls.
Compliance and Responsibility
When you offer a generative AI service to the public, you must meet the content safety review, filing or registration, and AI-generated content labeling requirements that apply in the regions where the service operates. Build these requirements into the design. Enable safety checks, keep audit logs, and clearly label AI-generated content in the interface. For user-uploaded files and personal information, define how long the data is retained, and provide a way for users to delete it.
Summary and Checklist
The key to building a conversational application is not adding more features. It is defining the trigger conditions, data boundaries, and failure strategy for each capability. Before launch, check the following items:
- Web search has trigger conditions and a limit on the number of rounds.
- File parsing preserves structural information, and the output has been verified by sampling.
- Link fetching blocks access to internal network addresses.
- External content is treated as data to prevent prompt injection.
- Output passes a safety check, and interceptions are logged.
- Source display and AI content labels are provided.
Following this checklist helps you implement a basic conversational experience in your own system with reasonable reliability.
