# Building an agentic design system

> Contracts that stop coding agents drifting.

Canonical: https://someshks.com/work/building-agentic-design-system  
Author: Somesh Kesarla Suresh  
Published: 2026-11-15

| Fact | Detail |
| --- | --- |
| Role | Designer and engineer, solo |
| Timeline | Built alongside the Singularity app |
| Problem | Agents treat a design system as suggestions and ship off-system values. |
| Outcomes | One gate command that fails on drift; Three token tiers in W3C DTCG; Contracts in AGENTS.md |
| Stack | W3C design tokens, TypeScript, React, CI |

`@singularityfm/design-system` runs the Singularity app. Agents write most of its code and I review it. That showed me a design system built for people does not survive an agent.

The [live style guide](https://design.singularityfm.app) shows the components. This page is about what keeps an agent on the system.

## Why agents drift

- **Agents chase the screenshot.** If a raw `#3B82F6` looks closer than `--color-interactive`, they use the hex.
- **Docs are advice.** A Storybook note carries as much weight as a random answer online.
- **Drift compounds.** One off-grid value becomes the example the next agent copies.

> Interactive on the web: Drag-to-compare view of the interface before and after the redesign.

## Contracts, not docs

Each package has an `AGENTS.md` that reads like a contract: what an agent may import, which token does which job, and what it must never do. Agents follow rules they can check. "Spacing comes from `--space-*`" is checkable. "Visual harmony" is not.

## Tokens are the only values

Tokens come in three DTCG tiers: primitive (`sand.600`), semantic (`text.secondary`) and component (`button.bg`). Components never read primitives. So there is one right answer for "secondary text colour", and an agent can search for it.

## One gate, run by everyone

`pnpm run gate` runs types, lint, token lint and contrast checks. Every `AGENTS.md` ends with it, and CI runs the same command. The token lint fails on raw colours, off-scale spacing and primitives in components. The contrast check fails any pair that breaks WCAG 2.2 AA.

The same card, built from a screenshot and built through the gate:

> Interactive on the web: Toggle between a naive agent's output (raw hex and spacing) and the same screen built by an agent gated on design-system tokens.

## What changed

Review got faster. Wrong greys and wrong gaps stopped reaching me, so review became about the design itself. The system also got smaller: when every value must be a token, unused tokens stand out.

## Looking back

- A strict gate slows exploration. I turn it off for throwaway prototypes.
- When a rule changes, `AGENTS.md` changes in the same commit.

The top gate failure: `gap: 12px`. That's what `--space-3` is for.

- Source: https://github.com/somesh-ks/singularityfm-design-system
