Manuscript Offprint

arXiv:2610.17436

SchemaWeaver: Accelerating On-Device Mobile Agentic AI via Schema-Guided Parallel LLM Decoding

Boyuan Yang, Wei Gao

ABSTRACT

Large language models (LLMs) on mobile devices can act as agents that call external software tools to complete complex tasks, but the major challenge of supporting on-device mobile agentic AI with LLMs is the long latency of LLM tool calling on mobile devices. In particular, the decode phase is the main contributor of such long latency, but is hard to speed up on mobile processors as it is bound by memory bandwidth rather than compute power. To address this limitation, in this paper we present SchemaWeaver, a new on-device mobile agentic AI technique that enforces schema-guided parallel decoding in the decode phase of LLM tool calling, to reduce its latency by producing multiple tokens in each decode pass. SchemaWeaver can be generically applied to the LLM inference engine on mobile devices without involving any training efforts or changes on LLMs, and our experiment results on major mobile SoCs and LLM families show that SchemaWeaver can reduce the LLM tool calling latency by up to 3.9 times, compared to the competitive baselines.

1 INTRODUCTION

In recent years, Large Language Models (LLMs) have been used as the backbone of agentic AI systems. When given proper context, LLM agents can interpret user instructions, select the proper external software tools, and call these tools to complete complex tasks [27, 52, 53, 77]. For example in Figure 1, when being asked for driving directions, the LLM agent selects the get_route software tool from the available tools for this task. It then calls this tool for route planning and returns the results back to the user in natural language. In this process, the LLM agent perceives each tool from its schema, which is a machine-readable description that gives the tool's description and the names and types of its arguments [27]. The LLM agent, then, calls the tool by generating the text command with values of the tool's arguments.

Currently, LLM agents on mobile devices (e.g., smartphones) have become increasingly popular, allowing intelligent and automated operations on the user's personal data [11, 47, 62]. Agentic AI functionalities on mobile devices have also been supported by mainstream mobile OSes, via Android AppFunctions [2, 3] and iOS App Intents [4]. In particular, running on-device LLM agents on local devices well

Wei Gao

University of Pittsburgh

Pittsburgh, PA, USA

weigao@pitt.edu

Figure

Figure 1: Agentic AI systems based on LLM agents that call external software tools

preserves the user’s data privacy [37, 73, 78], and quantized LLMs with 1B-3B parameters, which fit in a smartphone’s memory budget [19, 22, 39, 42], have been capable of launching tool calls with reasonable accuracy [25, 49, 80].

The major challenge of supporting on-device mobile agentic AI, however, is the long latency of LLM tool calling on mobile devices. In inference, an LLM produces its output through repeated forward passes that constitute a prefill phase and a decode phase. The prefill phase uses the first pass to read the input prompt, and the decode phase then generates the response using the other passes, each of which produces one output token [51, 72]. As shown in Figure 2(a), in traditional conversation-based LLM uses, one prefill is usually followed by a large quantity of decoded text tokens that the user reads as they arrive, and most of the decode latency is hence “hidden” in user reading [40, 68]. Agentic LLM operations, in contrast, first decode a structured tool call command for tool execution, and text tokens in response can only be produced after the completion of tool execution. The decode latency experienced by the user, hence, becomes significantly longer, especially when executing complicated agentic tasks such as on-device content search that involves multiple tool calls of different types. In these tasks, our experiments show that the decode latency constitutes up to 81% of the wall-clock time being taken (Sec 2.2).

Unfortunately, it is difficult to accelerate this decode phase on mobile devices, which is bound by the device’s limited memory bandwidth rather than by compute power [28, 51]. More specifically, on mobile devices, the LLM’s weights have to be repeatedly loaded from memory to mobile processors by every pass, due to the processors’ limited cache capacities.

Figure

(a) Agentic LLM use incurs longer latency to the user

Figure 2: The latency of LLM tool calling in on-device mobile agentic AI

(b) SchemaWeaver reduces latency via parallel decoding

[1, 51]. Since each decode pass only produces one output token, the decode latency is determined by the speed of memory bus, which is usually much slower than the mobile processor speed and hence causes processor starvation. Our experiment results on the OnePlus 12R phone with Snapdragon 8 Gen 2 SoC show that the decode speed on mobile CPU is > 5× slower than the prefill speed (Sec 2.3). Using mobile GPU or NPU cannot help much, due to the shared memory architecture in mobile SoCs [8, 11, 34, 72].

The key to accelerating the decode phase in mobile agentic AI, hence, is how to allow producing multiple output tokens in one decode pass, to fully utilize the on-device compute power. One straightforward approach is speculative decoding [9, 20, 32], which first uses a much smaller draft model to guess the next few tokens and then lets the target model check the correctness of these guesses in one pass. Since a tool call is highly structured, most output tokens are highly predictable. For example, with a SmolLM2-1.7B as the target model and SmolLM2-135M as the draft model, 74% of guesses are correct. However, these correct guesses only result in 31% speedup, because the draft model still decodes one token per pass and is bounded by memory bandwidth as well.

Another option is constrained decoding [16, 21, 33, 64, 82], which builds a set of grammatical rules from the tool's schema and forbids any output token that makes the LLM tool call ill-formed. These rules can be further used by jumpforward decoding [82] in each decode pass, to skip the current decode computation when only one legitimate output token exists. These skipped tokens can then be processed in batch by a single prefill pass. However, since tokens can only be skipped when they are being computed, the overall decode latency is still bound by the number of decode passes, which can only be sequentially computed.

To fundamentally overcome this limitation of sequential decode computations, we instead aim to allow decoding the argument values of an LLM tool call in parallel, by leveraging the pre-known and fixed information contained in the tool schema. More specifically, the schema describes the position of each argument's value in the tool call command, and each position is always fixed. For example, in the call get_weather() shown in Figure 2(b), the value of argument city is a string that begins after city=" and ends at the closing quote, and the value of argument days is an integer after days=. Hence, instead of decoding these argument values sequentially, we can decode all of them as one batch in parallel to save unnecessary passes. On the other hand, the fixed names of arguments need no decoding, and can instead be loaded by the LLM inference engine via one prefill pass.

Based on this idea, in this paper we present SchemaWeaver, a new on-device mobile agentic AI technique that enforces schema-guided parallel decoding in the LLM inference engine. First, SchemaWeaver parses the fixed parts in the tool schema to build a tool skeleton that provides information about the position of each argument value (Sec 4.1). It then places argument names as parallel token sequences, so that arguments share the same prompt and tool call prefix to facilitate parallel decoding of argument values. To handle rugged value lengths, we pad decode sequences on the fly for the maximum compute efficiency (Sec 4.2). Since decode results of argument values may not share exactly the same sequential prefix, we add a write-back phase after parallel decoding to realign the decode results and rebuild the LLM agent's KV cache accordingly. To avoid this write-back phase from blocking tool executions, we assemble a valid tool call at the same time and emit the tool call early to further reduce the end-to-end latency (Sec 4.3).

Many tools called by the LLM agent may include optional arguments. For example, when calling the weather query tool, the LLM agent may opt to specify the temperature unit or not. The values of optional arguments have to be decided after all required argument values are generated, and cannot adapt to parallel decoding. Instead, we have to decide and generate values of optional arguments in a sequential manner, after parallel decoding of required argument values (Sec 5). To minimize the extra latency caused by this sequential decoding, we design provisional calls for read-only tools to emit early only with required arguments, which can be later replaced by a corrected call once the LLM agent adds the optional argument values (Sec 5).

To our best knowledge, SchemaWeaver is the first system design that accelerates on-device LLM tool calling on mobile devices, without involving any training efforts or changes on LLMs. We implemented SchemaWeaver in llama.cpp [22] inference engine by using multiple tokens as a matrix in decoding when performing GEMM (general matrix-matrix multiply)1^{1}, and evaluated it on multiple tool calling benchmarks, mobile SoCs and LLM families including Qwen [74, 75], Llama 3.2 [24] and SmolLM2 [6]. Based on experiment results, we have the following conclusions:

  • SchemaWeaver reduces the number of forward passes for a tool call from 44.3 to 13.1, and the end-to-end tool calling latency by 2.13×2.13 \times over the competitive baselines.

  • The gain of SchemaWeaver grows as the memory bandwidth falls. When the memory bus is slowed by 4.7×4.7 \times, serial decoding slows by 3.2×3.2 \times but SchemaWeaver only slows by 2.4×2.4 \times, and its speedup rises from 3.0×3.0 \times to 3.9×3.9 \times.

  • Applying SchemaWeaver costs <2%< 2\% of tool calling correctness across different LLM settings.

  • SchemaWeaver is lightweight and efficient. With 8.9 MB of extra peak memory being used compared to baselines, it reduces the energy consumption of a tool call by 2.1×2.1 \times.

References (55)