AI Virtual Try-On: Engineering a Reusable Skill and Preview Page
This article explains how to turn AI virtual try-on into a production-ready capability by packaging it as a structured skill and pairing it with a single-file HTML preview page. It covers the limits of ad-hoc chat workflows, a three-layer architecture, an input contract for four reference images, a six-step generation pipeline with targeted retries, a seven-dimension quality checklist with three-tier verdicts, and the delivery package structure along with explicit usage boundaries.
1. Why Ad-Hoc Chat Cannot Support Long-Term Production
In e-commerce visual production, AI virtual try-on usually means this: given a model reference image and a garment product image, the model outputs a commercially usable image of the model wearing that garment. The capability first reached a wide audience with the rise of diffusion models and visual orchestration tools, and was later internalized by many e-commerce teams as plugins or internal tools to cut shooting costs and shorten time-to-market for new items.
However, many teams still work in a “open a chat window, upload two images, describe the requirements repeatedly” mode. This works for one-off validation, but once it enters the daily workflow, three problems surface:
- Not reproducible: once the session context is cleared, all previously tuned constraints, shot planning, and negative prompts are lost.
- Not portable: the capability is bound to a temporary session and cannot be called by other agent frameworks or automation pipelines.
- Not auditable: there is no structured acceptance standard, so whether an output is acceptable depends on individual experience, and teams apply inconsistent criteria.
The right approach is to consolidate the capability into a skill package: a structured specification file that describes inputs, constraints, workflow, and acceptance criteria, plus a visual page (HTML) that handles asset intake, parameter confirmation, and result comparison. This article presents a practical engineering approach from a general technical perspective.
2. Overall Architecture: Skill and Page Each Do Their Own Job
Split the system into three layers to avoid mixed responsibilities:
- Skill layer: centered on a Markdown specification file that defines the role, input contract, processing pipeline, acceptance rules, and refusal policy; it ships with two reference documents, one on shot planning and one on capability description.
- Execution layer: by default, call the image generation capability already available in the host environment, without introducing extra services; add adapters, environment variables, and a backend proxy only when the user explicitly asks for a web deployment or integration with external APIs.
- Interaction layer: a single-file page responsible for asset upload, missing-input validation, shot selection, a 3x3 result grid comparison, and manual review marking.
The benefit of this split: the skill layer can be loaded by any agent that supports a skill mechanism, while the interaction layer can be delivered independently to business users. The two are decoupled through one agreement: input assets + output results + review verdict.
3. Input Contract: Four Reference Images Must Have Single Responsibilities
When virtual try-on results go out of control, the cause is usually not a weak model but confused input responsibilities. The following boundaries must be fixed in the skill specification:
| Reference image | Sole responsibility | Allowed to influence | Must not influence |
|---|---|---|---|
| Model image | Lock the person’s identity | Face shape, hairstyle, skin tone, apparent age | Garment style and scene |
| Garment image | Lock the style and material | Fit, color, pattern, fabric texture | Person’s identity and background |
| Pose image | Control action and composition | Joint angles, camera position, aspect ratio | Garment details and facial features |
| Scene image | Control environment and lighting | Background, weather, light position, color temperature | Garment style and person’s identity |
Also write in a hard constraint: if the model image or the garment image is missing, terminate the flow and ask for the missing asset; never fabricate a person and never fall back to default assets. This may look conservative, but it is the baseline for commercial usability: the wrong model is a brand asset incident.
4. Processing Pipeline: A Six-Step Loop with Targeted Retries
The skill specification should use imperative wording and fix the flow into six steps, each with a clear deliverable:
- Asset analysis: read the four images and output a structured asset list, for example:
{"model": {"present": true, "identity_lock": "face_hair_skin"},"garment": {"present": true, "attributes": ["mid_length", "knit", "beige"]},"pose": {"present": true, "framing": "three_quarter_body"},"scene": {"present": false, "fallback": "plain_studio_light"}}
- Visual planning: based on the intended use (main image, detail page, Lookbook, or social post image), determine the aspect ratio, the number of camera positions, and the shot order, forming a batch shot list.
- Prompt assembly: generate Chinese positive and negative prompts separately. The positive prompt describes “who + wearing what + doing what + in what environment + under what light”; the negative prompt focuses on face swapping, garment deformation, limb malformation, extra people, text, logos, watermarks, and inconsistent lighting.
- Image generation: by default, call the generation capability available in the current environment, without presetting any proprietary API name.
- Quality check: score each item and mark it as “pass / recommend manual review / fail”.
- Targeted retry: change only the failing variables and keep the passed items as they are.
Targeted retry is the key design. Rewriting the whole prompt often fixes the hands but loses the face. Maintain a variable mapping table:
Inconsistent face -> raise model image weight, add "face swap, feature drift" to negativesLost garment pattern -> raise garment image weight, add "wrong fabric, color shift" to negativesMalformed hands -> add "extra fingers, missing fingers, twisted joints"; switch to a pose that hides the hands if neededCluttered background -> raise scene image weight or switch to a plain studio shotText in the image -> add "text, watermark, label, logo" to negatives
5. Quality Checklist: Seven Dimensions and Three Verdicts
Acceptance criteria must be executable. Fix them into seven dimensions:
- Face consistency: whether facial proportions and hairstyle direction match the model image;
- Garment fidelity: whether color, pattern, length, and fit are recognizable;
- Wearing plausibility: whether the layering at the collar, cuffs, and hem follows physical sense;
- Body naturalness: finger count, joint direction, shoulder and neck connection;
- Pose compliance: whether the action and camera position from the pose image are matched;
- Scene and lighting: whether light direction, shadow length, and color temperature are consistent;
- Commercial cleanliness: no text, no watermark, no extra people, no brand marks.
Only three verdicts are allowed, and they must be written into the deliverable:
Pass -> ready to enter the business libraryRecommend manual review -> minor uncertain items exist and need human confirmationFail -> trigger a targeted retry and log the failing variables
6. Page Implementation: The Minimum Viable Form of a Single HTML File
The page needs no framework; one static file covers intake and review. The core logic is local pre-validation and result comparison:
<input type="file" id="model" accept="image/*"><input type="file" id="garment" accept="image/*"><select id="usage"><option>E-commerce main image</option><option>Detail page</option><option>Lookbook</option><option>Social post image</option></select><button id="run">Generate</button><div id="grid"></div><script>const need = ['model', 'garment'];document.getElementById('run').onclick = () => {const missing = need.filter(id => !document.getElementById(id).files.length);if (missing.length) { alert('Missing required assets: ' + missing.join(', ')); return; }// Call the generation capability provided by the host environment, render the 3x3 grid, and attach the three-tier verdict};</script>
The page does only three things: block missing assets, display the comparison, and record the manual verdict. The real constraint logic stays in the skill specification, so the rules do not diverge in two places.
7. Delivery and Boundary Statement
When packaging, remove placeholder content, verify that the directory structure is complete, and compress it into a delivery package with a consistent name. The recommended directory is:
ai-fashion-tryon/├── SKILL.md├── references/│ ├── shot-plans.md│ └── api-reference.md└── preview.html
Finally, two boundaries must be stated clearly in the specification: no promise of absolute fidelity — generated results are probabilistic output and require human final review before commercial placement; and refuse any sexualization of minors or any exploitative content — terminate such requests immediately and explain why. Writing the boundaries into the skill file, instead of relying on the user’s on-the-spot judgment, is what lets this capability run stably in a team over the long term.
