Server-Side Tool Calling for LLMs: A Practical Guide

    This guide walks through the shift from client-side retrieval pipelines to server-hosted tool calling, covering thinking-on versus thinking-off interaction patterns, protocol compatibility and tool declarations, the multi-turn state pitfall, sampling parameter side effects, and the cost structure of file parsing. It closes with a deployment checklist for routing modes by scenario and building observability around tool calls.

    1. From Client Pipelines to Server Hosting: Where the Architecture Center Moves

    To add “search the web” answers to a chat application, developers used to build a full retrieval-augmented pipeline themselves: call a search API for candidate links, fetch each page’s body text, clean and denoise it, chunk it, splice the extracted text into the context, and only then let the model generate an answer. Every stage in that chain carried engineering cost. Search quotas, fetch timeouts, body-extraction failures, and context truncation were all hidden burdens that needed ongoing maintenance.

    Server-side tool calling pulls that tedious work into the model. The client no longer decides whether to search, how many rounds to search, or which links to fetch. It submits the user’s question together with the tool declarations, and the model decides the call order and when to stop on its own during inference. In effect, a deterministic orchestration logic is replaced by dynamic, model-driven decisions, and the engineering complexity moves up from the application layer to the model serving layer.

    The important caveat: this migration does not mean the client can do nothing. Quite the opposite. The client’s responsibility changes from “implementing the pipeline” to “maintaining session state and protocol correctness,” and the latter requirement is more subtle and easier to overlook.

    2. Typical Interaction Shapes: Thinking Off vs. Thinking On

    With deep thinking turned off, the model behaves close to a one-shot retrieval Q&A: it issues a web search or an image search as needed, answers directly once results arrive, and includes source citations in the reply. This mode has low latency and predictable behavior, which suits latency-sensitive scenarios such as customer support Q&A and fact-checking.

    With deep thinking turned on, searches are interleaved into the reasoning chain, producing a “reason and fill gaps as you go” shape. Take comparing the heights of two landmark buildings: the model’s typical sequence is to run one broad search for candidate information, open the relevant official pages to pin down specific numbers, and if a single fetch does not cover every field it needs, search within the page, swap in different keywords for a second pass, and keep going until the evidence is sufficient before converging on an output. Tool calls across the whole process can reach the order of a dozen or more, so this mode fits high-value, low-frequency analytical requests rather than hot paths under high concurrency.

    Practical advice: expose the two modes as configurable tiers to the business layer above, and let the scenario pick the tier instead of enabling deep thinking globally.

    3. Protocol Compatibility and Tool Declarations

    mainstream API access methods are usually compatible with several common message protocol shapes, including Messages style, Responses style, and Chat Completions style. This means the cost of adapting existing code is low: in most cases you only swap the service endpoint and the model identifier, and fill in the tool declarations according to the field structure of the corresponding protocol.

    For tool declarations, one retrieval tool handles web search and image search, and one read tool handles fetching the body text of links the user actively provides. A sketch of the tool definitions follows (field names follow the actual protocol; this only expresses the structure):

    1. {
    2. "tools": [
    3. {
    4. "type": "web_search",
    5. "web_search": { "enable_image_search": true }
    6. },
    7. {
    8. "type": "read_url",
    9. "read_url": { "max_chars": 20000 }
    10. }
    11. ]
    12. }

    4. The Biggest Pitfall: Multi-Turn State Must Be Passed Back Verbatim

    Beyond the final text, the content blocks returned by the server may also include thinking blocks, search result blocks, and web page fetch result blocks. On the next request these blocks must be passed back verbatim and in order. They cannot be rewritten, compressed, or dropped.

    Many teams insert a self-built gateway in the middle for auditing, redaction, or format conversion. If that gateway filters on the assumption that it only needs to keep text content, the request still returns a success status code, but the model has already “forgotten” the pages it saw in the previous turn. The symptoms are repeated searches, self-contradictory answers, or lost citations. There is no error to trace, so the debugging cost is very high.

    The way to avoid this is to distinguish content block types explicitly at the gateway layer and pass through unknown types rather than dropping them:

    1. ALLOWED = {"text", "thinking", "search_result", "url_content"}
    2. def sanitize(blocks):
    3. # Pass through unknown block types to avoid silently losing session evidence
    4. return [b for b in blocks if b.get("type") in ALLOWED or b.get("type", "").startswith("server_")]

    It is also worth adding a regression case in the test environment: construct a two-turn conversation, and in the second turn assert that the number of retrieval-type content blocks from the first turn in the request body matches the original.

    5. Side Effects of the Server Taking Over Sampling

    When a request enables tool calling, automatic title generation, or a higher safety level, the server takes over the sampling schedule, and sampling parameters explicitly set in the request, such as temperature and top_p, are ignored. The reason is that tool calling and multi-step retrieval need a stable decision path; too much randomness breaks the continuity of the call sequence.

    The direct impact on developers is that the common trick of lowering temperature to stabilize structured output stops working. The constraint has to move forward into the prompt and protocol layers instead: use explicit output format instructions, field enumerations, and validation with retries to guarantee structure, rather than counting on sampling parameters. If you genuinely need controllable randomness, consider splitting those requests onto a different path from tool-calling requests.

    6. The Cost Structure of File Parsing: Two Modes and How Billing Works

    File types billed per page typically include PDFs, word processing documents, presentations, and images. Parsing comes in two tiers: plain text extraction and layout-aware parsing.

    Take a financial report. Plain text mode only takes the text layer, so a revenue trend chart in it is discarded entirely, the model sees no chart information, and questions about the chart can only get guesses based on the body text. The layout-aware mode crops out chart regions and reinserts them at the corresponding positions in the original text, so the model can read the graphical content. But the cropped images are billed as image input tokens, and chart detection is automatic, so some charts may be missed; whatever is missed stays invisible to the model.

    Selection advice: use layout-aware parsing for documents with high chart information density, and spot-check key pages manually; use plain text mode for pure-text contracts and meeting notes to control cost. If document volume is large, route by document type rather than applying one tier globally.

    7. Deployment Checklist

    • Define scenario tiers: latency-sensitive paths use thinking off, analytical paths use thinking on.
    • Pass unknown content blocks through at the gateway, and add a regression assertion for multi-turn pass-back.
    • Do not rely on sampling parameters to control output structure; use protocol constraints and validation with retries.
    • Route parsing modes by document type, and spot-check layout-aware results on key pages.
    • Build observable metrics for tool call counts, retrieval hit rate, and parsing cost to make later tuning easier.