对话上下文管理
The node that makes multi-turn AI chat work in a ComfyUI graph
- context
ComfyUI isn't a chat app. Each time you hit Queue it re-runs the graph from scratch, and nodes don't remember what you asked last time - which is a real problem once you've got a Gemini LLM or image node in your workflow and you want a conversation: "now make it sunset," "now add a person," "now revert the first edit." That's what this node is for. It reads the pack's running conversation history and hands it to any node that accepts a context input, so your second, third and fourth generations can build on the first.
How it works
The trick is in the name "global context." When the pack's LLM/image nodes (GeminiLLMNode, Gemini3NanoNode, GPT_Image_2_Node) run, they append your prompt and the result to an in-memory conversation store. This node just reads that store and outputs it. But there's a subtlety: ComfyUI would normally skip a node whose output nothing consumes, and would cache results it thinks are unchanged. So the author hard-wired this node to always execute - it's marked as an output node, caching is disabled, and the seed input (which you never need to touch, it defaults to 1) exists purely as a "fake input" that makes ComfyUI treat the node as fresh on every run. Every execution, it prints how many context entries it's passing along to the console, which is a nice sanity check.
The inputs and outputs
seed(INT, default 1) - don't overthink this one. It's a re-execution trigger, not a creative seed.context(ANY) - the output. It's deliberately type-flexible (ANY), because the pack keeps two conversation buckets internally - one for LLM text turns and one for image turns - and the node passes whatever's current.
Wire context into the context input of a Gemini or GPT image node, then queue your next prompt. The model sees your earlier turns and edits accordingly. This is the "multi-turn editing" loop the pack's own workflows rely on.
Installing it
Same pack as everything else here - comfyui-MJAPI-party. ComfyUI Manager: search "mojieapi_party", install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/MoJIeAIGC/comfyui-MJAPI-party.git
Restart, register at mojieaigc.com, and drop your key into config.ini:
[API]
KEY = your_api_key
BASE_URL = https://www.mojieaigc.com/v1/completions
No model files, no heavy dependencies - the install is over in a minute.
Common issues
- The context looks empty. The conversation store lives in RAM and starts blank. If you haven't run a Gemini/GPT node yet in this ComfyUI session, there's nothing to read - run one first, then check the console log for the entry count.
- You queued but the node didn't fire. Check you're not running an old version of the pack; the always-execute flags were added to make this reliable. A stale install behaves like a plain pass-through node.
- Conversations don't survive a restart. They're in-memory, not on disk. That's by design - a chat session is ephemeral, and it's also the main reason to treat the whole LLM-in-ComfyUI idea as a working sketch rather than a production chatbot. It's plenty for iterating on an image in one sitting, which is what the pack's example workflows actually do.
One honest caveat: because context is a global singleton, two independent workflows in the same ComfyUI session can leak conversation history into each other. Run one chat at a time and you won't hit it.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| seed | INT | 11–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| context | ANY | — |