DEV Community

Cover image for Why AI Coding Agents Fail at UI/UX (And How We Engineered 43 Protocols to Fix It)
Wahyudi
Wahyudi

Posted on Originally published at github.com

Why AI Coding Agents Fail at UI/UX (And How We Engineered 43 Protocols to Fix It)

Why AI Coding Agents Fail at UI/UX (And How We Engineered 43 Protocols to Fix It)

Every engineer who has paired with Claude Code, Cursor, Windsurf, or Google Antigravity knows the 2:00 AM AI UI illusion.

You prompt the model: "Build a high-converting billing dashboard with tiered pricing and usage analytics."

Within twelve seconds, the agent streams four hundred lines of pristine TypeScript. The types check out. The JSX parses without a hitch. You spin up the local server, look at it on your 32-inch 4K display, and think: β€œWe’re living in the future.”

Then you resize the viewport to 390px.

The entire layout disintegrates. Buttons overlap with table headers. The search input creates an aggressive 40px horizontal scrollbar. You click "Submit" on an empty form, and the app crashes into a blank white screen because the agent never handled partial API failures or loading spinners.

What You Asked For:  "A resilient, production-ready SaaS interface"
What You Received:   A fragile CodePen demo dressed in Tailwind utility classes.
Enter fullscreen mode Exit fullscreen mode

πŸ” The Root Cause: Syntax Fluency vs. Architectural Conscience

LLMs don't fail at frontend engineering because they lack raw intelligence. They fail because they lack an architectural conscience.

Large Language Models optimize for immediate token probability and syntactic completeness. When an agent writes code, it draws from millions of public repos, hobby tutorials, and isolated snippets that prioritize the "happy path."

In the real world, production software is 90% edge cases:

  • What happens when a German customer's last name is 45 characters long?
  • What happens when the billing balance is negative (-$1,492.50) instead of positive?
  • What happens when the user's connection drops mid-checkout on a mobile browser?

To bridge the chasm between code generation and world-class product engineering, we spent the last six months building Agentway β€” an open-source framework of 43 modular engineering protocols and CLI automation engines that transform any AI coding agent into an autonomous Lead Product Architect & QA Engineer.


πŸ›οΈ The 9-Layer Architecture: Inside the Engine

Instead of feeding AI vague prompts like "make it clean and modern", Agentway establishes deterministic mathematical boundaries and contract-driven generation across 9 specialized pillars:

Agentway Software Architecture Diagram

[ Visual Intelligence ] ──► [ Design Tokens Engine ] ──► [ 5-State Component Contract ] 
                                                                    β”‚
                                                                    β–Ό
[ Closed-Loop QA ] ◄── [ UX Chaos Monkey Stress Testing ] ◄── [ Design Synthesis ]
Enter fullscreen mode Exit fullscreen mode

πŸ“ 1. Mathematical UX: Replacing Vague Prompts with Cognitive Physics

Traditional AI prompt guidelines say: "Ensure good visual hierarchy." That advice is useless to an LLM.

Agentway replaces subjective aesthetics with verifiable cognitive formulas:

🎯 Hick-Hyman Law (Decision Friction Index)

When scaffolding navigation shells, dropdowns, or dashboard actions, the agent computes the user's decision reaction time ($RT$) before generating markup:

$$RT = b \cdot \log_2(n + 1)$$

If an unscrolled view exposes more than 5 equal-weight actions, the Cognitive Friction Index (CFI) trips a circuit breaker:

  • The agent is forbidden from rendering another button.
  • It is mandated to apply 2-Step Progressive Disclosure (promoting one dominant primary CTA and collapsing auxiliary actions into a contextual menu).

πŸ“ Fitts’s Law (Motor Ergonomics & Safe Zones)

On touch viewports ($w \le 768\text{px}$), target acquisition difficulty is bounded by index of difficulty ($ID$):

$$ID = \log_2\left(\frac{2D}{W}\right) \text{ (bits)}$$

All interactive elements must fit within the natural thumb-reach arc, enforce an uncompromised minimum tap target of $\ge 44\times 44\text{pt}$, and incorporate dynamic env(safe-area-inset-*) padding.


🎭 2. The UX Chaos Monkey: Engineering for Catastrophes

Most development teams test with clean mock data: "Jane Doe", "$49.00", on fiber-optic WiFi.

Real users paste foreign-language documents, enter extreme numeric values, and travel through subway tunnels with flaky 3G connections.

In Agentway v1.5.0, we introduced the UX Chaos Monkey (ux-chaos-monkey) β€” an autonomous destructive testing engine that subjects generated interfaces to three stress vectors:

                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί 1. Text Explosion (German/Russian 45+ chars)
[ Chaos Monkey ] ──┼───────────────► 2. Data Extremes ($999M, -$1.4K, NaN, XSS)
                  └───────────────► 3. Flaky Network (Mid-stream cuts, 30s timeouts)
Enter fullscreen mode Exit fullscreen mode
  1. Text Explosion Test: Injects 45-character German compound words ("Rechnungsabgrenzungsposten"), Finnish agglutinatives, and 40-character emoji strings into badges, table cells, and buttons to guarantee zero horizontal overflow at 320px.
  2. Data Extremes Injection: Verifies that components gracefully format $0, -$1,492.50, $999,999,999.99, NaN, null, and 120-character usernames without truncation breaks.
  3. Flaky Network State: Simulates mid-stream AI disconnections, 30-second server latency spikes, and queues offline form submissions into IndexedDB with FIFO auto-sync on reconnection.

You can generate a turnkey Playwright chaos test suite with a single command:

agentway chaos:inject ./my-app
Enter fullscreen mode Exit fullscreen mode

πŸ›‘οΈ 3. The 5-State Component Resilience Contract

A component’s quality is measured by how it behaves when things go wrong. Agentway forbids the "happy-path-only" antipattern by enforcing a strict 5-State Matrix on every data-driven container:

State What the Agent Is Contractually Obligated to Build
1. Ideal State Full data rendered, design tokens applied, 60fps micro-animations.
2. First-Use Empty Zero user data exists. Explains value proposition + prominent creation CTA.
3. Filtered Empty Search query returned 0 matches. Provides an inline "Clear Filters" action.
4. Partial Failure 3 of 4 dashboard cards loaded. Renders working cards + inline retry on the failed card.
5. Fatal / Timeout Network dropped completely. Diagnostic error message + offline indicator + retry action.

⚑ 4. Zero-Token Overhead: The Magic of Progressive Disclosure

A common question we hear from engineering leads:

β€œIf you have 43 deep engineering protocols, doesn't that consume 50,000 tokens of context before the agent even writes a single line of code?”

No. The idle footprint is exactly 0 tokens.

Agentway operates on Progressive Disclosure:

  • In standard mode, only short trigger signatures are indexed.
  • The agent dynamically loads full protocol instructions into memory only when specific intent is detected (e.g., "audit contrast", "scaffold module", "test checkout flow").
  • Every protocol is secured with a cryptographic SHA-256 hash in skills-lock.json to prevent instruction tampering.

πŸ› οΈ Try It in Your Workflow in 30 Seconds

Agentway is free, open-source under the MIT License, and integrates seamlessly with Claude Code, Google Antigravity IDE, Cursor, and Windsurf.

1. Initialize in Your Project:

npx @uwayxt/agent-skills@latest init
Enter fullscreen mode Exit fullscreen mode

2. Or Install Globally:

npm install -g @uwayxt/agent-skills
agentway list
Enter fullscreen mode Exit fullscreen mode

3. Run the Built-In CLI Engines:

# Compile design tokens to CSS Custom Properties, Tailwind & TypeScript definitions
agentway tokens:build

# Scaffold a resilient 5-state modular slice
agentway scaffold:module BillingAnalytics

# Audit codebase for broken routes, orphaned buttons & dead links
agentway audit:routes

# Evaluate cognitive friction, Hick's Law reaction time & CFI score
agentway audit:cognitive

# Generate Playwright multi-viewport & WCAG 2.2 AA test suite
agentway gen:playwright

# Inject Chaos Monkey stress vectors (Text Explosion & Flaky Network)
agentway chaos:inject
Enter fullscreen mode Exit fullscreen mode

🌐 Community & Ecosystem

Let’s elevate AI coding assistants from simple syntax autocomplete into true Lead Product Architects.


What’s the most frustrating UI bug you’ve ever seen an AI agent generate? Drop your war stories in the comments below! πŸ‘‡

Top comments (0)