Tool Calling Failure on Domestic AI Accelerators: A Troubleshooting Walkthrough

    This article walks through a real-world case where tool calling (function calling) silently degraded into plain text on a domestic AI accelerator card running a large open-source model. It covers the symptoms, a four-step investigation from sampling parameters to chat template and parser rules, the two-layer root cause involving template pollution and an incomplete adaptation chain, a four-layer fix strategy, and a practical checklist for regression testing, multi-turn tool result injection, streaming output, and quantization. The key takeaway is that tool calling depends on agreement among the training framework, chat template, and inference parser, so teams should treat template baselines, parser test cases, adapted images, and monitoring as a repeatable process.

    1. Background: Why Tool Calling Breaks on Heterogeneous Compute

    Deploying large open-source models on domestic AI accelerator cards has become a common choice for teams building private inference. Hardware cost, supply chain control, and keeping data within their own environment are all practical drivers. But once teams move to production, they often hit a frustrating class of problem: the model’s Chinese and coding abilities work fine, yet tool calling (Tool Calling / Function Calling) fails. When the model should emit a structured call intent, it returns the call request as ordinary chat text instead.

    What makes this confusing is that it is neither an explicit error nor an obvious drop in inference quality. The service starts, the API responds, and the logs show no exception stack traces. Only the business side notices that “the agent stopped doing its job.” This article uses one typical debugging session as a thread, breaking the process into symptoms, hypotheses, verification, root cause, and fix, to form a reusable troubleshooting methodology.

    One premise needs to be clear first: tool calling is not a skill the model “learned on top of everything else.” It is the product of a three-way agreement among the training framework, the chat template, and the inference engine’s parser. If any one of them is misaligned, the symptom is the same: the call degrades into text.

    2. Symptoms: Structured Output Downgraded to Natural Language

    On a domestic AI accelerator, after deploying an open-source model with tool calling support through a recent open-source inference framework, a request containing a tool list produced roughly the following response:

    1. {
    2. "role": "assistant",
    3. "content": "好的,我来帮你查询。```json\n{\"name\": \"get_weather\", \"arguments\": {\"city\": \"上海\"}}\n```"
    4. }

    The expected result is that the tool_calls field is populated and content is empty. The actual result is that the call intent sits entirely inside content, wrapped in a Markdown code block. The business-side parsing branch gets no executable structure, and the flow stops there.

    There are three key observations:

    • The model’s semantic understanding is correct. The tool name and arguments are both right, which suggests weight loading, quantization precision, and operator implementations are not obviously at fault.
    • The output is wrapped in a generic code block format, which suggests the model is “imitating some text convention” rather than “emitting special markers.”
    • The inference engine throws no parsing exception, which suggests the parser failed silently and fell back to returning plain text.

    3. Troubleshooting: From the Template File to the Parser Regex

    3.1 Step 1: Rule Out Sampling Parameters

    The most common misdiagnosis is to blame sampling configuration. The team fixed the random seed, lowered the temperature, and disabled nucleus sampling, but the problem reproduced consistently. This ruled out randomness and showed that the output format is deterministic, coming from the template or the prompt constraints.

    3.2 Step 2: Compare the Chat Template

    The team exported the chat template actually in effect and compared it section by section against the model’s officially recommended template. They found that the system prompt area had an explicit format constraint appended, roughly meaning “when you need to call a tool, output it as a json code block.” The injection position of the tool list and the field naming also deviated from the official convention.

    This is the dividing line of the problem: the custom template used a natural-language instruction to override the model’s native output protocol. During training, the model was aligned to a specific marker sequence, usually made up of reserved tokens or control characters, but the template asked it to output a generic text format. The model chose to follow the instruction that came later and was more explicit.

    3.3 Step 3: Check the Parser’s Matching Rules

    The framework’s built-in tool parser is essentially a set of regexes and a state machine targeting a specific marker sequence. It scans the generated text, looks for the agreed markers, and deserializes the content between the markers into a call structure. When the model outputs generic code block markers, the regex does not match, the parser returns an empty result, and the framework degrades to a plain text response by design.

    The chain can be understood with this pseudocode:

    1. # Simplified logic on the inference engine side
    2. raw = model.generate(prompt_with_tools)
    3. match = TOOL_CALL_PATTERN.search(raw) # relies on the native marker sequence
    4. if match:
    5. return build_tool_call_response(match)
    6. else:
    7. return plain_text_response(raw) # silent degradation, no error

    3.4 Step 4: Verify with a Minimal Change

    Keeping the tool list injection logic and removing all non-standard output format instructions from the template, the team sent the request again with the model back on its native protocol. Tool calling was parsed correctly. Template pollution was confirmed as the direct cause.

    4. Root Cause: Two Layers Stacked

    The first layer is a configuration problem. The custom chat template introduced a natural-language format constraint that conflicts with the native protocol, a typical case of “prompt engineering overstepping its bounds.” The template’s job is to organize context and inject the tool list, not to redefine the output protocol.

    The second layer is an ecosystem problem, and the more fundamental one. The inference framework version available for a given domestic accelerator often lags in supporting newer open-source model families: model architecture updates, newly added control markers in the vocabulary, and parser rule changes all need operator adaptation, precision alignment, and image rebuilds after being merged upstream before they take effect on the user side. The template was modified by hand precisely because the default template did not behave well on the new hardware stack, so operations or application engineers patched it with prompts, ultimately turning an adaptation gap into a protocol conflict.

    So attributing this kind of problem simply to “the model is bad” or “the hardware is bad” is inaccurate. It is an external symptom of an incomplete adaptation chain.

    5. Solution: A Four-Layer Fix Strategy

    1. Return the template to native. Use the officially recommended template as the baseline. Any customization should be additive rather than a rewrite, and output format instructions must not be written into the template.
    2. Make parsing capability explicit. Before going live, verify with a fixed set of cases whether the parser matches, and check that the structured fields in the response are non-empty, instead of only checking whether the text reads well.
    3. Build an adapted image. Fix the driver, runtime, inference framework, model weights, and template into one validated image, and release it in a versioned way through a container platform, avoiding the drift caused by manually changing configuration on each machine.
    4. Establish regression and observability. Add tool calling cases to continuous integration, and combine them with logging and monitoring with threshold alerts on metrics such as “structured field fill rate” and “parse failure rate,” so problems are caught early.

    One additional engineering recommendation: add a fallback check at the gateway layer. If the structured fields are empty but the text contains a suspected call intent, intercept it directly and return an explicit error code, preventing silent degradation from flowing into the business.

    6. Practical Checklist and Pitfalls

    • After upgrading the inference framework or switching hardware models, always run a tool calling regression. Do not test only general question answering.
    • In multi-turn conversations, the field naming used when injecting tool results back must match the template strictly, or mismatches start from the second turn.
    • Verify parallel tool calling and streaming output separately. Under streaming, markers may be split across different data chunks.
    • After quantizing the model, reconfirm that control markers were not trimmed. Vocabulary-related changes are especially sensitive.
    • If you use managed cloud capabilities, you can build a standardized delivery pipeline on top of common categories such as container platforms, object storage, logging, and monitoring with alerting, and bring images, templates, and test case sets under version control together.

    7. Summary

    Tool calling degrading into plain text looks like a formatting problem on the surface, but it is essentially a problem of protocol consistency and adaptation completeness. Troubleshooting should follow the order of first ruling out randomness, then comparing the template, then checking the parser rules, and finally verifying the image and version, to avoid burning time repeatedly on sampling parameters. For a team, the most valuable outcome is not any single fix, but turning the template baseline, parser test cases, adapted image, and monitoring alerts into a process, so that bringing models online in heterogeneous compute environments goes from “relying on luck” to “verifiable.”