android / designer
AGENTS.md1.1k starsChanged 3 months agoApache-2.0View on GitHub
This document describes how an AI agent can interact with the Layout Editor (Designer).
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- compose-designer/AGENTS.mdAGENTS.md
- preview-designer/AGENTS.mdAGENTS.md
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Use NlWriteCommandActionUtil.run() to perform atomic updates.
- Very specific: line 23
Attributes: Use NlComponent.setAttribute() for simple changes.
- Very specific: line 25
Clean-up: Always call backend.reformatAndRearrange() after significant XML edits to maintain file style and consistent indentation.
- Distinctive: line 39
Use Bazel for the core designer tests:
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Designer Agent Guide
This document describes how an AI agent can interact with the Layout Editor (Designer).
Key Entry Points
1. Structural Changes and Undo
Structural changes to the layout (adding/removing/reordering components) MUST be wrapped in an NlWriteCommandAction.
- Use
NlWriteCommandActionUtil.run()to perform atomic updates. - Example:
NlWriteCommandActionUtil.run(component, "Add Widget", () -> { model.addComponent(newComponent, parent, null); });
2. Scene vs Model
- NlModel: Represents the "Source of Truth" (the XML). Use this for data-driven changes (attributes, hierarchy).
- Scene: Represents the "Interaction Layer". Use
SceneManagerto calculate layout positions or handle constraints without touching the XML immediately. NlComponentBackend: (NlComponentBackend.kt) Agents should use the backend to perform low-level XML operations.NlComponent.tagprovides the underlyingXmlTag.
3. View Modification
- Attributes: Use
NlComponent.setAttribute()for simple changes. This maintains the internal cache. - Transactions: For multiple attribute changes, use
AttributesTransaction(AttributesTransaction.java) to batch PSI events and improve performance. - Clean-up: Always call
backend.reformatAndRearrange()after significant XML edits to maintain file style and consistent indentation.
Interaction Handling
InteractionHandler: (InteractionHandler.java) The entry point for mouse/keyboard events. Agents can simulate user input by invokingcreateInteractionOn()for specific ViewHandlers.
Important Considerations for Agents
- Dumb Mode: Many operations (like finding a View's handler based on its FQN) require indices. Check
DumbService.isDumb(project)before performing actions that depend on symbol resolution. - Asynchronous Rendering: Previews are rendered in-process using Layoutlib. Use
RenderService.getLastRenderResult()to check if the current view is up-to-date. IfrenderResult.isValid()returns false, the image may be stale.
Examples and Testing
- Integration Tests:
com.android.tools.idea.uibuilder.surface.NlDesignSurfaceTestshows how to mock user interactions (clicks, drags) on the surface. - Constraint Layout:
com.android.tools.idea.uibuilder.handlers.constraint.ConstraintLayoutHandlerTestdemonstrates how to test complex auto-connect logic.
How to run tests
Use Bazel for the core designer tests:
bazel test //tools/adt/idea/designer:intellij.android.designer_testsRelated Documentation
- Layout Editor Architecture
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

