Server-Side Tool Orchestration for LLM APIs: Web Search Integration Best Practices

    This article explains how model platforms are moving web search, URL reading, multimodal parsing, and speech tools from client-side pipelines into server-side orchestration. It covers capability layers, dynamic multi-round tool loops, protocol-compatible integration, structured tool-result pass-through, open-source frontend and session migration, and an engineering checklist for observability, cost, reliability, security, evaluation, and capability detection.

    Recently, a model service platform made a valuable engineering update: it moved a set of tools that previously existed only in its web and mobile apps to the API side, and also open-sourced a chat frontend. For developers, this significantly lowers the cost of building “chat with web access.” In the past, teams had to build their own retrieval, fetching, extraction, and context-injection pipelines. Now that work can be pushed down to the server side. This article does not focus on any specific product. Instead, it frames the update as a general technical question: when a model service takes tool orchestration server-side, how should clients and gateways be designed to save effort without stepping into pitfalls?

    1. Capability Layers: What Exactly Is Being Opened Up

    The capabilities described in announcements and documentation can be grouped into four layers:

    • Retrieval layer: web search and reverse image search. The server decides whether to search, how many rounds to run, and which query terms to use.
    • Reading layer: fetch the body text from a given URL and convert an unstructured web page into text that can enter the context.
    • Multimodal parsing layer: document parsing and image content understanding, turning attachments into semantic fragments that the model can read.
    • Speech layer: dictation (speech-to-text) and read-aloud (text-to-speech), completing both the input and output sides.

    The common feature of these four layers is that they are not capabilities of the model weights themselves, but external tools around the model. In the past, developers had to implement scheduling logic for these tools on the client. Now scheduling authority has been handed to the server side. This is the most fundamental change in this update, and it is the starting point for all engineering conclusions below.

    One caveat is necessary: updates like this often have differences in specification coverage. New tools are often first opened on a lightweight specification, while flagship specifications follow later. Before integration, you must confirm whether the target model specification supports tool orchestration, and you should build “capability detection + graceful degradation” into the architecture. Do not hardcode tool calls as a global assumption.

    2. Server-Side Orchestration: How Reasoning and Retrieval Interleave

    The traditional approach is a one-way pipeline: retrieve first, then stitch, then generate. Server-side orchestration changes it into a model-driven multi-round loop:

    1. The client sends only the user question, along with tool declarations.
    2. The model decides whether retrieval is needed, and if so, initiates a tool call.
    3. The server executes retrieval or fetching and injects the result back as a tool result block.
    4. The model continues reasoning based on the new evidence. If the information is insufficient, it changes query terms, performs in-page search, or checks source sites again.
    5. Once the evidence is sufficient, it closes the loop and outputs an answer with source citations.

    When thinking mode is off, this loop is relatively “shallow”: it usually converges after one or two retrieval rounds. When thinking mode is on, retrieval is interleaved into the reasoning chain, forming a deep search pattern that “searches while reasoning.” A typical public demo example is comparing the heights of two landmark buildings: the model first runs a broad search, then opens each official page to find the numbers. If it does not find everything, it searches within the page by keyword and changes keywords to fill gaps. It may make more than ten consecutive tool calls before closing the loop.

    This leads to two lessons that must be internalized:

    • Latency is a variable, not a constant. The number of tool rounds is decided dynamically by the model, so end-to-end latency will show a long-tail distribution. Timeout and streaming design must budget for the worst-case round count, not the average round count.
    • The termination condition is on the server side. The client cannot predict how many times tools will be called. Therefore, do not try to control the number of rounds on the client. Budget control should be delegated to server-side parameters and quota policies.

    3. Integration: Protocol Compatibility First

    The key to reducing integration friction is protocol compatibility. The mainstream approach is to make the server compatible with several common message-style API protocols at the same time (chat-completion style, response-object style, and message-list style). Developers can reuse existing SDKs and calling code, and only need to add tool declaration fields. An example is shown below:

    1. {
    2. "model": "<target model spec>",
    3. "tools": [
    4. { "type": "web_search" },
    5. { "type": "read_url" }
    6. ],
    7. "messages": [
    8. { "role": "user", "content": "Find public technology news from the past week and summarize it." }
    9. ]
    10. }

    Keep tool declarations minimal: attaching only retrieval and URL reading can cover most web-enabled Q&A scenarios. Attachment parsing and speech capabilities should be enabled separately according to business needs, to avoid unnecessarily expanding the attack surface and billing surface.

    4. The Biggest Pitfall: Tool Result Blocks Must Be Passed Back Unchanged

    The documentation specifically flags a constraint that is easy to overlook: thinking blocks, search result blocks, and page fetch result blocks returned by the server must be passed back unchanged in the next conversation turn.

    The reason is not hard to understand. These blocks are the carrier of the model’s “memory.” If an intermediate self-built gateway or proxy filters them out for trimming, redaction, format validation, or other purposes, the request may still return a success status code, but the model will “lose memory.” Web page content it just saw disappears into thin air, answer quality drops sharply, and no error is reported, no log is written, and the issue is extremely hard to locate.

    1. # Bad: keep only plain text and discard structured blocks
    2. clean = [{"role": m["role"], "content": m["content"] or ""} for m in history]
    3. # Good: pass structured blocks through as a whole, with only necessary length trimming
    4. def trim(history, max_chars):
    5. out, budget = [], max_chars
    6. for m in reversed(history):
    7. size = len(str(m.get("content", "")))
    8. if budget - size < 0 and out:
    9. break
    10. budget -= size
    11. out.append(m)
    12. return list(reversed(out))

    Engineering advice: make “block pass-through” an explicit gateway contract, and add return integrity validation to the link (compare the set of block types in the previous response with the set of block types in the next request). If a block is missing, alert immediately instead of waiting for a business team to report that “the answers got dumber.”

    5. Open-Source Frontend and Session Migration

    Open-sourcing the chat frontend at the same time has practical value: it returns the “last mile” to developers. You can try it online directly, or download an archive, open it locally, fill in a key, and use it. A more useful point is support for importing session archives previously exported from the official site and continuing the conversation. This solves the data continuity problem when moving from trial use to a formal product.

    From an architecture perspective, an open-source frontend also brings three benefits: first, interaction patterns (streaming rendering, citation tracing, and reasoning-process folding) can be reused directly; second, it makes private customization and compliance adaptation easier; third, the session structure can serve as a reference implementation of the frontend-backend data contract. During implementation, it is advisable to decouple session storage from the frontend, use object storage for archives, and use a cache service to accelerate hot sessions. Avoid keeping state in browser local storage.

    6. Engineering Implementation Checklist

    • Observability: instrument tool round count, retrieval latency, fetch success rate, and citation hit rate separately, and use logging and monitoring alerts to locate long-tail requests.
    • Cost control: set round and frequency limits for retrieval tools, cache results for frequently repeated queries, and restrict “deep search” to high-value scenarios.
    • Stability: server-side tools depend on external web pages, so preset fallback wording and backup answers for fetch failures, page structure changes, rate limiting, and other exceptions.
    • Security and compliance: fetched content is untrusted input, so guard against prompt injection; validate the type and size of user-uploaded documents and images; apply domain allowlists or risk warnings to external links.
    • Evaluation system: build an evaluation set with standard answers and source annotations, measure correctness, citation accuracy, and end-to-end latency separately for “thinking off” and “thinking on” modes, and use it as a regression baseline during specification upgrades.
    • Capability detection: at startup, detect whether the target specification supports tool orchestration. If it does not, automatically fall back to a client-side self-built retrieval pipeline to ensure availability.

    7. Conclusion

    The real significance of this update is not that there are a few more tools, but that tool orchestration authority has moved from the client to the server. Developers save pipeline code, but give up fine-grained control over the retrieval process. Therefore, the integration strategy should be: at the protocol layer, use compatible interfaces to minimize changes; at the context layer, strictly honor the structured block pass-through contract; at the governance layer, add observability, cost, and security guardrails. If you are already building applications with Baidu AI Cloud model services and general cloud products such as object storage, cache, message queues, logging, and monitoring, the layering and checklist above also apply. First make the contracts and observability solid, then talk about experience upgrades.