Nodes/comfyui-cyberdelia-z-engineer/Cyberdelia Prompt Engineer — Chain
ComfyUI Node

Cyberdelia Prompt Engineer — Chain

One prompt, five LLM passes — chaining system prompts without the drift

By cyberdeliaAI·Created 5 months ago·Updated 5 days ago· 17
Cyberdelia Prompt Engineer — Chain
    • final_prompt
    • stage_1
    • stage_2
    • stage_3
    • stage_4
    • stage_5
    ◄modetrue►
    ◄text►
    ◄stage_count3►
    ◄handoff_modeprevious output only►
    ◄system_prompt_1Rewrite the input into a clear, well-structured image prompt. Return only the revised prompt.►
    ◄system_prompt_2Improve visual detail, composition, lighting, and atmosphere without changing the core concept. Return only the revised prompt.►
    ◄system_prompt_3Polish the prompt for clarity and remove repetition. Return only the final prompt.►
    ◄system_prompt_4►
    ◄system_prompt_5►
    ◄api_urlhttp://localhost:1234/v1►
    ◄modelauto►
    ◄seed0►
    ◄temperature0.70►
    ◄max_tokens600►
    ◄timeout120►
    ◄keep_terms►
    ◄preserve_constraintsfalse►
    ◄clean_outputtrue►
    ◄error_modestop►
    ◄retries1►

    Why you'd want more than one pass

    Ask a chat model to "improve my prompt" once and you get exactly what you'd expect: it adds detail you never asked for, buries your subject under three adjectives, and hands you the plot of a different image. That's not a bug in any particular node, it's what one open-ended rewrite does. The pattern people actually converge on is to narrow the LLM's job and run it in steps - analyse this, then restructure that - because two tightly scoped passes drift far less than one free-form pass.

    Cyberdelia Prompt Engineer - Chain is that idea as a node. It takes one seed prompt and pushes it through between one and five system prompts in sequence, stage 1 feeding stage 2 feeding stage 3, and it hands you the output of every stage so you can see where the thing went wrong instead of just getting a mysteriously bad result at the sampler.

    It's the multi-pass sibling of Prompt Engineer - Text in the same pack: same author (Cyberdelia AI Lab), same pipeline underneath, no CLIP needed, no model downloads - you bring your own local LLM. The pack is a rebuild of BennyDaBall930's ComfyUI-Z-Engineer, so you'll see both names floating around.

    How it works

    The node is the pack's Conditioning node with the encoding stripped out, so each stage is a plain OpenAI-compatible chat completion. stage_count decides how many of the five system_prompt_N fields actually run. Stage 1 receives your text untouched; every later stage receives the previous stage's output - or, with handoff_mode set to original + previous output, a labelled block containing both the seed prompt and the last result, which is what stops a chain from forgetting what you originally asked for.

    Two details you can't guess from the widgets. An empty system_prompt_N field skips that stage entirely - the text passes through unchanged and that stage's preview output shows what came in. And there's one model for the whole chain: model is resolved once before the loop, so you can't put an 8B on stage 1 and a 32B on the polish stage.

    The inputs that matter

    • mode - a boolean toggle, despite the README's parameter table making it sound like a dropdown. On, it runs the chain. Off, it's raw passthrough: your text comes out unchanged, no model discovery, no network call.
    • text - the seed prompt. Everything downstream is a rewrite of this.
    • stage_count - how many stages run, 1–5. Start at two. The default trio (rewrite → add detail → polish) is a reasonable shape, but stage 3 mostly removes repetition that stage 2 added.
    • handoff_mode - previous output only (default) or original + previous output.
    • keep_terms - comma-separated terms that must survive the whole chain, e.g. a LoRA trigger. The node asks the model to keep them and then appends anything missing itself, so you don't lose them to a stage that felt creative.
    • preserve_constraints - off by default. When on, it pulls quoted text, counts, colour phrases, code-like identifiers and lens/aperture strings out of your seed and checks them again at the end.
    • error_mode - stop, fallback_input, or empty. retries (default 1) covers the transient cases only: connection errors, timeouts, HTTP 429 and 5xx.

    api_url defaults to LM Studio at http://localhost:1234/v1. temperature (0.7), seed, max_tokens (600) and timeout (120s) are passed straight to the API per stage. clean_output strips reasoning blocks, ChatML tokens, Markdown fences and "Here is your prompt:" prefixes, and it's on for every stage by default.

    Outputs are all STRING: final_prompt first, then stage_1 through stage_5. Wire final_prompt into whatever encodes your text - a CLIP Text Encode node, a Krea2 encoder, a saver - and hang stage_N off a Preview Text node while you're tuning. Stages you aren't using come back empty. If you wanted sampler-ready conditioning in one step, that's the Conditioning node, not this one.

    Install

    ComfyUI Manager, search Cyberdelia. Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/cyberdeliaAI/comfyui-cyberdelia-z-engineer.git
    pip install -r comfyui-cyberdelia-z-engineer/requirements.txt
    

    Restart ComfyUI. The only dependency is requests, and there are no model files to download - the LLM lives on your side, in LM Studio, Ollama or any OpenAI-compatible server.

    Troubleshooting

    Ollama won't connect, though LM Studio works. The endpoint URL is allowlisted, and only loopback port 1234 is allowed out of the box. To use Ollama's 11434, set this before starting ComfyUI:

    export CYBERDELIA_Z_ENGINEER_ALLOWED_API_URLS="http://127.0.0.1:11434/v1"
    export CYBERDELIA_Z_ENGINEER_API_KEY="your-api-key"   # only if the endpoint wants one
    

    The output is identical to your input. You left mode off. It's the first widget on the node and it's a plain toggle - the README's parameter table calls it "enhanced LLM mode or raw passthrough", which reads like a dropdown and isn't. In passthrough nothing is cleaned, discovered or sent anywhere.

    Everything after one stage is empty. That's error_mode: empty doing what it says - the failed stage returns "", the next stage gets an empty input, and the rest of the chain no-ops into nothing. Use fallback_input instead, or original + previous output handoff, which makes the stage input non-empty even when the previous result isn't.

    auto model selection errors out. It only picks when the choice is unambiguous - with two models loaded it reports the ambiguity rather than guessing. Type the model ID in model, or refresh the list in LM Studio after loading something new.

    It feels slow. It is: five stages is five sequential chat calls, each waiting up to timeout seconds. Keep stage_count at what you can justify, and skip reasoning models here - they're slower and more likely to leak their scratch-work into your prompt.

    CategoryCyberdelia/Prompt

    Inputs (20)

    NameTypeDefaultDescription
    modeBOOLEANtrue—
    textSTRING—
    stage_countINT31–5—
    handoff_modeCOMBOprevious output only2 options: previous output only, original + previous output
    system_prompt_1STRINGRewrite the input into a clear, well-structured image prompt. Return only the revised prompt.—
    system_prompt_2STRINGImprove visual detail, composition, lighting, and atmosphere without changing the core concept. Return only the revised prompt.—
    system_prompt_3STRINGPolish the prompt for clarity and remove repetition. Return only the final prompt.—
    system_prompt_4STRING—
    system_prompt_5STRING—
    api_urlSTRINGhttp://localhost:1234/v1—
    modelSTRINGauto—
    seedINT00–18446744073709550000—
    temperatureFLOAT0.700–2—
    max_tokensINT60050–262144—
    timeoutINT12010–600—
    keep_termsoptSTRING—
    preserve_constraintsoptBOOLEANfalse—
    clean_outputoptBOOLEANtrue—
    error_modeoptCOMBOstop3 options: stop, fallback_input, empty
    retriesoptINT10–3—

    Outputs (6)

    NameTypeDescription
    final_promptSTRING—
    stage_1STRING—
    stage_2STRING—
    stage_3STRING—
    stage_4STRING—
    stage_5STRING—