Server-Side Tool Calling for LLMs: Web Search and Document Parsing Practices

    Server-side tool calling streamlines the integration of web search and reasoning capabilities into LLM applications by centralizing the retrieval pipeline. This article explores the background of shifting retrieval logic to the server side, compares two operating modes—deep reasoning enabled versus disabled—and outlines four critical practices for integration design, including protocol selection, tool permission scoping, and conversation state management. It also discusses the trade-offs between plain text extraction and layout-aware document parsing for handling uploaded files.

    1. Background: Why Hand Over the Retrieval Pipeline to the Server Side?

    In the past, when building conversational applications with internet capabilities, developers typically had to maintain an entire pipeline themselves. The process generally included determining whether retrieval was needed, calling the search API, fetching candidate pages, extracting the main text, truncating the length, and finally splicing the results into the prompt. Every step was prone to failure. For instance, anti-scraping mechanisms could cause fetch failures, text extraction might mistakenly include navigation bar text, or the concatenated content could exceed the context length limit.

    Server-side tool calling consolidates this workflow to the model side. The client only needs to submit the query and a declaration of available tools, while the server side decides whether to retrieve, how many rounds of retrieval to perform, and when to stop. The benefits are straightforward: reduced client-side code volume and centralized management of retrieval strategies. The trade-off is that the intermediate process becomes a black box, reducing client-side control, which necessitates adding observability back into the integration design.

    2. Two Operating Modes

    2.1 Deep Reasoning Disabled

    The model calls web or image search on demand and provides an answer accompanied by source citations. This mode features lower latency and is suitable for factual queries, recent news, and single-point knowledge Q&A.

    Two points require attention during implementation. First, the cited sources should be displayed to the user along with the retrieval time to prevent them from treating outdated information as current. Second, the credibility of different sources varies significantly; the weighting of official pages versus forum posts should be differentiated, and source types can be annotated on the frontend.

    2.2 Deep Reasoning Enabled

    During the reasoning process, the model can interleave retrieval actions, continuing to fetch additional information once a gap is identified. Take comparing the altitudes of two towers as an example. A typical path for the model is: first search for general information, then open an authoritative page to find specific values. If the target numbers are not present, it will search for keywords within the page or change the search terms to query again, only outputting the conclusion once the information is complete.

    This mode is most valuable for multi-hop questions but also introduces uncertainty. A single task may go through multiple rounds of tool calls, increasing both time and cost. Engineering-wise, it is necessary to set a total time limit and observe the number of calls, returning partial conclusions upon timeout rather than making the user wait for an extended period.

    3. Four Key Points for Integration Design

    3.1 Choose the Interface Protocol

    Mainstream conversational interfaces can generally be categorized into three types: a message format based on content blocks, a format based on response items, and a classic format centered on roles and text. Teams should prioritize protocols already supported by their existing gateways or SDKs, avoiding rewriting the entire calling layer just for a single feature.

    3.2 Follow the Principle of Least Privilege When Declaring Tools

    Tool declarations should only include capabilities essential to the business. For example, a customer service Q&A application typically only requires two capabilities: web search and link reading, without needing any write operations enabled. Tool descriptions must clearly state their purpose and input format, as the model relies on these descriptions to decide when to call a tool.

    3.3 Fully Save and Return Conversation State

    This is the most error-prone part of the integration. The content returned by the server typically contains various blocks: the model’s reasoning process, search requests and results, page reading results, and the final text. When entering the next round of conversation, these blocks must be returned as-is so the model can see which pages it has previously read.

    If there is a custom gateway in between, a common issue is filtering content blocks based on a whitelist, keeping only the text. This practice will not cause the request to fail, making it hard to detect. However, in subsequent rounds, the model will exhibit behavior indicating it has “forgotten” previous retrieval results.

    It is recommended to treat the history as an opaque data structure:

    1. history = []
    2. def chat_turn(user_text):
    3. history.append({"role": "user", "content": user_text})
    4. resp = call_model(messages=history, tools=TOOL_SPECS)
    5. # Save all content blocks as-is without type filtering
    6. history.append({"role": "assistant", "content": resp.raw_content_blocks})
    7. return resp.text_output()

    Before going live, a regression test should be added: construct a follow-up question that requires citing previous search results to verify whether the second round’s answer still references the sources from the first round.

    3.4 Sampling Parameters Are Managed by the Server Side

    When the server side takes over the retrieval and reasoning rhythm, common parameters in client requests such as temperature and top-p sampling may be ignored. Developers cannot rely on these parameters to adjust the output style. The alternative solution is to constrain the format and tone through prompts and use a fixed test set to verify output stability.

    4. Document Parsing: Trade-offs Between Plain Text and Layout Parsing

    When uploading PDFs, Word documents, presentations, or images, there are generally two parsing modes.

    Plain text extraction outputs only text. It is cost-effective and fast. The downside is that charts, formatting, and image information are entirely lost. Taking a financial report as an example, if only text is extracted, the revenue trend charts become completely invisible, and the model can only answer based on the descriptions in the main text. However, the main text often only provides conclusions without data details.

    Layout parsing identifies chart regions, crops them, and inserts the images back into their original positions in the text. It comes with two costs. First, the cropped images will be output as image inputs