# How Awesome-GPT-Image-2 Structures Prompts for Stability and Reusability

> Discover how Awesome-GPT-Image-2 structures prompts using a three-tier architecture for stability and reusability. Learn to compress prose requests into a structured protocol.

- Repository: [苍何/awesome-gpt-image-2](https://github.com/freestylefly/awesome-gpt-image-2)
- Tags: deep-dive
- Published: 2026-08-28

---

**Awesome-GPT-Image-2 compresses prose-style requests into a structured protocol using a three-tier architecture of JSON-backed libraries, dual-format templates, and programmatic generation skills.**

The `freestylefly/awesome-gpt-image-2` repository treats every image-generation request as a data contract rather than a free-form sentence. By separating **template definition**, **library metadata**, and **runtime generation**, the system ensures that prompts remain consistent across agents, reusable across projects, and resilient against model drift.

## The Three-Pillar Architecture for Stable Prompt Engineering

### Categorized Prompt Library

All prompt templates are stored in a JSON-backed style library located at [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json). This file groups templates by **category** (e.g., `UI`, `Infographic`, `Poster`) and **style** (e.g., `3D`, `Brand`, `Illustration`).

Each entry carries:
- A unique `id` for programmatic reference
- A human-readable `value` for display purposes
- Multilingual titles for internationalization
- A list of **keywords** that help agents match user intent to the correct template

```json
// data/style-library.json (simplified excerpt)
{
  "id": "cat-ui",
  "value": "UI Screenshot",
  "titles": { "zh": "界面截图", "en": "UI Screenshot" },
  "keywords": ["app", "interface", "mobile", "dashboard"],
  "styles": ["iOS", "Android", "Web"]
}

```

This categorization ensures that agents never construct prompts from scratch; they retrieve validated schemas that enforce consistent output formats.

### Template-Driven Prompt Forms

The core prompt definitions live in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md). For every category, the documentation provides two parallel formats:

1. **Plain-text skeletons** with placeholders like `[产品类型]` and `[平台]` for manual editing
2. **JSON-ready advanced templates** that agents emit directly, ensuring data integrity

Crucially, each template section includes an **"avoid-pitfalls"** block that enforces constraints such as *text must be readable*, *aspect ratio must be locked*, and *no ambiguous wording*. For example, the UI template (lines 15-46) specifies that generated screenshots must maintain a 9:16 aspect ratio with a bottom tab bar, while the Poster template (lines 49-60) mandates bleed lines and safe zones for print.

This dual-format approach guarantees that whether a human writes the prompt or an agent generates it, the structure adheres to a well-defined schema that prevents common model failures.

### Programmatic Prompt Generation

The runtime layer isolates prompt construction logic from image generation. When an agent needs a reusable prompt, it invokes the **gpt-image-2-style-library skill** defined in [`agents/skills/gpt-image-2-style-library/SKILL.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/agents/skills/gpt-image-2-style-library/SKILL.md).

The execution flow follows three steps:

1. **Lookup**: The skill queries [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) to find templates matching the user's `category`, `tagLabels`, and `styles`
2. **Hydration**: It fills placeholders (or builds the JSON version) using the user's parameters
3. **Constraint Injection**: It appends technical constraints (aspect ratio locks, negative prompts) from the template's "avoid-pitfalls" section

The resulting structured prompt is then forwarded to [`api/generate-image.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/api/generate-image.js) (line 59), which stores the request for credit tracking before dispatching it to the image-generation service.

```js
// Agent code pattern (simplified)
import { loadLibrary } from '@/agents/skills/gpt-image-2-style-library';

const userIntent = {
  category: 'cat-ui',
  platform: 'iOS',
  product: 'Fitness App',
  style: { theme: 'Dark Mode', primary_color: 'Neon Green' }
};

const prompt = loadLibrary(userIntent);
// Returns a JSON template with all placeholders resolved

```

## Practical Implementation: From Intent to Image

To generate an image using the structured prompt system, an agent hydrates the template and POSTs the resulting JSON to the generation endpoint.

```js
import fetch from 'node-fetch';

// Hydrated template from the style library
const structuredPrompt = {
  "type": "UI Screenshot",
  "platform": "iOS",
  "product": "Fitness App",
  "layout": "Card-based feed with bottom tab bar",
  "style": {
    "theme": "Dark Mode",
    "primary_color": "Neon Green",
    "typography": "Clean sans-serif"
  },
  "constraints": "High fidelity, readable text, 9:16 aspect ratio"
};

const response = await fetch('https://gpt-image2.canghe.ai/api/generate-image', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: JSON.stringify(structuredPrompt),
    caseId: 12345  // Optional tracking ID
  })
});

const { image } = await response.json();
console.log('Generated image URL:', image);

```

By sending the prompt as a JSON string, the system preserves the hierarchical structure that free-form text would otherwise lose, ensuring the model interprets the layout and constraints correctly.

## Extending the System with New Templates

Adding a new style requires only two file updates without touching the generation logic:

1. **Update [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md)**: Append a new markdown section with plain-text and JSON templates
2. **Update [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json)**: Add a new entry mapping the `id` to categories and keywords

For example, to add a "Brand & Logos" template:

```markdown
<a name="tpl-brand"></a>

### Brand & Logos

**JSON 进阶模板（推荐给 Agent 调用）**

```json
{
  "type": "Brand Identity",
  "logo": "Minimalist monogram",
  "color_palette": ["#112233", "#445566"],
  "style": "Modern flat",
  "constraints": "Transparent background, square aspect ratio"
}

```

**避坑指南**
- 防止出现 **文字**：只生成图形标识，不要添加任何文字。
- 锁定 **配色**：使用 `color_palette` 列表，避免模型自行添加额外颜色。

```

The skill layer automatically exposes this template via the `brand` style entry, making it immediately available to all agents without code changes.

## Summary

- **Stability** comes from JSON schemas in [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) and explicit constraint blocks in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) that prevent ambiguous instructions.
- **Reusability** is achieved through the `gpt-image-2-style-library` skill, which allows any agent to reference templates by `id` rather than duplicating prompt text across the codebase.
- **Extensibility** requires only updating the library JSON and markdown templates; the [`api/generate-image.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/api/generate-image.js) endpoint consumes the structured data regardless of the specific category.
- The architecture separates **metadata** (library), **content** (markdown templates), and **runtime** (skill + API), creating a maintainable pipeline for high-fidelity image generation.

## Frequently Asked Questions

### How does the system prevent prompt drift across different agents?

By centralizing templates in [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) and enforcing hydration through the `gpt-image-2-style-library` skill, all agents pull from the same canonical source. The skill resolves user intent into standardized JSON schemas rather than allowing agents to freestyle prompt text, ensuring that terms like "Dark Mode" or "Card-based feed" map to identical visual characteristics every time.

### Can I use the plain-text templates instead of the JSON format?

Yes. The [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) file provides human-readable skeletons with placeholders like `[产品类型]` for manual editing. However, for programmatic use, the JSON templates are recommended because they enforce type safety and automatically include constraint fields (aspect ratio, negative prompts) that prevent model hallucinations.

### What happens if I need to support a new image category like "3D Product Renders"?

You only need to append a new section to [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) with both plain-text and JSON variants, then add a corresponding entry to [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) with appropriate `keywords` and `tags`. The existing `loadLibrary` function in the skill layer will immediately recognize the new category without requiring changes to [`api/generate-image.js`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/api/generate-image.js) or the agent logic.

### How are aspect ratios and readability constraints enforced?

These are stored in the **constraints** field of each JSON template and the **avoid-pitfalls** sections of the markdown documentation. When the skill generates a prompt, it injects these constraints into the final payload. For example, UI templates explicitly lock the `aspect ratio` to `9:16` and mandate `readable text`, while Brand templates enforce `transparent background` and `no text` rules.