12 Factor Agents for Client-Side ML: What Carries Over

12 factor agents on client devices: config, parity and disposability carry over, but measured batch-1 dispatch overhead means you still need a device…

12 Factor Agents for Client-Side ML: What Carries Over
Written by TechnoLynx Published on 11 Jul 2026

What does not carry over is the quiet assumption that the same code costs the same everywhere. On a client the runtime substrate (WebGPU on Vulkan or Metal, WebAssembly, the browser itself) is the hidden environment variable, and measured batch-1 data shows its cost differs by backend and implementation, so it has to be measured rather than assumed. That gap bears on why client-side ML misses latency targets, and closing it takes a device baseline as well as good design.

Where the 12-Factor Pattern Came from, and Why It Needs Adapting

The agent version borrows its name and spirit from the twelve-factor app, the 2011 set of principles for software-as-a-service built around explicit dependencies, config in the environment, stateless processes, disposability and strict dev/prod parity. HumanLayer’s agent factors apply that discipline to LLM applications, on the premise that good agents are mostly deterministic code with model calls placed at the right points. The full list, from natural language to tool calls through to making the agent a stateless reducer, is covered in our piece on 12-factor agent principles, and the LLM-agent reading of the pattern lives in our explainer on engineering principles for production-grade LLM agents.

Even for servers, the original manifesto is best treated as a checklist rather than a religion: keep the intent, adapt the mechanism. A client device fleet stretches that adaptation further than a gRPC service or a long-lived WebSocket ever did.

Which 12 Factor Agents Ideas Matter on a Device, and Which Stay on the Server?

The factors that govern state, context and control flow matter more on a client, because the device constrains memory, can lose its GPU mid-session and gives you no operator to restart things. The factors about channels and triggering are mostly server concerns.

Agent factor What changes on a client device Weight on the client
3. Own your context window The context budget is bounded by device memory as well as model attention, so small, focused context matters twice High
8. Own your control flow Client-side rate limiting, caching and when to break out of the loop become your code’s decisions, not an agent framework’s loop High
10. Small, focused agents Small agents keep context windows manageable and LLM performance high High
12. Stateless reducer (with 5, unified state) If execution state can be rebuilt from the context, a lost runtime can be recreated without losing the task High
6. Launch/pause/resume Pausing maps naturally onto tab suspension and device sleep Medium
1 and 4. Tool calls as structured outputs Unchanged by where the model runs Neutral
11. Trigger from anywhere Slack, email, event and cron triggers are channel integrations, not inference concerns Low on the client

The original app factors that HumanLayer’s list does not restate (config, parity, disposability) are where most of the client-side work sits.

Externalising Device Capability as Config

The twelve-factor config factor defines config as everything likely to vary between deploys and demands strict separation of config from code. On a client, the thing that varies most between “deploys” is the device: which accelerator exists, which precision it supports, how much memory the runtime can claim.

The runtimes already expose the surfaces to make capability an input:

  • ONNX Runtime Web lets you choose the WebAssembly execution provider for very lightweight models and a small binary, or the WebGPU execution provider for compute-heavy models that need the client’s GPU.
  • Windows ML exposes execution providers across NPU, GPU and CPU, with the CPU as the universal fallback. CPU and GPU (via DirectML) work on all supported Windows versions, while hardware-optimised NPU and specific GPU providers require Windows 11 24H2 (build 26100) or later.
  • WebNN takes speed and power preferences (powerPreference of default, high-performance or low-power, plus an accelerated flag) but does not reveal which device was selected or let the developer enumerate devices. It does expose opSupportLimits() so an application can probe operator support and pick the model architecture to deploy for each platform.
  • TensorFlow.js reports whether a device can render float32 textures through the WEBGL_RENDER_FLOAT32_CAPABLE flag, because some mobile WebGL implementations only support 16-bit floats.

Put together, a capability-as-config design probes what the platform will tell you, maps the result onto a small number of named capability tiers, and selects model variant, backend and precision from a table rather than from branches scattered through the inference code. The W3C’s own WebNN use case describes exactly this: detect whether acceleration is available, and load a tiny CPU-capable model on devices without it.

The original factor also insists that config values are granular and orthogonal, never grouped into named “environments”. That is the one place we would bend the rule on a client. Free combinations of backend, precision and model size explode the test matrix, so we would deliberately group them into a handful of tiers you can actually test, and accept the loss of granularity. And with WebNN, the config is a request, not a guarantee: the browser decides, and your telemetry has to tell you what you actually got.

What Dev/Prod Parity Means When Production Is a Fleet of User Devices

The original parity factor targets three gaps (time, personnel and tools) and warns that swapping backing services between development and production, even behind an adapter, lets small incompatibilities through. It asks that every deploy use the same type and version of each backing service. On a client, the “backing service” is the browser, the graphics backend and the driver, and you do not get to choose them.

The smartphone fleet alone is extremely fragmented. Facebook’s study of mobile inference found only 30 smartphone SoCs with more than 1% market share, together covering just 51% of the market, and reported that inference variability in the field is much worse than standalone benchmark results. An analysis of in-browser deep learning across 50 PCs and 20 mobile devices measured in-browser inference at an average of 16.9 times slower than native on PC CPUs and 4.9 times slower on PC GPUs, rising to 7.8 times on mobile GPUs.

Variation also comes from the software stack, not only the silicon. A cross-vendor arXiv characterisation of WebGPU dispatch measured about 1040 µs per dispatch in Firefox on all platforms, against 31.7 µs for Safari on Metal and 71.1 µs for wgpu-native on the same Metal backend. The same study found laptop and mobile GPUs at roughly twice the desktop per-dispatch cost, and saw Chrome on Linux/Vulkan fail shader compilation for models that ran under D3D12 on Windows. Precision is part of parity too: the TensorFlow.js documentation notes that WebAssembly gives portable 32-bit float arithmetic across devices, while WebGL precision is hardware-specific and can fall back to 16-bit on iOS.

Parity on a fleet therefore cannot mean “identical environments”. It means each capability tier has a named reference device and browser that the team tests on continuously, so the gap between the developer’s fastest machine and the median user’s phone is measured rather than assumed.

Disposable Runtimes Across WebGPU, WebAssembly and CPU Backends

The disposability factor asks for processes that start fast, shut down gracefully and survive sudden death without corrupting work. In a browser, sudden death includes losing the GPU device. WebGPU device loss can follow a driver crash, resource pressure, a very long shader, a driver update, or Chrome’s GPU watchdog killing the GPU process. When the device is lost, every buffer, texture and pipeline created with it becomes unusable and has to be recreated and uploaded again.

Treating the runtime as disposable means building for that from the first commit:

  1. Request a fresh adapter immediately before each device request, since adapters expire and a consumed or stale adapter returns a lost device.
  2. Keep the agent’s task state outside the runtime, which is where the stateless-reducer factor pays off: the context, not the GPU, holds the truth.
  3. Define a fallback chain (WebGPU, then WebAssembly, then CPU) as config, so losing the GPU degrades latency instead of failing the task.
  4. Know the ceiling on recovery. In Chrome, a second GPU process crash within two minutes blocks the page from getting a new adapter, and three crashes in two minutes block all pages.
  5. Isolate compute from the UI. WebLLM runs its engine in a web worker so heavy inference does not block the main thread.

Disposability has a latency cost on clients. A recreated runtime has to recreate pipelines and re-upload every resource, and TensorFlow.js recommends warming a model with a same-shaped input before real data if first-prediction time matters. A latency-stable agent budgets for the warm path and the cold path separately, and its fallback chain is only stable if each rung has been measured on the tier that will use it.

Where Measured Dispatch Data Shows the Pattern Stops

Config, parity and disposability make device capability an explicit input. They cannot tell you whether that input will hit a latency target. At batch size 1, the regime of single-stream browser and edge inference, per-operation dispatch overhead rather than kernel compute can dominate cost. The cross-vendor WebGPU study puts the true per-dispatch API cost at 24 to 36 µs on Vulkan and 32 to 71 µs on Metal, with total per-operation overhead of about 95 µs once framework code is included. Without fusion, its torch-webgpu backend ran at CPU speed on its RTX 5090 platform, with the GPU’s compute advantage cancelled by dispatch overhead.

How much the optimisation that fixes this helps depends on the backend. On one RTX 5090 Vulkan setup, kernel fusion cut dispatches from 876 to 564 and improved throughput by 53%, yet Metal showed no benefit (0.95 times under wgpu, 0.91 times under Safari) and browser Vulkan only 1.06 times. The authors conclude that backend choice is the dominant factor in optimisation behaviour. A fused kernel that wins on one cohort can be neutral on another, so an optimisation tuned on the test device is a hypothesis about the rest of the fleet, not a result.

Measurement itself is a trap here. The same study found naive single-operation benchmarks overestimate per-dispatch cost by about 20 times, because they conflate dispatch with GPU-CPU synchronisation. This is why we profile before optimising anything: fusion’s benefit is backend-dependent, and that context only comes from profiling.

The scope of that evidence matters as well. The causal fusion experiment ran on a single platform (RTX 5090, Dawn, Vulkan) at batch 1 in float32, and the authors leave larger batches, where kernel compute starts to dominate, to future work. Their own verdict is that WebGPU inference currently suits latency-tolerant, portability-critical or privacy-sensitive workloads rather than latency-critical serving where CUDA is available. Portability is real, though. WebLLM retained up to about 80% of native MLC-LLM decoding throughput on the same device.

A Device Capability Baseline, Checked Before Tuning

The 12-factor pattern gives you the config surface; the baseline fills it with numbers. Before committing to an optimisation, we would want each of these answered per capability tier:

  • Which backend and browser combination does the tier actually get, as reported by telemetry rather than requested in config?
  • What is the per-dispatch and per-operation overhead on that backend, measured with sequential dispatches rather than isolated single operations?
  • Does the model’s precision survive the tier (float32 textures available, or a 16-bit fallback)?
  • How many dispatches per token or per frame does the model issue, and does fusion help on this backend or only on Vulkan?
  • What do cold start and warm start cost after a device loss?
  • Is p95 latency on the tier’s reference device inside the target, not just the median on the fastest test machine?

For agents built on generative models, TechnoLynx’s generative and agentic AI R&D work is where this profiling and porting effort sits. Whatever the model, the open question the factors leave you with is not “is the agent portable?” but “portable to which tier, at what latency, measured how?”. The published dispatch evidence is batch-1 and mostly float32, so for batched or mixed-precision on-device workloads the honest position is that the baseline still has to be built, not borrowed.