Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee Context Manager
ComfyUI Node

EmAySee Context Manager

The original context loop — rolling LLM memory written to a plain text file

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee Context Manager
    • STRING
    file_pathprompt.txt
    history_count2
    mode
    force_resetfalse
    new_generation

    An LLM connector gives ComfyUI a brain, but a brain with amnesia is a limited tool. Every request starts from zero unless you carry history forward - and that's what EmAySee Context Manager is for: a rolling-memory file that persists your conversation between runs, so the model "remembers" what it generated last time.

    It's the original node in the pack's context family, before the V2 and V5 rewrites, and its design tells you exactly how the author thinks about LLM workflows. It maintains a plain text file on disk - default prompt.txt - holding a history of prompt/response blocks, and it has two modes. Read_Context returns the last N blocks as a string (what you feed the LLM as context). Append_and_Prune writes a new generation to the file and keeps only the last N entries. Run one, then the other, in a loop, and you've built conversational memory out of nothing but a text file.

    How it works

    The file format is the contract: blocks are delimited by PROMPT: ... STATE: markers, extracted with a regex that matches PROMPT:.*?STATE:.*? up to the next PROMPT: or end of file. On a Read with an empty file, an optional new_generation input acts as a seed - it's written immediately so the append step later in the same cycle sees it. Writes are flushed and fsynced to disk, which the author explicitly added to dodge Windows/Linux write-caching weirdness.

    The file is resolved with os.path.abspath(file_path) - meaning a relative path like prompt.txt lands in ComfyUI's working directory, not your output folder. Set an absolute path if you want it somewhere predictable.

    The inputs that matter

    • file_path (default prompt.txt) - where the history lives.
    • history_count (2) - how many blocks to keep/return.
    • mode - Read_Context or Append_and_Prune.
    • force_reset - deletes the file, starting clean.
    • new_generation (optional) - the text to append in write mode, or the seed in read mode.

    Output is a single STRING: the context (read mode) or the new generation (write mode).

    Install

    Part of the EmAySee pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes
    

    Restart ComfyUI (or Manager → "ComfyUI_EmAySee_CustomNodes"). Category: EmAySee/Automation. No extra dependencies.

    Gotchas

    The regex is the trap. The block format only matches if the text contains both PROMPT: and STATE: headers - and Context Manager itself doesn't add them. If you append plain text with no STATE:, the read side finds nothing and you're back to an empty context. The V2 node prints every file path and block count to the console as debug spam, which is annoying but also makes this failure visible. And the author's own framing applies: this exists to serve LLM loops that need hand-crafting, not turnkey magic. Hobbyware, no support, README says so - but the format is plain text, so you can always read the file and see exactly what happened.

    CategoryEmAySee/Automation

    Inputs (5)

    NameTypeDefaultDescription
    file_pathSTRINGprompt.txt
    history_countINT21–10
    modeCOMBO2 options: Read_Context, Append_and_Prune
    force_resetBOOLEANfalse
    new_generationoptSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING