AGSoft Reference to Latent
The Flux reference-image workflow in one node — encode, attach, and sample
- positive
- negative
- vae
- image1_mask
- image1
- image2
- image3
- image4
- image5
- image6
- image7
- image8
- image9
- image10
- positive
- negative
- latent
- mask
- image
Flux doesn't do img2img the way SD 1.5 did. Its family of models expects reference images to arrive inside the conditioning as reference_latents, not as a separate latent you blend - which means the "standard" Flux reference-image workflow is a fiddly multi-node dance with the VAE and some conditioning plumbing. AGSoft Reference to Latent compresses that dance into one node: feed it conditioning, a VAE, and up to ten reference images, and it hands back conditioning that Flux can actually consume, plus a base latent and mask. If you've been copy-pasting Flux reference workflows, this is the part that keeps getting re-wired.
How it works
The mechanism is exactly what the name says, and it's grounded in how Flux conditions:
- Your
positiveandnegativeconditioning come in from the CLIP/text-encoder side. - Each reference image you connect (
image1–image10, chosen by mode) gets encoded into latent space with the vae you provide. - The node calls ComfyUI's own
conditioning_set_values(..., {"reference_latents": ref_latents}, append=True)on both positive and negative - the canonical way to attach reference latents to conditioning for Flux-family models.
The mode dropdown (1_image through 10_image) controls how many imageX inputs appear - dynamic inputs driven by the frontend, so you only see the sockets you need.
It returns five outputs:
- positive / negative - your conditioning, now carrying
reference_latents. - latent - the first reference image encoded as a
LATENT, which serves as the base latent for the sampler (Flux's img2img flow works by sampling from that latent). - mask - the
image1_maskyou optionally supplied, auto-scaled to latent size (this is what limits how much of the base latent gets overwritten). - image - the original first reference image, passed through for convenience (preview, or a second use downstream).
What to wire where
- positive, negative, vae - three required inputs; the VAE must match the model family (Flux's own VAE for Flux workflows - the KB's point about VAE/latent-space compatibility applies: wrong VAE, wrong latent space, garbage out).
- mode - pick how many references; start with 1.
- image1 - your main reference; it becomes both a reference latent and the base latent.
- image1_mask - optional, but this is the lever that makes it "edit this part, keep the rest." Without a mask, the sampler tends to redraw from the whole base latent.
Then take positive/negative and latent into a KSampler. That's the whole integration.
Installing and gotchas
cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft
Restart (or ComfyUI Manager → "comfyui-AGSoft"). No model downloads - you supply your own VAE.
Two traps trip people up. First, the conditioning only helps if your model expects reference_latents - Flux dev/schnell and their derivatives do; SD 1.5/XL checkpoints don't, and wiring this into one of those just silently does nothing useful. Second, resolution: reference images that aren't at a compatible size get rounded to a valid latent size by the node's own helper, but a wildly-off-size reference can still come out stretched - upscale or crop to your target aspect first. If the output ignores the reference entirely, the mask is your first suspect (too tight, or none supplied).
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| positive | CONDITIONING | Positive conditioning from CLIP text encoder. --- Позитивный conditioning от текстового энкодера CLIP. | |
| negative | CONDITIONING | Negative conditioning from CLIP text encoder. --- Негативный conditioning от текстового энкодера CLIP. | |
| vae | VAE | VAE model used to encode images into latent space. --- VAE модель, используемая для кодирования изображений в латентное пространство. | |
| mode | COMBO | Number of reference images to use (1-10). Dynamically changes the number of 'imageX' inputs. --- Количество используемых эталонных изображений (1-10). Динамически изменяет количество входов 'imageX'. | |
| image1_maskopt | MASK | Mask for the first image. Determines which areas will be affected during generation. Scaled automatically to latent size. --- Маска для первого изображения. Определяет, какие области будут затронуты во время генерации. Автоматически масштабируется до размера латентов. | |
| image1opt | IMAGE | First reference image (used as base latent). --- Первое эталонное изображение (используется как базовый латент). | |
| image2opt | IMAGE | Second reference image. --- Второе эталонное изображение. | |
| image3opt | IMAGE | Third reference image. --- Третье эталонное изображение. | |
| image4opt | IMAGE | Fourth reference image. --- Четвертое эталонное изображение. | |
| image5opt | IMAGE | Fifth reference image. --- Пятое эталонное изображение. | |
| image6opt | IMAGE | Sixth reference image. --- Шестое эталонное изображение. | |
| image7opt | IMAGE | Seventh reference image. --- Седьмое эталонное изображение. | |
| image8opt | IMAGE | Eighth reference image. --- Восьмое эталонное изображение. | |
| image9opt | IMAGE | Ninth reference image. --- Девятое эталонное изображение. | |
| image10opt | IMAGE | Tenth reference image. --- Десятое эталонное изображение. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| positive | CONDITIONING | — |
| negative | CONDITIONING | — |
| latent | LATENT | — |
| mask | MASK | — |
| image | IMAGE | — |