Server-Side Tool Orchestration: Integrating Web Search and Document Understanding into LLM Workflows
This article explores the shift from client-side retrieval pipelines to server-side tool invocation in large language model (LLM) applications. It compares non-thinking and thinking modes of tool use, details the critical requirement of preserving complete assistant message blocks in multi-turn conversations, and explains how sampling parameters are overridden in tool-enabled contexts. A practical breakdown of document parsing—plain text extraction versus layout parsing—helps developers choose the right mode for cost and accuracy. The article also covers voice integration, frontend security considerations such as SSRF prevention, and a pre-launch checklist covering timeouts, logging, and historical message integrity.
Introduction: Why Move Tool Invocation to the Server Side
Previously, developers who wanted models to answer questions requiring real-time information had to build their own retrieval pipeline. The typical flow involved determining whether a search was needed, calling a search API, fetching individual pages, extracting main content, trimming length, and appending everything into the prompt. Each step was prone to failure—timeouts, extraction errors, or context windows being exceeded.
The server-side tools approach moves this workflow to the model provider’s infrastructure. The client simply declares which tools are available and sends the user’s question. Whether to search, how many rounds of retrieval to perform, and which pages to read are determined by the model’s own reasoning process. The client receives the final answer along with attached source citations.
This approach lowers the integration barrier but also hands a degree of control to the server side. Understanding this division of responsibility is essential to using this capability correctly.
Two Working Modes
Server-side behavior differs notably depending on whether thinking is enabled.
Without Thinking Mode
The model tends to make decisions in one pass. When faced with time-sensitive or image-related questions, it triggers web search or reverse image search, then composes an answer with citations at the end. This mode responds quickly and suits factual lookup scenarios.
With Thinking Mode Enabled
In thinking mode, the model interleaves retrieval throughout its reasoning process. It may search first, then open relevant pages to read specific figures. If it finds the information incomplete, it searches within the page or refines its query and retrieves again, continuing until it has sufficient evidence to produce a final answer.
Using a comparison of two tower heights as an example, the typical process looks like this:
- Search for basic information about the two towers.
- Visit authoritative pages and read height data.
- When a specific data point is missing, search within the page for keywords like “height” or “meters.”
- Once data is complete, compute the difference and provide a conclusion.
In one demonstration scenario, a single response triggered more than a dozen tool calls in succession. This means latency and cost scale with the number of calls. Clients should set timeouts and maximum round limits to prevent abnormal tasks from consuming resources indefinitely.
Multi-Turn Conversations: Preserving Complete History
The server-side response includes more than plain text. It contains reasoning blocks, search request blocks, and page retrieval result blocks. These blocks record what the model has “seen” and serve as the basis for subsequent reasoning.
In multi-turn conversations, the client must place all of these blocks from the previous turn back into the message history unchanged. If an intermediate gateway filters these blocks to simplify the structure, the request will still succeed, but the model will lose its memory of previously retrieved pages, resulting in repeated searches or answers that drift from the context. This issue is subtle because it produces no error messages.
The following code pattern is recommended:
# Example: preserve the full assistant message, not just the text portionhistory.append({"role": "assistant","content": response["content"], # Includes text, reasoning, tool calls, tool results, etc.})# Send the next request with the history maintaining its original structuremessages = history + [{"role": "user", "content": next_question}]
In gateways or middleware layers, add structural assertions that verify block types in the history are complete, rather than only checking that the request succeeds.
Sampling Parameters Are Controlled by the Server
When a request enables tool calling, automatic conversation title generation, or higher security levels, the server takes over the generation rhythm. In such cases, client-provided sampling parameters like temperature and top_p may be silently ignored.
This is easy to overlook. A developer tunes parameters locally, deploys to a tool-enabled environment, and notices the output style has changed with no obvious cause.
The guiding principles are:
- Consult the API documentation to determine which parameters remain effective in tool mode.
- Do not rely on sampling parameters for output stability; use prompt instructions to constrain output format instead.
- For steps requiring deterministic output, use a separate request path without tools enabled.
Document Understanding: Trade-Offs Between Text Extraction and Layout Parsing
The server side supports document parsing for PDF, Word, PPT, and images, billed per page. Two parsing modes differ significantly in cost and effectiveness.
Plain Text Extraction
This mode extracts text only. It is low-cost and fast, making it suitable for scenarios like contract clause retrieval or article summarization where only text matters.
The trade-off is that chart and image information is lost. For example, in a financial report, revenue trend charts or composition pie charts will not enter the context. If a question asks about chart values, the model can only respond that the information is not mentioned in the text—without explaining that the parsing mode is the reason.
Layout Parsing
This mode identifies images and charts within pages, crops them, and inserts them back into the text flow at their original positions. The model can therefore read chart content.
Layout parsing introduces two additional costs:
- Cropped images are counted as image input tokens. With more pages and more charts, costs rise noticeably.
- Chart detection is automatic. If a chart is not identified and cropped, the model still cannot see it—and no error is raised.
Mode Selection Recommendations
A simple decision rule:
- Questions only about body text: choose plain text extraction.
- Questions involving charts, diagrams, or layout information: choose layout parsing.
- Batch processing large numbers of documents: run plain text extraction first for coarse screening, then apply layout parsing to matched documents.
Before going live, sample and verify parsing results, focusing on whether charts were extracted and whether the image-text order is correct.
Integrating Voice Capabilities
Speech-to-text (dictation) and text-to-speech (reading aloud) are typically enabled through request parameters. The client is responsible for audio capture and playback.
Key implementation considerations:
- Audio format and sample rate must match the API requirements. If they do not, transcode on the client side first.
- For long audio, consider uploading in segments and displaying intermediate results to reduce perceived wait time.
- Before reading text aloud, clean the text by removing Markdown symbols, code blocks, and citation numbers so that meaningless characters are not spoken.
Frontend and Security
A demonstration frontend can run as a static page, but in production environments, long-term API keys should not be embedded in browser pages. The more secure approach is:
- Use a backend service to proxy model requests, keeping keys in server-side environment variables.
- Apply a whitelist or protocol validation to user-supplied links to prevent the server from being induced to access internal network addresses (server-side request forgery, SSRF).
- Validate citation links returned by the model before displaying them, avoiding clicks to unknown domains.
When the server reads user-provided links, it is essentially making network requests on the user’s behalf and should be reviewed under the same security standards.
Pre-Launch Checklist
Before going live, verify the following items:
- Whether the message history preserves all returned blocks completely.
- Whether sampling parameters behave as expected in tool mode.
- Whether tool calls have a maximum round limit and an overall timeout.
- Whether the document parsing mode matches the business use case and whether sample verification has been performed.
- Whether link reading goes through a whitelist and blocks internal network addresses.
- Whether logs record the number of tool calls, enabling cost tracking and anomaly troubleshooting.
Conclusion
Server-side tool invocation moves retrieval, fetching, and parsing into the model service, reducing client-side pipeline code. But control is not entirely transferred. Developers still need to pay attention to preserving historical blocks in message history, the server’s takeover of sampling parameters, and the cost and missed-detection risks of document parsing. Embedding these details into design and testing is what turns this capability into reliable product value.
