# How to Automate Prompt Generation with the GPT-Image2 Agent Skill

> Automate prompt generation with the GPT-Image2 agent skill. Transform your style library into structured prompt templates using a validation and rendering pipeline. Learn how to streamline your workflow today.

- Repository: [苍何/awesome-gpt-image-2](https://github.com/freestylefly/awesome-gpt-image-2)
- Tags: how-to-guide
- Published: 2026-09-09

---

**The GPT-Image2 agent skill automates prompt generation by transforming a curated style library into structured prompt templates through a validation and rendering pipeline.**

The `freestylefly/awesome-gpt-image-2` repository provides a complete automation framework that converts static style definitions into dynamic, context-aware image prompts. By combining a structured JSON knowledge base with human-readable documentation and a Node.js generation script, the system enables the GPT-Image2 agent to automatically select and compose optimal prompts based on user intent without manual intervention.

## Understanding the GPT-Image2 Agent Skill Architecture

The automation workflow relies on three integrated components that work together to produce the runtime reference consumed by the agent skill.

### The Style Library Data Layer ([`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json))

At the core of the system sits [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json), which stores structured data for **templates**, **categories**, **styles**, and **scenes**. Each template entry contains an ID, multilingual titles, category classification, style tags, scene identifiers, cover image paths, and guidance metadata.

The JSON structure enables the agent to perform semantic matching between user requests and available prompt templates. When you modify this file to add new templates or update existing styles, the automation pipeline detects these changes during the next generation cycle.

### Human-Readable Documentation ([`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md))

Parallel to the JSON data, [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md) provides comprehensive markdown documentation for every template defined in the library. Each template section includes an HTML anchor (`<a name="…"></a>`) that corresponds to the `anchor` field in the JSON entries.

The generation script cross-references these anchors to ensure every JSON entry points to a valid documentation block. This validation step prevents broken references and guarantees that the agent skill always has access to complete template descriptions during prompt selection.

### The Generation Script (`scripts/generate-style-skill.mjs`)

The `scripts/generate-style-skill.mjs` Node.js script (requires Node ≥ 18) serves as the automation engine. It performs three critical validation steps before rendering the final reference:

- **JSON Schema Validation**: Ensures all required fields are present and ID uniqueness is maintained
- **Asset Verification**: Confirms that every cover image referenced in the JSON exists in the repository
- **Anchor Mapping**: Validates that JSON anchors correspond to actual documentation sections in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md)

Upon successful validation, the script renders [`agents/skills/gpt-image-2-style-library/references/style-library.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/agents/skills/gpt-image-2-style-library/references/style-library.md), the comprehensive reference file that the GPT-Image2 skill reads at runtime.

## How the Selection Rules Automate Prompt Building

When the GPT-Image2 agent skill processes a user request, it applies a three-tier matching algorithm defined in the generated reference:

**Step 1 – Category Match**: Product type keywords (e.g., *poster*, *UI*, *icon*) map to a template's `category` field. The agent filters the library to templates matching the requested content type.

**Step 2 – Style Match**: Visual adjectives (e.g., *realistic*, *illustration*, *minimalist*) map to the template's `styles` array. This narrows the selection to templates capable of producing the desired aesthetic.

**Step 3 – Scene Match**: Context keywords (e.g., *commerce*, *travel*, *education*) map to the `scenes` tags, ensuring the template supports the intended use case.

If the user request remains ambiguous after these steps, the skill presents 2–3 strong template directions and requests clarification before composing the final prompt.

## Setting Up the Automation Pipeline

To initialize or update the prompt generation system, execute the generation script after ensuring your style library and documentation are current:

```bash
node scripts/generate-style-skill.mjs

```

The script outputs confirmation when successful:

```bash
Generated GPT-Image2 style skill reference at agents/skills/gpt-image-2-style-library/references/style-library.md

```

After updating [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) or [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md)—whether adding new templates, revising guidance, or updating cover images—simply rerun the script. The GPT-Image2 skill automatically consumes the refreshed reference without requiring code changes:

```bash
git pull  # Retrieve latest library updates

node scripts/generate-style-skill.mjs

```

## Example Template Structure and Usage

A typical entry in [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) follows this structured format:

```json
{
  "id": "t01",
  "title": { "en": "Modern Poster", "zh": "现代海报" },
  "category": "poster",
  "styles": ["realistic", "vibrant"],
  "scenes": ["commerce"],
  "cover": "/images/poster-modern.png",
  "anchor": "modern-poster",
  "useWhen": {
    "en": "When a clean, bold poster is needed.",
    "zh": "需要干净、醒目的海报时。"
  },
  "guidance": {
    "en": ["Use bold typography", "Keep background simple"],
    "zh": ["使用粗体排版", "保持背景简洁"]
  }
}

```

At runtime, the agent skill consumes the generated reference to automate prompt construction:

```javascript
import { loadReference } from 'agents/skills/gpt-image-2-style-library';

const ref = loadReference();                      // reads the generated markdown
const prompt = ref.selectPrompt(userMessage);      // applies the selection rules
await sendToGPTImage2(prompt);

```

The automated output always includes the chosen template name, a copy-paste-ready GPT-Image2 prompt string, and concise constraints specifying aspect ratio, layout requirements, and negative prompts.

## Summary

- The GPT-Image2 agent skill automates prompt generation through a three-part pipeline: JSON data in [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json), documentation in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md), and the Node.js generator at `scripts/generate-style-skill.mjs`.
- **Selection Rules** automate template matching through category, style, and scene keyword analysis.
- Running `node scripts/generate-style-skill.mjs` validates data integrity and produces the runtime reference at [`agents/skills/gpt-image-2-style-library/references/style-library.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/agents/skills/gpt-image-2-style-library/references/style-library.md).
- The system supports continuous expansion—new templates require only JSON updates and documentation anchors before regeneration.
- According to the `freestylefly/awesome-gpt-image-2` source code, the agent handles ambiguity by suggesting 2–3 template options when automatic selection criteria overlap.

## Frequently Asked Questions

### What Node.js version is required to run the generation script?

The `scripts/generate-style-skill.mjs` script requires **Node.js 18 or higher**. Earlier versions may lack support for the modern JavaScript features and APIs used in the file validation and markdown rendering logic.

### How does the agent skill handle ambiguous user requests?

When the **Selection Rules** cannot determine a single best template, the GPT-Image2 skill identifies 2–3 strong template candidates based on partial matches. It presents these options to the user with brief descriptions from the `useWhen` fields, requesting clarification before generating the final prompt string.

### Can I add custom templates without modifying the agent code?

Yes. Add your template to [`data/style-library.json`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/data/style-library.json) with a unique ID, create the corresponding anchor section in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md), place the cover image in the specified path, and run `node scripts/generate-style-skill.mjs`. The agent skill automatically incorporates the new template into its selection logic without requiring changes to the runtime code.

### What validation does the generation script perform?

The script validates JSON schema compliance, ensures **ID uniqueness** across all templates, verifies that referenced cover images exist in the repository, and confirms that every JSON `anchor` field corresponds to an actual HTML anchor in [`docs/templates.md`](https://github.com/freestylefly/awesome-gpt-image-2/blob/main/docs/templates.md). These checks prevent runtime errors and broken references in the generated skill reference file.