WebLLM runs AI models locally in your browser using WebGPU. These community adapters connect WebLLM to agent frameworks. The first load fetches WebLLM's runtime and model files; the browser caches them for later loads.
| Package | Guide | Examples | npm |
|---|---|---|---|
langchain-web-llm |
Usage and support | LangChain and Deep Agents | npm |
pi-ai-web-llm |
Usage and support | Pi Agent Core and Pi Durable | npm |
strands-web-llm |
Usage and support | Strands SDK and Harness | npm |
Exact WebLLM 0.2.86 IDs checked with the adapters below. All = LangChain, Pi, and Strands.
O = verified; O* = verified with request.constrainedToolCalls: true; X = unverified. Tools covers call → result → final answer; Think covers separation and preservation of native reasoning within the current tool loop.
Tool choice and argument accuracy depend on the model.
MMLU-Pro scores are for the source models; decode speeds are local M4 Pro (24 GB), Chrome 155 measurements.
Exact WebLLM model_id |
MMLU-Pro | Decode tok/s | Tools | Think | Image | Audio | Video | Verified adapters |
|---|---|---|---|---|---|---|---|---|
Qwen3.5-9B-q4f16_1-MLC |
82.5 | 19.7 | O | O | X | X | X | All |
Qwen3.5-4B-q4f16_1-MLC |
79.1 | 33.0 | O | O | X | X | X | All |
Qwen3-8B-q4f16_1-MLC |
74.2 | 32.0 | O | O | X | X | X | All |
Qwen3-4B-q4f16_1-MLC |
70.4 | 51.5 | O | O | X | X | X | All |
Qwen3.5-2B-q4f16_1-MLC |
66.5 | 59.7 | O | O | X | X | X | All |
gemma-4-E2B-it-q4f16_1-MLC |
60.0 | 38.5 | O | O | X | O (LangChain, Strands) | X | All |
Qwen3-1.7B-q4f16_1-MLC |
56.5 | — | O | O | X | X | X | All |
Qwen2.5-7B-Instruct-q4f16_1-MLC |
56.3 | 38.0 | O* | X | X | X | X | All |
Qwen2.5-3B-Instruct-q4f16_1-MLC |
43.7 | 59.5 | O | X | X | X | X | All |
Qwen3.5-0.8B-q4f16_1-MLC |
42.3 | 71.2 | O | O | X | X | X | All |
Qwen2.5-1.5B-Instruct-q4f16_1-MLC |
32.4 | 87.6 | O | X | X | X | X | All |
Qwen2.5-0.5B-Instruct-q4f16_1-MLC |
15.0 | 136.8 | O | X | X | X | X | All |
For WebLLM 0.2.86, use the bundled Gemma runtime. Audio works in ordinary chat, without tools or thinking. Video is unsupported.
Gemma named or single-tool required choices prefill the call, so there is no thinking before that call.
For Hermes, WebLLM does not enforce tool_choice; the adapters validate the result.
Qwen and native chat replay tool results in the supplied order; they do not match results by ID.
Qwen3 and Qwen3.5 drop earlier thinking after a new user question, following their model templates.
Qwen2.5-7B can emit malformed tool calls without constraints. Constraints are optional and off by default.
Qwen2.5 uses its original default system prompt when no system message is present; this differs from WebLLM's model configuration. Pi supplies an empty system message for tools when no system prompt is set, so the default is omitted in that case.
Required and named Qwen tool choices append an instruction to the system message.
When a Qwen3.5 argument's type cannot be inferred, JSON-like values may be parsed as JSON. In nullable string fields, null is interpreted as null rather than the string "null".
Benchmark notes and tool formats
Models are ranked by source-model MMLU-Pro with thinking on; Qwen2.5 has no thinking mode. Evaluation settings vary. Decode speeds are the median of three local runs, thinking off, max 128 tokens; they are not portable across devices.
Tool formats follow Hermes (Qwen2.5/Qwen3), Qwen3 Coder (Qwen3.5), and Gemma.
Exact WebLLM model_id |
Use | Verified adapters |
|---|---|---|
Phi-3.5-vision-instruct-q4f16_1-MLC |
Image input | All |
snowflake-arctic-embed-m-q0f32-MLC-b32 |
Embeddings, 768 dimensions | LangChain, Strands |
snowflake-arctic-embed-m-q0f32-MLC-b4 |
Embeddings, 768 dimensions | LangChain, Strands |
snowflake-arctic-embed-s-q0f32-MLC-b32 |
Embeddings, 384 dimensions | LangChain, Strands |
snowflake-arctic-embed-s-q0f32-MLC-b4 |
Embeddings, 384 dimensions | LangChain, Strands |
The listed embedding models accept up to 512 tokens. No listed model is verified for both tools and vision.
Runnable examples use published model sampling settings supported by WebLLM, except where they demonstrate custom sampling. top_k and min_p are not exposed by its API.
When using a custom WebLLM configuration, keep the listed model_id for supported models.
Without a schema, response_format: { type: 'json_object' } accepts any JSON value. Set schema: '{"type":"object"}' to require an object.
WebLLM uses XGrammar for structured response_format; structural_tag is one format type, not a
separate xgrammar2 flag. Raw formats work on chat paths when the model supports them.
constrainedToolCalls builds Qwen-specific tool grammar. Earlier tests covered every Qwen ID above; release checks use representative IDs.
With tools enabled, unverified model IDs return an error. All three adapters accept it with
WebLLM 0.2.86.
It uses the existing tool definitions;
framework tool selection, thinking, and argument validation still apply. It can be slower or less accurate.
It does not guarantee the intended tool call or argument values.
Explicit text format is compatible; JSON, grammar, and structural-tag formats are not. WebLLM resumable generation is unsupported.
The model table's Tools column means tool calls work; it does not indicate constrained decoding support.
Gemma tool and thinking requests use WebLLM's Completion API, which does not accept response_format.
LangChain and Pi allow Gemma ignore_eos without tools and preserve a length finish. Strands rejects it because its SDK treats a max-token finish as an error. Tool calls need normal end-token handling.
Qwen3.5 accepts closed object schemas (additionalProperties: false) with fixed properties.
String enums and string const values can omit type.
Type-less non-string enum/const values and anyOf/oneOf unions without string branches use JSON Schema constraints.
Raw string fields support type, enum, and const; schema $ref references are unsupported,
but literal $ref keys in JSON values are preserved.
Unsupported XML shapes raise an error. JSON-valued fields retain native XGrammar limits;
not every JSON Schema keyword is enforced. Omit the option for ordinary tool generation.
Qwen3.5 tool history cannot safely replay message-boundary tokens such as <|im_start|>.
For the Qwen3.5 models listed above with WebLLM 0.2.86, pass these chatOpts when creating or reloading the engine:
import type { ChatOptions } from '@mlc-ai/web-llm'
const chatOpts: ChatOptions = {
conv_config: {
role_empty_sep: '\n<think>\n',
stop_token_ids: [248044, 248046],
},
}Set thinkingPrefilled: true on your adapter. This restores Qwen3.5's official thinking prefix and stop tokens; the shipped stop IDs can cut off ordinary Korean or Thai words. Per-call request.extra_body.enable_thinking: false still works.
For Qwen JSON/grammar with thinking off, the adapters remove WebLLM's fixed empty thinking prefix. The generated body and raw onChunk data stay unchanged.
For repository development, use the Node.js version in .node-version and npm 11.21.1:
npm ci
npm run checkRegistry packages need a publish time and must be at least 24 hours old. CI also tests packed installs with npm and both Yarn installation modes.
See contributing and security guidance.