Design contracts
intermediate·8 min·Markdown for agents
What this lesson teaches
Give your agent a .design file or a DESIGN.md so it uses your tokens instead of guessing, know which source wins a disagreement, and write design-system docs an agent can actually follow.
Your brand uses 8px corners and one blue. The agent builds a new screen with 6px corners, Inter at 14px and a blue that is almost yours.
It didn't ignore your design system. It never saw one. Write the system down where an agent looks, and this stops.
Two files an agent reads
A is a design decision with a name: colors.accent, rounded.md, motion.duration.base. Components use the name; the value lives in one place.
There are two common files that hold tokens for an agent:
.design | DESIGN.md | |
|---|---|---|
| Made by | AgentsORG (schema design.v1) | Google Labs |
| Shape | a machine-readable contract | tokens up top, prose below |
| Holds | tokens, components, voice, rules, and an intent | tokens, plus an overview and do's and don'ts |
| When both exist | it is the contract | it becomes the rationale |
Who wins a disagreement
Your prompt says one thing, the contract another, the skill a third. The .design format settles this with a fixed order. Toggle the sources below and watch the value change.
How long should the dialog take to open?
The agent uses 400ms, from the .design contract. If that clashes with the skill's 300ms ceiling, it says so once, then complies.
The order, top to bottom: your prompt (this task only), the nearest .design, the design skill's procedure, generic taste skills like design-engineering, and finally the model's defaults.
So if your contract says dialogs open in 400ms, the agent uses 400ms, even though the skill says most UI lands under 300ms. It raises the tension once, in a sentence, then complies.
Silence isn't permission. Where the contract says nothing, the skill's craft still applies.How an agent reads a .design
The agent walks up from the file it is editing to find the nearest contract. In a monorepo, a package's own contract beats the one at the root.
agent.instructions first
The contract's own short brief, written so the file works even with no skill installed.intent
The committed direction, where boldness is allowed (thesignature), and the register: utilitarian or editorial.constraints, policy, decisions
Hard rules, and what to do when a component isn't listed: ask, use the nearest, or invent with a note.tokens, voice, components
Bind every listed property to its token. Apply the voice (casing, terminology, error style) as firmly as the colours.
If there's no contract at all, the agent should offer to create one, after scanning what you already have (global CSS, Tailwind config, an existing DESIGN.md). It should never invent a system silently.
How an agent reads a DESIGN.md
The agent looks in the repo root, then design/, then .design/. The YAML at the top is normative: use {colors.primary}, never a hardcoded hex; match the typography token, not "close enough". The markdown below is context: the overview tells it what the system is trying to feel like, and the do's and don'ts are hard constraints.
The agent never rewrites your DESIGN.md on its own. It may propose an edit, as a review comment, when a token is missing, a pair fails contrast, or a variant like button-primary-active doesn't exist yet.
$ npx -y @google/design.md lint DESIGN.mdBefore writing UI, find our design contract (.design first, then DESIGN.md). Use token references, never raw hex, spacing or radius values. If our contract and your skill disagree, say so once and follow the contract. List any literal you had to leave in place and why.
Writing docs an agent can follow
Tokens say what exists. Docs say when to use what. Every decision the docs leave out gets replaced by a guess, and a guess looks exactly like a decision.
Write them for an engineer who joined yesterday and can never ask you a question.
Inventory the code first
Every token, every component's variant list, two or three real uses each. Never write from memory: that's how agents learn variants that don't exist.Size it
One token file and five components or fewer: one file. Bigger: a short root file plus one file per topic, each under 150 lines.Use the four-part template
For every component, in this order.Verify by prompting
Ask for a real screen in one sentence and read the drift.
The four parts:
- When to use it, and when to use the alternative. "Navigation styled as a button is a Link."
- Which variant applies where, and the default. Then close the set: "Nothing else exists; an unlisted variant is a bug."
- One correct and one incorrect example, from real code.
- A flowchart when there are three or more options.
✕ Hedged
✓ Strict
When the test screen drifts, fix the docs, never just the screen:
| The agent did | The fix |
|---|---|
| hardcoded a colour | move the "semantic tokens only" rule into the root file |
| invented a variant | add "nothing else exists" and tighten the type |
| picked the wrong component | add the when-vs-alternative line for that pair |
Repeat until a fresh prompt drifts zero.
Quick check
Your .design sets dialog duration to 400ms. The skill says most UI should be under 300ms. Your prompt says nothing about it. What should the agent do?
In the skill
The nodes your agent reads when it does this work.
- Using a `.design` contractHow the agent discovers, reads, follows, updates, and verifies a project's .design contract — and why it outranks this skill's defaults.
meta/using-design-file - Using design.mdHow the agent reads, respects, and (rarely) updates a project's DESIGN.md file. Tokens are normative; prose is context.
meta/using-design-md - Design system docs agents can followDocs define when to use what; write them for an engineer who joined yesterday and can never ask. Inventory the code first, size the structure, give every component when/alternative + closed variant set with a default + one correct and one incorrect example + a flowchart, ban hedge words, then verify by prompting and fix the docs, not the output.
meta/design-system-docs
Connected lessons
What this lesson builds on and leads to, across every course.