Source-linked AI summary
APE: Agentic Prompt Enhancer for Image Generation and Editing
Zijian Huang, Jay Zhangjie Wu, Zian Wang, Tianshi Cao, Jiasi Chen, Sanja Fidler, Huan Ling, Xuanchi Ren
TL;DR
Text-guided image generation and editing are sensitive to prompt wording and specificity, while strong prompt enhancers often rely on large proprietary LLMs. APE post-trains small models as prompt-enhancement agents, improving benchmark alignment and prompt following and narrowing the gap to closed-source enhancers.
Problem
Text-guided generation and editing are sensitive to prompt wording and specificity, while strong enhancers often rely on large proprietary LLMs.
Source: §1 · p. 4Method
APE post-trains small language models as prompt enhancers, using SAPE for one-pass rewriting and MAPE’s router–rewriter–composer pipeline for compositional requests.
Source: §1 · pp. 4–5Results
Across image generation and editing, post-trained enhancers improve visual alignment and prompt following, narrowing the closed-source gap from −9% to the range of (−3%, +2%); MAPE is especially effective on complex compositional tasks.
Source: §1 · pp. 5–6Takeaways & Limitations
Prompt enhancement is a scalable, trainable component for improving generative visual systems.
Source: §1 · p. 5GRPO and GDPO use only final downstream rewards, leaving finer-grained credit assignment across pipeline stages for future work.
Source: §5 · p. 14
Abstract
from arXiv · showhide
Natural language has become a powerful interface for image generation and editing, yet text-guided visual systems remain highly sensitive to prompt formulation. Semantically similar requests can produce different outputs depending on wording, specificity, and how explicitly visual constraints are stated, motivating prompt enhancement as a trainable component rather than a peripheral user choice. Existing strong enhancers often rely on large, proprietary LLMs such as ChatGPT or Gemini, adding cost, latency, and deployment dependence to the visual generation pipeline. We propose Agentic Prompt Enhancer (APE), a lightweight framework that post-trains small language models (SLMs) as prompt-enhancement agents. APE supports both single-agent rewriting and role-specialized multi-agent enhancement. Its single-agent instantiation, SAPE, rewrites the prompt in one pass, while its multi-agent instantiation, MAPE, decomposes enhancement into a router--rewriter--composer process for handling compositional constraints over objects, attributes, spatial relations, and edits. With task-aware rewards and post-training protocols, APE improves visual alignment and prompt following without modifying the downstream visual model. Experiments on challenging image generation and editing benchmarks demonstrate that post-trained small prompt enhancers reliably outperform their base counterparts, narrowing the gap to closed-source prompt enhancers; in addition, MAPE proves particularly strong on complex compositional tasks within these benchmarks.
1. Introduction
APE treats prompt enhancement as a trainable component of image generation and editing, post-training small language models as single-agent or role-specialized multi-agent enhancers. Its central finding is that these agents improve visual alignment and prompt following without changing the downstream visual model.
- Prompt sensitivity makes semantically similar requests produce different outputs, including failures in spatial relations, preservation of unchanged regions, or compositional correctness.The problem arises from wording, specificity, and how explicitly visual constraints are stated.Source: §1 · p. 4
- Prior work found that richer descriptions improve visual quality and prompt adherence [9], supporting treatment of prompt formulation as essential rather than peripheral.Simple prompts can also prompt failures in positional reasoning, object count, aesthetics, and faithfulness.Source: §1 · p. 4
- APE instantiates lightweight prompt enhancement as SAPE, which rewrites prompts in one pass, and MAPE, for generation and editing.Reinforcement learning on SAPE yields substantial gains in visual alignment and prompt following without modifying the downstream visual model.Source: §1 · pp. 4–5
- MAPE separates semantic-field selection, refinement, and composition across router, rewriter, and composer agents to handle interacting object, attribute, spatial, and editing constraints.This role-specialized process addresses compositional requests that can challenge a single-pass rewriter while keeping the downstream interface lightweight.Source: §1 · p. 5
- Across image generation and editing, APE narrows the gap to closed-source prompt enhancers from −9% to the range of (−3%, +2%), with MAPE especially effective on complex compositional tasks.The reported gains use task-aware rewards and post-training protocols.Source: §1 · pp. 5–6
2. Related Work
Image-generation and editing progress has made prompt quality an important determinant of visual alignment, motivating prompt enhancement that improves outputs without changing the generator. APE builds on prompt-enhancement and multi-agent research by training SLM enhancers and assigning specialized roles to MAPE agents.
Generative Models for Image Synthesis
- Image synthesis has progressed from autoregressive and GAN methods to diffusion and flow matching, while newer generators and editing backbones improve instruction following and fidelity [39] [32] [15] [31] [12] [25] [37] [22] [33] [28] [4] [2] [43] [18] [44].Prompt quality strongly affects semantic alignment and faithfulness across generation and editing [9].Source: §2 · p. 6
Prompt Enhancement
- Prior prompt enhancement uses search, ranking, evolution, LLMs, or learned rewriters, whereas APE trains SLMs and MAPE specializes field selection, rewriting, and composition [51] [40].Earlier image-prompt enhancers were mostly single-stage and relied primarily on prompting or supervised rewriting.Source: §2 · p. 6
3. APE: Agentic Prompt Enhancer
APE post-trains prompt-enhancement agents to rewrite instructions for image generation and editing, optionally using a source image. It offers single-agent SAPE and structured multi-agent MAPE, optimizing rewrites through downstream image rewards while keeping the image model frozen.
3. APE: Agentic Prompt Enhancer
- APE rewrites user instructions, optionally with a source image, into prompts for downstream image generation or editing.Only the prompt-enhancement modules are post-trained; the downstream generator or editor remains frozen.Source: §3 · p. 6, Figure 2 · p. 7
3.4. GRPO and GDPO for Prompt Enhancer Optimization
- APE uses GRPO for scalar feedback and GDPO for multi-reward supervision, with the methods differing mainly in how they construct the advantage signal.GRPO uses a single scalar reward; GDPO normalizes reward dimensions separately before aggregation.Source: §3 · p. 6, §3.4 · p. 8
3.1. Problem Formulation
- Because valid rewrites lack a unique textual ground truth, APE optimizes prompts using rewards computed from their downstream images.The objective is to make those images better satisfy user intent.Source: §3.1 · p. 7, §3.4 · p. 8
3.2. SAPE: Single-Agent Prompt Enhancer
- SAPE directly rewrites an input into a final prompt in one step, suiting local rewriting, stylistic polishing, or moderate attribute expansion.Underspecified, compositional, or constraint-heavy requests can entangle its implicit decisions about what to refine, how, and how to compose the result.Source: §3.2 · p. 7
3.3. MAPE: Multi-Agent Prompt Enhancer
- By making field selection, elaboration, and composition explicit, MAPE targets underspecified or constraint-heavy requests and reduces interference among heterogeneous decisions.Its structured factorization provides a stronger inductive bias than SAPE for harder tasks.Source: §3.3 · pp. 7–8
- MAPE uses a router to select semantic fields, field-specific rewriters to refine them, and a composer to integrate the refinements into a prompt.Fields can cover generation aspects such as subject, appearance, background, composition, lighting, and style, as well as editing constraints such as operation, preserved content, region, and locality.Source: §3.3 · p. 8
3.4. GRPO and GDPO for Prompt Enhancer Optimization
- Post-trained SAPE and MAPE are the default variants; their untrained counterparts are called one-shot SLMs and multi-step prompting (MSP), respectively.For MAPE, users may choose which pipeline modules to optimize.Source: §3.4 · p. 9
4. Experiments
Experiments show that post-training improves small prompt enhancers for image generation, while MAPE’s structured multi-agent design is especially useful for complex prompts. On image editing, enhancement also helps, but success depends on routing that avoids unnecessary rewriting.
4.1. Single Agent Prompt Enhancer for Image Generation
- GRPO improves SAPE over its pretrained counterpart with single rewards, while multi-reward training yields broader gains across evaluation metrics despite a frozen image generator.The trained enhancer also resolves vagueness, grounds abstract descriptions, and avoids excessive or semantically drifting elaboration.Source: Table 3 · p. 10, §4.1 · p. 10, Table 4 · p. 11
4.2. Multi-Agent Prompt Enhancer for Image Generation
- MAPE better grounds fine-grained details, supports spatial and logical reasoning, and preserves original constraints on complex image-generation prompts.Its value is not simply longer prompts, but more coherent integration of constraints and plausible relevant details.Source: §4.2 · pp. 11, 13
- On UniGenBench, MAPE matches or surpasses Gemini-3.1-Pro (MSP) across four T2I backbones and improves over corresponding off-the-shelf Qwen3 enhancers.The Gemini comparison uses decomposed router–rewriter–composer prompting rather than one-shot prompting; MAPE also outperforms unenhanced baselines and SLM baselines.Source: §4.2 · p. 11, Table 5 · p. 12
- MAPE’s gains on Z-Image-turbo increase from multi-step prompting to SFT and then full MAPE with RL, showing contributions from both decomposition and post-training.SFT adds prompt details, while RL helps adapt pipelines to downstream image models.Source: §4.2 · p. 11, Table 5 · p. 12
4.3. Multi-Agent Prompt Enhancer for Image Editing
- MSP generally improves image-editing performance, but Gemini-3.1-Pro performs worse with MSP than one-shot prompting, showing that decomposition does not always help a strong enhancer.Multi-stage processing can propagate errors or confuse information when edit instructions are already clear.Source: §4.3 · p. 13
- +1.67 on Extract, +0.22 on Style, and +0.06 on Adjust contrast with -0.9 on Remove and -0.1 on Action under forced MSP with Qwen3-VL-4B and FLUX.2-klein-4B.MAPE benefits more complicated edits requiring grounding and context preservation, while forced rewriting can hurt simpler, direct edits.Source: §4.3 · p. 13
- Allowing the router to skip rewriting and applying GDPO improves SLM-based editing performance while balancing categories that need grounding against those that benefit from restraint.The findings identify rewrite-field selection and deciding whether rewriting is needed as central to editing performance.Source: §4.3 · p. 13
5. Conclusion
APE enhances image-generation and editing prompts through single-agent SAPE or router–rewriter–composer MAPE, with post-training gains while the image model remains frozen. MAPE further helps on harder compositional tasks, while reliance on final downstream rewards remains a limitation.
5. Conclusion
- Post-training only the prompt enhancer while keeping the image model frozen yields strong gains in image generation and editing.APE uses SAPE for single-agent rewriting and MAPE for router–rewriter–composer enhancement.Source: §5 · p. 14
- For harder compositional tasks, MAPE further improves detail grounding, information preservation, and reasoning over complex prompts.Small, carefully designed prompt enhancers can achieve strong performance, sometimes approaching closed-source systems.Source: §5 · p. 14
- Because GRPO and GDPO use only final downstream rewards, future work will explore finer-grained pipeline-stage credit assignment and extensions to video generation and editing.Source: §5 · p. 14
Appendix
The appendix provides additional qualitative examples, training analyses, ablations, method details, implementation prompts, and related work for APE.
Appendix A
- Appendix A presents more APE qualitative examples, including RL effectiveness and MAPE visualizations on ImgEdit; UniGenBench generation examples appear in Figure 1.The RL examples are in A.1 and the ImgEdit visualizations in A.2.Source: Appendix · p. 15
Appendix B
- Appendix B examines prompt-distribution differences between the prompt enhancer and the effectiveness of MAPE’s training stages.Source: Appendix · p. 15
Appendix C
- Appendix C reports image-generation ablations across all four models, demonstrating benefits of the framework and training method.Source: Appendix · p. 15
Appendix D
- Appendix D details the RL methods, including mathematical formulations of GRPO and VLM-scored GDPO.GRPO is covered in D.1 and GDPO in D.2.Source: Appendix · p. 15
Appendix E
- Appendix E lists the MAPE router, rewriter, and composer prompts for image generation and image editing.Generation prompts are in E.1 and editing prompts in E.2.Source: Appendix · p. 15
Appendix F
- Appendix F provides further details on related work.Source: Appendix · p. 15
A. Visualization · A.1. Visualization of RL effect for Image Generation
The visualization section presents a qualitative comparison of prompts before and after GRPO.
A.1. Visualization of RL effect for Image Generation
- Table 8 compares prompt enhancement before and after GRPO qualitatively.Source: Table 8 · p. 16
A.2. Visualization of Image Editing by MAPE · B. Prompt Length Distribution Change
The section presents a qualitative comparison of one-shot Qwen3-VL-4B and MAPE for image editing, and describes how prompt length changes across enhancer frameworks, training stages, and image-generation models.
A.2. Visualization of Image Editing by MAPE
- Table 9 presents a qualitative image-editing prompt-enhancement comparison between one-shot Qwen3-VL-4B and MAPE (Qwen3-VL-4B) across three parts.The supplied captions identify Part I and the continued Parts II and III, but provide no specific comparison outcomes.Source: Table 9 · pp. 17–19
B. Prompt Length Distribution Change
- Prompt length increases from the original prompt through one-shot SLMs and MSP to MAPE-RL.The section reports this trend from Figure 3.Source: Figure 3 · p. 20, B. Prompt Length Distribution Change · p. 20
- After RL, prompt length differs by image-generation model, which the section interprets as adaptation by the agentic pipeline.The passage says RL can help the pipeline adapt to each model.Source: Figure 3 · p. 20, B. Prompt Length Distribution Change · p. 20
- More test-time computation, the agentic pipeline, and SFT can add details intended to guide downstream image-generation models.The passage presents these as explanations for the increasing prompt length.Source: B. Prompt Length Distribution Change · p. 20
- After RL, FLUX.2-klein-4B is given as a model that prefers shorter prompts, while Z-Image-turbo prefers longer prompts.These are the examples reported in the passage.Source: B. Prompt Length Distribution Change · p. 20
- The passage suggests model capability differences and reliance on details during pretraining may explain these preferences.This explanation is presented as a possibility, not a demonstrated cause.Source: B. Prompt Length Distribution Change · p. 20
C. Ablation Studies
The MAPE ablations show improved image-generation performance and comparable performance to commercial-LLM prompt enhancers, with benefits from its architecture and training stages.
C. Ablation Studies
- MAPE significantly improves image-generation model performance and achieves performance comparable to prompt enhancers using commercial LLMs.The paper reports these findings in Table 10.Source: C. Ablation Studies · p. 20
- Task decomposition, knowledge injection, and downstream image-generation model adaptation each contribute benefits to MAPE.The ablations attribute benefits to both the framework architecture and its training stages.Source: C. Ablation Studies · p. 20
- The ablations assess how MAPE’s architecture and each training stage contribute to its performance.The reported components include task decomposition, knowledge injection, and downstream image-generation model adaptation.Source: C. Ablation Studies · p. 20
D. Details about GRPO and GDPO · D.1. GRPO for Scalar-Reward Optimization
For scalar-reward prompt enhancement, GRPO learns from the downstream image produced by each rewrite, rather than requiring a single correct rewrite. It uses group-relative reward comparisons and applies to both SAPE and MAPE.
D.1. GRPO for Scalar-Reward Optimization
- GRPO suits prompt enhancement because rewrite quality is determined by the resulting image, not by a single correct rewrite.Source: §D.1 · p. 20
- For each state, GRPO samples G candidate prompts from the behavior policy, runs them through the downstream model, and scores each output with a scalar reward.Source: §D.1 · pp. 20, 22
- When several scalar metrics are available, they can be combined into one reward using fixed nonnegative coefficients.Source: §D.1 · p. 22
- GRPO computes a group-relative normalized advantage from the group’s reward mean and standard deviation.Source: §D.1 · p. 22
- Its clipped objective uses an importance ratio comparing current-policy and behavior-policy likelihoods for each candidate prompt.Source: §D.1 · p. 22
- The objective supports either SAPE or MAPE; with MAPE, users can choose which router–rewriter–composer modules to optimize through the final prompt’s likelihood.Source: §D.1 · p. 22
D.2. GDPO for Multi-Reward Optimization · E. Prompts · F. Related Works
This section covers GDPO’s reward-dimension normalization, APE’s separation of enhancer architecture from reward-based optimization, and the routing, rewriting, and MAPE-Edit prompts and rubrics for generation and editing. It also situates prompt enhancement and APE’s small-model agents within related work.
D.2. GDPO for Multi-Reward Optimization
- GDPO normalizes each reward dimension separately before aggregation, then applies batch-wise normalization to preserve training-signal resolution and stabilize advantage scale as reward dimensions change.It addresses reward combinations collapsing to identical normalized advantages under naive multi-reward GRPO; GRPO and GDPO share a clipped policy-optimization backbone but construct advantages differently.Source: §D.2 · p. 22
E.1. Prompts for MAPE-Gen
- For MAPE-Gen, the router always selects short_description and objects, selects text_render only for explicitly requested text, and typically chooses 5–8 domains for elaboration.Domain rewriters produce schema-constrained JSON, adding visually useful details while remaining faithful to the prompt; the composer combines domain specifications into one detailed natural-language prompt and resolves conflicts in favor of more specific descriptions.Source: §E.1 · pp. 23–24
E.2. Prompts for MAPE-Edit
- For MAPE-Edit, the router preserves clear, straightforward instructions but classifies ambiguous or coordinated edits, identifies targets and changes, and supplies structured guidance to specialized rewriters.Its output captures target objects, edit details, preservation requirements, and scene and object perceptions, including localization of modified regions and the expected edited image.Source: §E.2 · pp. 25, 26, 28
- The task is to turn structured editing specifications into one concise editing instruction of 50–80 words (about 30 for simple edits), using direct language and specifying what changes and stays the same.The instruction should avoid vague language, make abstractions concrete, and be written as a single flowing paragraph.Source: §E.2 · p. 29
- Qwen-Image-Edit composers preserve the original intent while refining clarity, adding minimal details when needed, and maintaining human identity consistency for person edits.Replacement instructions specify “Replace Y with X”; style prompts concisely describe visual features, and text content is enclosed in English double quotes.Source: §E.2 · p. 29
- Replacement and addition evaluators use task-specific 5-point scales with three perspectives for judging editing results.The rubrics assess the edit against its instruction and evaluate visual and physical/detail qualities.Source: §E.2 · p. 30
- Object-extraction ratings assess identity, mask precision, and visual quality, with mask and quality scores constrained not to exceed identity.The identity scale runs from incorrect or incomplete objects to the exact requested instance; mask ratings consider edge quality and background purity, while visual-quality ratings cover detail, color, and artifacts.Source: §E.2 · pp. 34–35
- Background-edit ratings cover instruction compliance, visual seamlessness, and physical consistency, with the latter two scores constrained not to exceed compliance.The rubric checks whether the requested background is present while preserving the foreground, how well edges and textures blend, and whether lighting, perspective, and depth are coherent.Source: §E.2 · p. 35
- Hybrid-edit ratings assess compliance, naturalness, and physical consistency across multiple objects and operations, including whether unintended scene changes occur.The rubric expects each target object to receive its specified operation while other elements remain untouched, and evaluates visual blending and physical integration.Source: §E.2 · p. 36
F. Related Works
- Across both tasks, richer, well-grounded descriptions improve semantic alignment, attribute binding, and edit faithfulness [9], motivating trainable prompt formulation; prior methods search, evolve, select, or rewrite prompts [51] [40].Source: F. Related Works · p. 37
- APE treats prompt enhancement as decomposable: MAPE assigns field selection, field-specific rewriting, and final composition to specialized agents, drawing on role-based multi-agent coordination [8] [38].The related-work discussion cites role-playing agents [19], flexible multi-agent conversation, and workflow systems [13] [30] [3] as examples of structured coordination.Source: F. Related Works · p. 37
Related papers
This paper cites
- Score-Based Generative Modeling through Stochastic Differential Equations2020
- Photorealistic Text-to-Image Diffusion Models with Deep Language Understanding2022
- ChatDev: Communicative Agents for Software Development2023
- CLIPScore: A Reference-free Evaluation Metric for Image Captioning2021
- Large Language Model based Multi-Agents: A Survey of Progress and Challenges2024