Nodes/comfyui-AGSoft/AGSoft Reference to Latent
ComfyUI Node

AGSoft Reference to Latent

The Flux reference-image workflow in one node — encode, attach, and sample

By Art-xmaster·Created 12 months ago·Updated a day ago· 23
AGSoft Reference to Latent
  • positive
  • negative
  • vae
  • image1_mask
  • image1
  • image2
  • image3
  • image4
  • image5
  • image6
  • image7
  • image8
  • image9
  • image10
  • positive
  • negative
  • latent
  • mask
  • image
mode

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:

  1. Your positive and negative conditioning come in from the CLIP/text-encoder side.
  2. Each reference image you connect (image1image10, chosen by mode) gets encoded into latent space with the vae you provide.
  3. 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_mask you 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).

CategoryAGSoft/nodes

Inputs (15)

NameTypeDefaultDescription
positiveCONDITIONINGPositive conditioning from CLIP text encoder. --- Позитивный conditioning от текстового энкодера CLIP.
negativeCONDITIONINGNegative conditioning from CLIP text encoder. --- Негативный conditioning от текстового энкодера CLIP.
vaeVAEVAE model used to encode images into latent space. --- VAE модель, используемая для кодирования изображений в латентное пространство.
modeCOMBONumber of reference images to use (1-10). Dynamically changes the number of 'imageX' inputs. --- Количество используемых эталонных изображений (1-10). Динамически изменяет количество входов 'imageX'.
image1_maskoptMASKMask for the first image. Determines which areas will be affected during generation. Scaled automatically to latent size. --- Маска для первого изображения. Определяет, какие области будут затронуты во время генерации. Автоматически масштабируется до размера латентов.
image1optIMAGEFirst reference image (used as base latent). --- Первое эталонное изображение (используется как базовый латент).
image2optIMAGESecond reference image. --- Второе эталонное изображение.
image3optIMAGEThird reference image. --- Третье эталонное изображение.
image4optIMAGEFourth reference image. --- Четвертое эталонное изображение.
image5optIMAGEFifth reference image. --- Пятое эталонное изображение.
image6optIMAGESixth reference image. --- Шестое эталонное изображение.
image7optIMAGESeventh reference image. --- Седьмое эталонное изображение.
image8optIMAGEEighth reference image. --- Восьмое эталонное изображение.
image9optIMAGENinth reference image. --- Девятое эталонное изображение.
image10optIMAGETenth reference image. --- Десятое эталонное изображение.

Outputs (5)

NameTypeDescription
positiveCONDITIONING
negativeCONDITIONING
latentLATENT
maskMASK
imageIMAGE