Building an All-in-One AI Assistant: Web Search, File Analysis, and Voice Through a Unified API
This article explains how a unified model API can connect web search, web page reading, file analysis, OCR, speech recognition, speech synthesis, and content safety review in one request pipeline. It covers the tool-calling flow, the design considerations for each capability, and a recommended architecture that addresses cost, observability, and security.
In recent years, the competition among large model applications has shifted from “can it generate text” to “can it complete tasks.”
A truly useful intelligent assistant needs to do more than answer questions. Depending on user intent, it may need to proactively search for up-to-date information, read web pages, analyze uploaded files, recognize speech, generate spoken replies, and apply privacy protection and content safety review throughout the process. In the past, developers often had to integrate a search service, a web scraping component, a file parsing tool, a speech recognition service, a speech synthesis service, and a content safety module separately. This made the system complex and costly to maintain.
Some model service platforms now expose these capabilities through a unified API. Developers only need to declare the available tools in a chat request. The server then decides whether to call a given capability based on context, and automatically organizes the tool results before passing them back to the model for further reasoning. The core value of this approach is not just adding a few more endpoints. It integrates the model, the tools, and context management into one complete pipeline.
1. From Single-Turn Q&A to Task-Oriented AI Applications
A traditional large model call is usually simple:
- The client submits a user question.
- The model generates text.
- The client displays the result.
This pattern suits tasks such as writing, summarization, and translation. However, for requests like “check today’s weather,” “summarize the key points of a report,” “analyze an uploaded contract,” or “complete an action based on a voice command,” the model cannot access external information on its own.
After server-side tools are introduced, the flow becomes:
- The user submits a natural language request.
- The model decides whether an external tool is needed.
- The server runs a search, reads a web page, or processes a file.
- The tool results are returned to the model.
- The model combines the original question and the tool results to generate an answer.
- The client displays the text, citations, audio, or structured results.
In effect, this forms a lightweight AI agent system. The model handles intent understanding and answer organization. The tools retrieve facts and perform actions. The application layer manages permissions, state, auditing, and presentation.
2. A Unified Approach to Tool Calling
In engineering practice, it is generally not recommended to hard-code search and web scraping logic throughout business code. Instead, tool declarations tell the model which capabilities are currently allowed.
The following neutral pseudocode example shows the basic calling pattern:
from ai_sdk import Clientclient = Client(api_key="YOUR_API_KEY",endpoint="https://api.example.com")response = client.chat.create(model="general-purpose chat model",messages=[{"role": "system","content": "Answer in Chinese, and clearly distinguish known information from real-time search results."},{"role": "user","content": "Check today's weather in a certain city and give travel recommendations."}],tools=[{"type": "web_search"},{"type": "read_webpage"}])print(response.content)
The key point is the calling pattern, not the specific field names:
modelspecifies the chat model.messagesholds the system instructions, conversation history, and the user’s question.toolsdeclares the server-side tools the model may use.- The server decides whether to search based on the question.
- The response typically includes the model’s reply, tool call records, or citations.
In real projects, pay close attention to tool call records. They show whether the model called search, which sources it used, whether retrieval succeeded, and whether the final answer was based on the tool results.
3. Web Search vs. Web Page Reading
Web search and web page reading often appear together, but they serve different purposes.
1. Web Search
Search answers the question of where to find information. The model generates query terms from the user’s question, filters relevant results from public sources, and extracts titles, summaries, sources, and links.
It suits scenarios such as:
- Looking up real-time news or public information;
- Finding recent policies, events, and industry updates;
- Searching for resources on a technical problem;
- Producing a preliminary summary across multiple sources.
Search results are usually summary-level and do not guarantee coverage of the full content of each page. For complex material such as legal provisions, technical documentation, or research reports, do not rely on search snippets alone.
2. Web Page Reading
Web page reading answers the question of how to understand specific content. The system fetches a given page, extracts and cleans the main text, structures it, and passes it to the model for analysis.
It suits scenarios such as:
- Summarizing a specific article;
- Extracting tables and key conclusions from a web page;
- Comparing viewpoints across multiple pages;
- Answering specific questions based on one document.
Web page reading can be affected by login requirements, dynamic rendering, anti-scraping mechanisms, page structure, and access permissions. Engineers should therefore prepare fallback options for read failures, such as asking the user to upload a file or to paste the text directly.
4. File Input and Document Analysis
File analysis is a practical capability for intelligent assistants, but uploading a file does not mean the model can directly understand every file format.
A complete file processing pipeline generally includes:
- Identifying the file type;
- Detecting viruses and malicious content;
- Extracting text;
- Running OCR on images or scanned pages;
- Recognizing table structures;
- Splitting content into segments;
- Generating an index or temporary context;
- Submitting the content to the model for analysis.
Plain text files can have their text extracted directly. PDFs, scanned documents, and images may require OCR. For spreadsheets, reading cells is not enough. The system must also preserve row and column relationships, merged cells, and formula information. Otherwise, the model may misread the data structure.
File analysis is also constrained by context length. For large files, avoid sending the entire content in one request. Process it in chunks instead:
Raw file↓Text extraction and cleaning↓Split by section or semantic unit↓Select segments relevant to the question↓Send to the model for analysis↓Aggregate results across segments
For enterprise applications, record each file’s source, upload time, operator, and access permissions. This prevents data from being read across different users.
5. The Complete Pipeline for Voice Input and Output
Voice features generally consist of two directions:
- Speech recognition: converting audio into text;
- Speech synthesis: converting text into audio.
The typical voice input pipeline is:
Recording↓Audio format check↓Speech recognition↓Text correction and segmentation↓Submit to the chat model
Speech recognition accuracy depends on ambient noise, speaking speed, dialects, domain-specific terminology, and multiple speakers talking at once. For customer service, healthcare, and legal scenarios, keep both the original audio and the recognized text, and allow manual correction.
The voice output pipeline is typically:
Model generates text↓Text segmentation↓Speech synthesis↓Streamed audio playback
To reduce wait times, use streaming output. Once the model generates a segment of text that can be played, synthesize it immediately instead of waiting for the full response. Keep sentences at a reasonable length to avoid frequent inter
