Replace the custom mode/index/seed/start/end machinery with ComfyUI's native per-widget control_after_generate on the role dropdown. The frontend steps the combo itself: increment-wrap cycles roles 0->1->0 (verified ComfyUI_frontend valueControl.ts), randomize picks one, fixed holds. Number-widget increment clamps and never wraps, which is why the old INT index showed huge values and never returned to 0; a combo wraps cleanly and shows role names. Outputs reduced to system_prompt + role_name. Bump 1.0.0 -> 1.1.0. 15 tests pass.
LLM Set Role - Custom node for ComfyUI
A single node that presents a dropdown of LLM roles (system prompts) and outputs the selected role's text as a STRING. Wire that STRING into the system_prompt input of an LLM node (Ollama, etc.) to give the model a consistent role: a style transform, a summarizer, a translator, a captioner, an editor, anything you can write as a system prompt.
The node will be located under Add Node > LLM. Node name: Set Role.
Designed to pair with LLM nodes such as the stavsap/comfyui-ollama pack: this node supplies the system prompt, the LLM node does the generation.
The problem it solves
Multi-stage prompt pipelines reuse the same long system prompts. Pasting that prose into a text box on every workflow is error-prone and hard to keep consistent. This node keeps each role as a Markdown file on disk and exposes them as a dropdown, so a workflow picks a role by name and the exact, version-controlled text flows into the LLM. Modes let you also step or randomize through your roles across a batch.
Nodes included
- Set Role - dropdown of roles from
roles/*.md, outputs the selected role text and its name.
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
role |
combo | first role | The role to output. The list is built from roles/*.md at startup. Add a .md file and restart ComfyUI to add a role. Use the widget's control after generate to step through roles across a batch (see below). |
Outputs
| Output | Type | Description |
|---|---|---|
system_prompt |
STRING | The full text of the selected role file, ready to wire into an LLM node's system_prompt input. |
role_name |
STRING | The selected role's display name, e.g. for logging or filename suffixes. |
Stepping through roles
The role dropdown carries ComfyUI's control after generate control, the
same one on a sampler's seed widget. It steps the dropdown after each
generation, so a batch walks your roles natively, with role names shown (no
index numbers):
- fixed: stay on the selected role.
- increment wrap: advance to the next role each generation and wrap back to the first after the last (Role 0 -> 1 -> ... -> 0). Pick this to cycle through your roles.
- decrement: step backwards.
- randomize: pick a random role each generation (may repeat).
Tip: plain increment (without "wrap") stops at the last role instead of cycling; use increment wrap to loop.
Adding roles
-
Drop a new
.mdfile into theroles/directory. The file content is the system prompt, kept verbatim. Seeroles/example.md.examplefor the format. -
The dropdown label defaults to the prettified filename:
summarizer.mdbecomesSummarizer. -
To set an explicit label, make the first line of the file an HTML comment:
<!-- title: Concise Summarizer -->That line is stripped from the output and is used only as the dropdown label. (An HTML comment is used rather than a
#heading because role files commonly start with their own#heading.) -
Restart ComfyUI so the new file appears in the dropdown. Editing an existing role does not need a restart: the node re-runs when the file changes.
Your roles/*.md files are gitignored, so your prompts stay private and local. The shipped roles/example.md.example is tracked only as a format reference and is not loaded by the node.
Usage
[Set Role].system_prompt -> [Ollama Generate].system_prompt
your prompt text -> [Ollama Generate].prompt
Testing
Unit tests (no ComfyUI needed)
cd ComfyUI_LLMSetRole
python -m unittest test_set_role -v
Expect 15 passing tests (title parsing, filename prettify, label-collision disambiguation, path-traversal rejection, missing-file error, edit hot-reload, bad-encoding tolerance, shipped-role discovery).
In ComfyUI
- Restart ComfyUI so the node loads. Confirm it appears once under Add Node > LLM as Set Role, with no import error in
user/comfyui.log. - Add the node, pick a role (and optionally set its control after generate), and wire
system_promptinto your LLM node. - Run the workflow. The LLM node receives the selected role text.
Installation
ComfyUI Manager (recommended)
In ComfyUI, open Manager > Custom Nodes Manager, search for ComfyUI_LLMSetRole, click Install, then restart ComfyUI.
Manual install
Clone into your ComfyUI custom_nodes directory and restart ComfyUI:
cd ComfyUI/custom_nodes
git clone https://github.com/bradsec/ComfyUI_LLMSetRole
No extra dependencies (Python stdlib only).
Compatibility
Dual API: exports the legacy V1 NODE_CLASS_MAPPINGS and a V3 comfy_entrypoint (comfy_api). On builds whose loader reads NODE_CLASS_MAPPINGS first, the V1 path is used and comfy_entrypoint is skipped, so the node is never registered twice.
Support
If you find this useful, please consider starring the repo. Stars help other people discover these nodes.