Built-in Tool APIs for LLMs: Rebuilding a Complete Conversational Application

    This article explains how built-in tool APIs move retrieval, web reading, document parsing, speech, and safety filtering from the client to the model server. It covers the five tool categories, a practical cost model, a minimal integration path with protocol-compatible SDKs, server-side orchestration and context assembly, caching and fallback engineering, security and compliance practices, and a reusable layered architecture blueprint.

    1. From Assembling a Tool Chain to Using Built-in Tool Services

    Building a fully functional conversational AI application used to require developers to orchestrate a long tool chain themselves: a retrieval service for web search, a fetching service for content extraction, a document parsing service for files and optical character recognition, speech services for transcription and synthesis, and a content safety service for moderation. Each stage had to be selected, authenticated, rate limited, and billed separately, and the client had to implement a complete tool invocation and result回填 logic. The longer the chain, the larger the failure surface and the higher the troubleshooting cost.

    A practice that has recently emerged in the industry is to consolidate these capabilities into the model service as “built-in tools.” Developers only declare which tools to enable in the request; the server performs retrieval, fetching, parsing, speech processing, and safety filtering itself, assembles the results into the context, and continues reasoning. This shifts complexity from the client to the server and significantly lowers the barrier to rebuilding a complete conversational application. This is not a proprietary feature of any single vendor but a direction in which common industry technical solutions are evolving; this article discusses its engineering practice from a general perspective.

    2. Capability Breakdown: What Built-in Tools Actually Include

    Abstracted, these capabilities fall into five categories:

    • Web retrieval: generates queries from conversational semantics and returns up-to-date information, addressing the model’s knowledge cutoff and real-time needs.
    • Link reading and content extraction: extracts and structurally cleans the main content of a given address, turning a web page into context that can be reasoned over.
    • File input and optical character recognition: parses text and tables in common documents and images, extending the boundary of multimodal input.
    • Speech input and speech synthesis: handles speech transcription and reading results aloud, supporting full-duplex or half-duplex interaction.
    • Safety moderation: filters both input and output to reduce the risk of non-compliant content.

    The key engineering value lies in the change of “orchestration location”: tool invocation happens on the server, so the client no longer needs to implement a multi-turn tool protocol, result serialization, or failure retries, and handles only one request and one response.

    3. Cost and Billing: Building a Predictable Budget Model

    Model calls are usually priced separately for input and output tokens, with peak and off-peak periods distinguished; built-in tools are mostly billed per invocation, speech capabilities are often priced by duration, and limited-time discounts may exist. A practical approach to budget estimation:

    1. Cost per session ≈ model input fee + model output fee
    2. + retrieval calls × price per retrieval
    3. + fetch calls × price per fetch
    4. + file page or image count related fees
    5. + speech duration × price per minute

    Practical advice: set a “maximum calls per session” for each tool type; combine retrieval and fetching into a single orchestration; cache results for high-frequency repeated questions; use speech capabilities only where interaction genuinely requires them. This usually keeps costs within a predictable range and avoids the cost amplification caused by long contexts and unlimited retrieval.

    4. Integration Path: Protocol Compatibility and Minimal Changes

    Mature platforms generally support the styles of mainstream open protocols, offer multiple interface forms, and use unified model identifiers, making migration of existing code easy. The minimal integration steps:

    1. Create a key in the open platform and configure quotas and a call allowlist following the principle of least privilege.
    2. Choose a familiar SDK and only replace the service address and model identifier.
    3. Add a tool declaration field in the request body listing the built-in tool types to enable.
    4. Control reasoning behavior such as thinking mode and temperature through additional parameters.
    5. Parse the server-side tool invocation trace in the response to display citation sources and for auditing.

    Illustrative code (pseudocode, structure only):

    1. resp = client.chat.completions.create(
    2. model="<unified model identifier>",
    3. messages=[
    4. {"role": "system", "content": "You are a rigorous assistant; answers must cite sources"},
    5. {"role": "user", "content": "What is the weather in Shanghai today? Is it suitable for outdoor activities? Answer briefly"},
    6. ],
    7. tools=[{"type": "<web retrieval tool>"}, {"type": "<link reading tool>"}],
    8. )
    9. print(resp.choices[0].message.content)
    10. for step in resp.choices[0].message.tool_calls_trace:
    11. print(step.type, step.status)

    5. Server-side Orchestration and Context Assembly

    The core difficulty of built-in tools is not the “invocation” but the “orchestration strategy”: when to trigger retrieval, how many retrieval rounds, which links to fetch, how to trim the main content, and how to annotate citations. More mature implementations follow a few principles: perform intent detection first to avoid triggering tools for chitchat; truncate retrieval results by relevance to control context growth; fall back to summary fragments when fetching fails; and apply short-term caching for repeated retrieval of the same question. Understanding this allows developers to tune effectively at the prompt and parameter level rather than blindly increasing the number of tools.

    6. Engineering Practice: Caching, Fallback, and Observability

    • Caching: cache retrieval and fetch results keyed by “semantic fingerprint + time window” to significantly reduce repeated costs.
    • Fallback: when a tool is unavailable, fall back to the model’s own knowledge and clearly state that timeliness is limited.
    • Timeouts and retries: set independent timeouts for each tool type and use exponential backoff to avoid cascading failures.
    • Observability: record tool invocation latency, hit rate, failure reasons, and token consumption; build dashboards and alerts.
    • Citations and compliance: retain source links and fetch times for auditing and copyright risk control.

    7. Security, Privacy, and Compliance

    Files and speech are highly sensitive inputs. It is advisable to complete desensitization and minimal collection on the enterprise side and define a clear data retention policy; enable moderation on the output side and keep interception logs; set a domain allowlist for external links to guard against prompt injection and malicious content. If personal information is involved, follow applicable laws, regulations, and platform agreements, and avoid sending sensitive data directly into third-party chains.

    8. A Reusable Architecture Blueprint

    A practical layered structure: the access layer handles authentication and rate limiting; the session layer manages context and role settings; the orchestration layer decides whether to call built-in tools and controls rounds; the tool layer is hosted by the platform; the data layer accumulates caches and audit logs; the observability layer handles metrics and alerts. Baidu AI Cloud typically provides general capability categories such as container platforms, object storage, message queues, log services, and monitoring and alerting in similar scenarios, which can serve as infrastructure options for hosting this kind of architecture.

    9. Conclusion

    Building retrieval, parsing, speech, and safety capabilities into the model service essentially turns “integration complexity” into problems of “orchestration strategy and cost management.” What developers really need to refine are five fundamentals: intent detection, context trimming, caching and fallback, observability, and compliance. Mastering them allows you to build stable, controllable, and scalable conversational AI applications at lower cost, regardless of who provides the underlying tools.