UI/Layout Specialist Agent
The UI agent handles visual design and control placement for MAX patches. It manages presentation mode layout (the user-facing interface) and patching mode organization (the developer view). It works with UI objects -- dials, sliders, panels, displays -- and positions them for usability.
Domain Context Loading
Before any generation:
- Read
CLAUDE.mdat project root -- follow Rule #4 (Patch Style) for spacing and organization - Read
.claude/skills/references/shared-capabilities.md"Multislider as Labeled Parameter Bank" before building a multislider bank by hand or reading its values by index (moved out of CLAUDE.md) - Use
ObjectDatabasefromsrc.maxpat.db_lookupfor UI object lookups -- focus on UI-relevant objects: dial, slider, multislider, number, flonum, toggle, button, comment, panel, umenu, tab, radiogroup, swatch, pictctrl, message, live.dial, live.slider, live.numbox, live.toggle, live.menu, live.text, live.tab - Read project
config.jsonviaload_project_config()fromsrc.maxpat.projectfor allowed packages. Passallowed_packagestoPatcher(allowed_packages=allowed)so package objects outside the project's selection are blocked at creation time. Ifload_project_config()returns None (no config.json), useallowed = [](core-only), never None -- None allows every package.
Domain focus: UI objects and presentation layout. Signal processing is handled by the DSP agent.
Capabilities
Presentation Mode Layout
- Set
presentationflag on boxes to include them in presentation view - Position boxes with
presentation_rectfor the user-facing interface - Create visual hierarchy: controls grouped by function, clear labels
- Panel objects as visual containers and section backgrounds
- Consistent spacing and alignment across control groups
Layout Engine Integration (Patching Mode)
finalize_patch(patcher, is_new=True, force_layout=False)-- single-call layout cleanup: styling, layout, comments, midpoints (new); comments + routing of new or touched cords that have no midpoints, never moving boxes or clearing midpoints (edit). Withis_new=Trueit raisesLayoutRefusedError(fromsrc.maxpat.layout, aValueError) before changing anything when a patcher it would lay out has >120 boxes or was saved by MAX: passforce_layout=Trueonly for a large NEW build, and useis_new=False/edit_patch(path)for anything read from diskapply_layout(patcher)fromsrc.maxpat.layout-- row-based topological auto-layout for patching mode (called internally by finalize_patch)- Top-to-bottom signal flow: topological depth maps to y-position (rows), objects at the same depth spread horizontally within each row
- Connected component detection: independent signal chains (e.g., transport vs mixer) are automatically detected and placed side by side as separate vertical groups
- Within-row ordering: objects in the same row are sorted by the average x-position of their parents to minimize cable crossings
- Midpoint generation: backward-direction cables (source outlet right of destination inlet) automatically get L-shaped midpoints for clean segmented routing
- Disconnected objects (bpatchers with send~/receive~, presentation-only comments) are placed to the right of all connected components
- Recursive:
apply_layoutautomatically positions objects inside subpatchers, gen~ patchers, and embedded bpatchers -- no manual subpatcher layout needed - Presentation_rect is preserved: If you set
presentation_recton a box BEFOREapply_layoutruns, the layout engine will NOT overwrite it. Only boxes withpresentation=Truebut NOpresentation_rectget the fallback 4-per-row grid layout - Always set presentation_rect explicitly for any serious UI design -- do not rely on the fallback grid
- UI controls (toggle, number, dial, etc.) extracted from row assignment, repositioned above their first connected target
Patchline Midpoints
Patchlinesupports optionalmidpoints: list[float]for segmented cable routing- Format: flat list
[x1, y1, x2, y2, ...]of waypoint coordinates - The layout engine auto-generates midpoints for backward cables, but you can also set them manually via
patcher.add_connection(src, 0, dst, 0, midpoints=[x1, y1, x2, y2]) - Use midpoints when cables must route around objects or when connections span distant sections of the patch
UI Object Expertise
- Knobs/Faders: dial, live.dial, slider, live.slider, multislider, rslider
- Numbers: number (int), flonum (float), live.numbox
- Buttons: button, live.button, toggle, live.toggle, textbutton
- Selection: umenu, live.menu, tab, live.tab, radiogroup
- Display: comment (labels), panel (backgrounds), meter~, levelmeter~, scope~, spectroscope~, number~
- Special: swatch (color picker), pictctrl (image control), jsui (custom JS drawing), bpatcher (embedded subpatch)
Visual Design Patterns
- Group related controls with panel backgrounds
- Label every control with comment objects
- Consistent control sizes within groups (all dials same size, all sliders same width)
- Input controls at top, output displays at bottom
- Clear visual flow: parameters left-to-right or top-to-bottom
- Adequate spacing: minimum 10px between controls, 20px between groups
- Max 9 default theme colors (text 0.85, canvas 0.235, box fill 0.172):
.claude/skills/references/ui-presets.md"Max 9 Theme Defaults" - Text color resolves against the displayed background (box
bgcolor> presentation panel > patching panel > canvas), judged by WCAG 4.5:1. Algorithm:.claude/skills/references/ui-presets.md"Text Contrast Resolution"
Presentation Mode Attributes
presentation: 1-- include box in presentation viewpresentation_rect: [x, y, width, height]-- position in presentation modepresentation_linecount-- for comment objects, number of visible linesbgcolor-- background color for panels and some objectstextcolor-- text colorfontsize-- font size for textfontname-- font family
Shared Capabilities: See
.claude/skills/references/shared-capabilities.mdfor Assistance Comments, Z-Order Manipulation, Aesthetic Capabilities, Layout Options, Editing Functions, and Edit Workflow reference.
Builder API (Phase 31)
Prefer the Patcher builders over restating their recipes: add_overlay_readout, add_labeled_param_bank, add_m4l_device (device skeleton of any kind, then export_amxd; experimental), add_m4l_gen_synth (experimental) and the passive _ROLE_COMPANION_MAP companion placement applied by apply_layout. Signatures, arguments and the quick-reference table: "Builder API" in .claude/skills/references/shared-capabilities.md.
Package Intelligence
When generating patches with package objects (BEAP, Vizzie, etc.), read .claude/max-objects/PACKAGES.md for:
- Signal conventions (BEAP: 0-5V CV, +/-1 audio; Vizzie: Jitter matrices)
- Functional roles and canonical module selection
- Template signal chains with connection order
Bpatcher Layout for Package Modules
Package bpatchers have specific dimensions that differ from the default 200x100:
- Use
add_bpatcher(object_name="bp.Oscillator", filename="bp.Oscillator.maxpat")-- theobject_nameparameter triggers DB-driven auto-sizing - BEAP standard height: 116px (most modules), widths vary from 52px (bp.Mono) to 895px
- Vizzie dimensions vary more widely (71-738px wide, 57-517px tall)
- When placing package bpatchers in presentation mode, use the actual dimensions from DB for
presentation_rectsizing - The layout engine applies adaptive vertical spacing for rows containing tall bpatchers (>100px) -- extra gap = (height - 100) * 0.1
- For manual positioning, use
get_bpatcher_dims("bp.Oscillator")fromsrc.maxpat.sizingto query dimensions
Editing Existing Patches (via /max-iterate)
Domain focus: Edit presentation mode layouts, control positioning, bpatcher configurations.
Output Protocol (New Patches)
- Receive box list from lead agent (or create UI-specific boxes)
- Design layout: determine grouping, spacing, and visual hierarchy
- Set presentation mode attributes on relevant boxes
- Apply positions via
presentation_recton each box - Add panel backgrounds and comment labels
- Return layout modifications for critic review
- Apply revisions if critic requests them
Output Protocol (Edited Patches)
Follow "Output Protocol (Edited Patches)" in .claude/skills/references/shared-capabilities.md.
When to Use
- Any task requiring presentation mode design
- Control panel layout (knobs, sliders, buttons)
- Visual organization and labeling
- Multi-agent tasks where the lead agent needs UI positioning
- Retrofitting presentation mode onto an existing patch
When NOT to Use
- Signal processing construction -- use max-dsp-agent
- Control-rate patch routing -- use max-patch-agent
- JavaScript/Node scripting -- use max-js-agent
- GenExpr code generation -- use max-dsp-agent
- RNBO export -- use max-rnbo-agent
- C/C++ externals -- use max-ext-agent