Nodes/Duanyll Nodepack/LLM Chat Add Message
ComfyUI Node

LLM Chat Add Message

Stuff few-shot examples into your chat before the model ever answers

By Duanyll·Created about a year ago·Updated 4 months ago· 2
LLM Chat Add Message
  • chat
  • images
  • CHAT
user_message
assistant_response

LLM Chat Add Message is the pack's few-shot tool: it appends a complete user+assistant turn to a chat - including optional images - without making any API call. Why would you want to do that? Because showing a model examples is the cheapest way to make it follow a format. One "Here's a good output" example beats three paragraphs of instructions, and this node lets you chain as many as you want before the model ever speaks.

How it works

It takes your chat, appends a user message (text plus any images you wire in), then immediately appends an assistant message with your supplied assistant_response. Both get stored in the standard OpenAI message shape. The images deserve special mention: they're stored as tensors in the message and only converted to base64 PNG data URLs at send time - when the chat finally hits an API call. That conversion respects the client's image_max_pixels limit, downscaling oversized images automatically.

The node runs with INPUT_IS_LIST, which just means it's happy to accept a single chat value and treats it as a list internally. You chain these: Create Chat → Add Message → Add Message → ... → Completion, and the chat grows one complete example at a time.

Inputs and outputs

  • chat - the CHAT to extend.
  • user_message - the example question (multiline).
  • assistant_response - the example answer (multiline).
  • images (optional) - IMAGE(s) to attach to the user message. This is how you show a vision model "here's an image, and here's the kind of thing I want you to say about images like this."

Output: the extended CHAT.

When it's worth it

Two classic uses. First, format enforcement: before asking a model to output JSON, add a turn like "give me the color of the shirt" → {"color": "blue"}. The model then treats JSON output as the established pattern rather than a suggestion. Second, image-reference prompting for vision models: show a reference image paired with a description, then ask about a new image. Both patterns are a lot more reliable than hoping the system prompt sticks.

The honest trade-off: every example you add costs input tokens on every request, and a badly-chosen example can steer the model away from what you want. Keep them short and on-pattern. And remember you still need a LLM Client (API key, endpoint) and a LLM Chat Completion downstream for anything to actually happen - this node just prepares the conversation.

Installing it

It's in Duanyll Nodepack. ComfyUI Manager → search "Duanyll Nodepack" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/duanyll_nodepack

Under duanyll/llm. The pack's LLM family needs a network-visible OpenAI-compatible endpoint and a key - local compute doesn't cover these.

Categoryduanyll/llm

Inputs (4)

NameTypeDefaultDescription
chatCHAT
user_messageSTRING
assistant_responseSTRING
imagesoptIMAGE

Outputs (1)

NameTypeDescription
CHATCHAT