Tool Calling for LLMs and Agent Applications: Architecture and Practices

    This article explains how opening up built-in tool chains through general model APIs changes the work of building LLM applications. It covers a four-layer reference architecture, the engineering semantics of four core capabilities (web search, deep reasoning search, file parsing, and link reading), orchestration practices for multi-tool tasks, and how to balance cost, latency, and quality. A reusable implementation checklist is included for developers who want to build similar capabilities in their own products.

    1. From Chatting to Acting: What Capability Exposure Means

    Over the past two years, the form of LLM products has shifted noticeably. Early on, they mainly handled single-turn or multi-turn text generation: the user asks, the model answers. The boundary was clear, but the capability was limited. Once models were asked to answer time-sensitive questions, interpret a document hundreds of pages long, or summarize an external web page, purely parametric knowledge was clearly not enough. The solution the industry widely adopted is tool augmentation: deterministic tasks such as retrieval, parsing, crawling, and execution are handed off to external services, while the model decides when to call them, how to combine them, and how to fold the results into its response.

    A recent industry trend worth noting is that some model providers have begun exposing tool chains that were previously wrapped inside their own applications, making them available in general APIs as parameterized switches. Developers no longer need to assemble a search service, a document parsing pipeline, and a web crawling module themselves; they only declare the capabilities they need in the request, and the server side handles the orchestration. For application developers, this means the barrier to building an intelligent app that can look up information, read files, and reason across multiple steps has dropped from “standing up a tool platform” to “designing a single request well.”

    It is worth stressing that this kind of capability exposure does not change the underlying technical principles. What changes is where the capability is delivered: it moves from client-side self-hosting to server-side managed service. Understanding this is what lets you judge which scenarios are suitable for direct reuse and which still require building your own.

    2. A Reference Architecture for Tool-Augmented Applications

    A typical tool-augmented application can be split into four layers, decoupled from one another through explicit contracts:

    1. Interaction layer: responsible for multimodal input collection (text, images, documents), session state maintenance, and result rendering, including visualization of citation sources and parsed fragments.
    2. Orchestration layer: decides “whether to call a tool, which one, how many times, and when to stop.” This is the key to whether complex tasks succeed, and the layer most prone to getting out of control.
    3. Capability layer: atomic capabilities including web retrieval, page crawling and main-content extraction, structured document parsing, and content safety review. These can be either server-managed or self-built.
    4. Data and governance layer: covers session persistence, call logging, metrics monitoring, and quota and cost accounting.

    A schematic request structure typically looks like this (it only expresses a general shape and does not represent any specific API):

    1. {
    2. "model": "<model identifier>",
    3. "messages": [
    4. {"role": "user", "content": "Summarize the key risks in this quarterly report and check them against the latest policy guidance"}
    5. ],
    6. "tools": ["web_search", "read_url", "file_parse"],
    7. "reasoning": {"mode": "deep"},
    8. "safety": {"input_check": true, "output_check": true}
    9. }

    Here tools declares the available capabilities, reasoning controls whether multi-step deep reasoning is enabled, and safety controls basic risk review of inputs and outputs. Actual parameter names differ across providers, but the semantics are broadly the same.

    3. Engineering Semantics of the Four Core Capabilities

    Web search. Once enabled, the model can automatically initiate web or image searches based on the question in non-deep mode, and attach citations in the answer. Three engineering points matter: first, retrieval quality depends on query rewriting, and colloquial user questions often require the model to restructure the search expression first; second, citations must be traceable, otherwise they cannot be audited; third, time-sensitive questions should carry an explicit “freshness” constraint to avoid the model citing outdated pages.

    Deep reasoning search. In deep mode, the model autonomously initiates retrieval, reads links, and continues analysis based on new information across multiple reasoning steps. This brings a leap in capability, but also uncertainty: the number of calls and latency grow nonlinearly. In practice, it is advisable to set hard limits on maximum steps, timeout, and total budget, and to deduplicate and apply termination checks to repeated calls.

    File parsing. Supports uploading documents and images, with the server side performing plain-text extraction or mixed text-and-image parsing before handing the result to the model. The key engineering points are layout restoration and table handling: cross-page tables, multi-column layouts, and scanned documents lose semantic fidelity after extraction, so parsing results should preferably retain page numbers and block coordinates to make it easier to locate and trace sources when answering.

    Link reading. Once enabled, the model can automatically recognize URLs in messages, crawl the main content, and answer in context. What is most easily overlooked here is security and compliance: crawled content is untrusted input and must be guarded against embedded prompt injection; at the same time, real-world issues such as paywalls, dynamically rendered pages, and encoding anomalies must be handled.

    In addition, the two-way input and output safety review parameters provide basic risk interception and refusal flags, making it easier for the upper layer to apply consistent messaging and fallback strategies.

    4. Orchestration Practices for Complex Tasks

    The difficulty of coordinating multiple tools lies not in “being able to call them” but in “calling them correctly.” A few general principles apply:

    • Plan before executing: have the model first output a brief retrieval plan (what evidence is needed, in what priority), then execute step by step. This can significantly reduce ineffective calls.
    • Context compression: segment and summarize long document parsing results before putting them into context, while retaining citation anchors to the original text. This avoids attention dilution and cost spikes from stuffing everything in at once.
    • Structured evidence: organize retrieval results into “conclusion, source, time” triples for the model to generate from, which noticeably reduces unsupported inference.
    • Clear termination conditions: set a rule that stops once evidence is sufficient, to prevent over-retrieval.
    • Full-chain observability: log the input summary, elapsed time, response size, and matched fragments of each tool call to form a replayable trace.

    5. Balancing Cost, Latency, and Quality

    Tool calls are the main source of cost and latency. It is advisable to establish a three-tier budget: a per-request cap, a cumulative per-session cap, and a daily per-user quota. At the same time, route different questions by tier: simple Q&A goes to the pure model, time-sensitive questions go to retrieval, long documents go to parsing, and only genuinely complex questions enable deep reasoning. This tiered strategy usually compresses average overhead substantially without sacrificing experience.

    Quality evaluation should be independent of live traffic: build an evaluation set covering time-sensitive Q&A, document understanding, multi-hop reasoning, and refusal correctness, and separately measure citation accuracy, answer traceability, and out-of-bounds refusal rate. Without a traceability metric, retrieval augmentation easily degrades into something that “looks grounded but is actually patched together.”

    6. A Reusable Implementation Checklist

    To build similar capabilities in your own product, proceed in this order: first define the input and output contracts and citation conventions; then integrate managed tool capabilities for quick validation; next fill in logging, monitoring alerts, and quotas; then build a small-scale evaluation set and set launch criteria; finally, progressively replace self-built components for high-value scenarios, such as using object storage to archive original files, message queues to smooth out parsing task peaks, and container platforms to host crawling and parsing workloads, with log services and monitoring alerts providing full-chain tracing. If running on a cloud platform such as Baidu AI Cloud, the general-purpose category capabilities above can be combined directly without binding to any specific proprietary API.

    Overall, moving tool capabilities to the server side brings the construction of “super apps” back from infrastructure engineering to product and scenario design. The core competitiveness of developers is shifting from “whether they can connect tools” to “whether they can orchestrate tools accurately, controllably, and evaluably.”