Tool Calling for Large Language Models: Capabilities and Engineering Practices

    This article explains how large language model APIs are evolving from simple chat completion endpoints into full capability APIs that bundle built-in tools and a chat interface. It breaks down server-side tool execution, contrasts thinking and non-thinking search behavior, outlines common message protocols and a sample request structure, and highlights three frequent pitfalls: passing context blocks back unchanged, sampling parameters being overridden, and per-page document parsing costs. It closes with practical guidance for placing a self-managed gateway between applications and models to handle protocol conversion, context validation, capability routing, and observability.

    1. The Shift: From Model APIs to Capability APIs

    When developers integrated a large language model in the past, they typically received only a chat completion endpoint. Any capability involving web access, reading web pages, parsing attachments, or speech transcription and synthesis had to be built into a full pipeline on the client or server side. A recent wave of updates in the industry moves these toolchains—previously hidden behind vendors’ own applications—down into the API layer, while also open-sourcing the chat front end. Users can download an archive, open a local page, enter an API key, and run it. Some setups even support importing an official conversation export to continue an existing session. The essence of this change is that the delivery unit of the API has been upgraded from “model weight capabilities” to a complete loop of “model + tools + interactive interface.”

    Keep in mind that such updates often become available first on lightweight or fast-iterating model tiers, with flagship tiers following later. In addition, conditions such as tool calling, automatic title generation, and high security levels trigger server-side takeover of the sampling schedule, causing parameters declared in the request, such as temperature and top_p, to be ignored. When making technology choices, developers should evaluate both the “scope of available capabilities” and the “scope of controllable parameters.”

    2. What the Server Now Handles

    Running tools on the server eliminates the repetitive work of “retrieve—fetch—extract—inject into context.” That pipeline used to require handling deduplication, main-content extraction, timeout retries, citation alignment, and many other details. Now the client only submits a question, and the model decides whether to search and how many rounds to run.

    • With thinking mode off, the model performs web search or reverse image search on demand and answers with source citations. This suits factual Q&A and high-concurrency scenarios.
    • With thinking mode on, searches are interleaved with reasoning, creating a deep search experience that gathers information while reasoning. In an official example comparing the heights of two towers, the model first runs a broad search, then opens authoritative pages to get the numbers; if the data is incomplete, it switches keywords within the page to search again, closing out after up to a dozen or more consecutive tool calls.

    At the protocol level, three common message formats in the industry (Anthropic Messages, OpenAI Responses, and Chat Completions) can usually be integrated directly. Tools are mounted through naming conventions—for example, one handles web and image search, and another reads a user-provided link.

    A schematic request skeleton is shown below (it expresses structure only and is not tied to a specific vendor API):

    1. {
    2. "model": "<your-model>",
    3. "messages": [{"role": "user", "content": "Compare the heights of two towers and provide sources"}],
    4. "tools": ["web_search", "read_url"],
    5. "thinking": {"type": "enabled"}
    6. }

    3. Three Common Pitfalls

    First, context must be passed back unchanged. The thinking blocks, search result blocks, and page-fetch result blocks returned by the server must be sent back in the next turn with the original structure and order preserved. If a self-built gateway filters fields along the way, the request will still return successfully, but the model will “lose memory” and forget all the web page content it just saw, making answers suddenly vague.

    Second, sampling parameters may stop working. Once tool calling, automatic title generation, or a high security level is enabled, the server takes over the sampling schedule, and settings such as temperature and top_p no longer apply. Teams that need fine control over output style should implement capability switches and fallback strategies at the gateway layer.

    Third, document parsing is billed per page. PDFs, Word files, PPTs, and images are metered by page. If rich layout recognition is enabled, the system crops chart regions and reinserts them at their original text positions, but the cropped images are counted as additional image input tokens. Chart detection is automatic, so when cropping is missed, the model genuinely cannot see that content. For chart-heavy documents, pre-validation or manual fallback is recommended.

    4. Production Recommendations: Contain Uncertainty in a Gateway

    For production environments, add a self-managed gateway between the application and the model with four responsibilities: first, protocol conversion and a tool allowlist; second, context block integrity checks that fill or reject missing blocks; third, capability routing that decides whether to enable tools and document parsing based on model tier; and fourth, observability, using logging services and monitoring alerts to track search rounds, tool failure rates, and per-page billing records.

    On the infrastructure side, you can combine Baidu AI Cloud’s object storage for raw attachments, a message queue for peak shaving, a container platform to host the stateless gateway, and a logging and monitoring system for full-link tracing—keeping both cost and stability in your hands while preserving the user experience.