Nodes/ComfyUI-Session-Memory/πŸ’Ύ Session Memory Writer
ComfyUI Node

πŸ’Ύ Session Memory Writer

Log every run to disk so the next one can learn from it

By LatentnautΒ·Created 5 months agoΒ·Updated 5 months agoΒ· 0
πŸ’Ύ Session Memory Writer
    • run_summary
    • session_id
    β—„session_iddefaultβ–Ί
    β—„promptβ–Ί
    β—„summaryβ–Ί
    β—„max_runs0β–Ί

    The Reader is the brain of this pack, but the Writer is the pen. It sits at the end of your workflow, after the sampler and after whatever LLM summarizer you're running, and it's the node that actually records the run. Feed it the raw prompt and a structured summary, and it appends both to a session file on disk as a paired entry. Next run, the Session Memory Reader picks that entry up and feeds it to your prompt-writing LLM as context. Writer stores, Reader recalls - without the Writer, there's nothing to recall.

    If you're building an LLM-in-the-graph loop - the pattern where a language model in the workflow writes or refines your prompts - this is how you make that loop actually iterative instead of forgetful (llm-in-comfyui.md has the full context on the pattern). One run in, nothing changes. Twenty runs in, your LLM is nudged by a running log of what worked. That's the whole point of "session memory."

    How it works

    The mechanics are gloriously boring, which is the right kind of boring for a memory node. It loads sessions/{session_id}.json, stamps a new --- RUN N --- header on both the prompt and the summary, appends them as one entry, and writes the file back. If the prompt is empty it records a placeholder, and an empty summary becomes (No summary provided for this run) - a run still gets logged, just with a shrug.

    Two behaviors worth knowing. max_runs implements a sliding window: set it to, say, 10 and the Writer trims the oldest entries past that on each write, so the Reader never hands your LLM a novel. Note that run_count stays cumulative even as entries get trimmed - it counts runs ever recorded, not entries on disk. And there's a neat compatibility trick in the load path: legacy sessions with plain-string entries are auto-migrated to the {prompt, summary} format on read, so old files don't break.

    The inputs and outputs that matter

    • session_id - must match the Reader and Feedback Editor. Default default; use something meaningful per project.
    • prompt - the raw prompt that actually went to the model. This is what the Feedback Editor displays when you review, so keep it scoped to the prompts themselves, not a giant blob of workflow junk.
    • summary - the structured summary from your LLM summarizer (the README calls out Gemini, but any text summarizer works). This is what the Reader returns to the next run, so it's the half that does the remembering.
    • max_runs (optional) - the sliding window above; 0 means unlimited.

    Outputs are two pass-throughs: run_summary echoes the summary back out, and session_id chains to the Feedback Editor. The run_summary wire is worth connecting - the Feedback Editor's run_summary input exists specifically to force the editor to run after the Writer, which fixes execution order without you having to reason about ComfyUI's cache.

    Installing it

    Same pack for all four nodes - Latentnaut/ComfyUI-Session-Memory, no models, no exotic dependencies. The README lists the Session Memory Reader/Writer/Feedback Editor; the deprecated Session ID Selector also ships in it.

    cd ComfyUI/custom_nodes
    git clone https://github.com/Latentnaut/ComfyUI-Session-Memory
    

    Restart ComfyUI, or grab it via ComfyUI Manager by searching Session Memory.

    Gotchas

    The session JSON lives inside the custom node's own sessions/ folder, which is gitignored - re-clone the pack and your history is gone, so back it up if the log matters to you. Don't mismatch session_id between Writer and Reader or you'll cheerfully write into one file and read from another. And if your summarizer is absent, the Reader tries to salvage <summary> tags out of the prompt text, but you're better off actually wiring a summary - a run logged with nothing but the raw prompt is a lot less useful next week. Place this node as an output node at the tail of the graph, and let the Feedback Editor do the reviewing.

    Category🧠 Memory

    Inputs (4)

    NameTypeDefaultDescription
    session_idSTRINGdefaultSession identifier. Must match Reader/Feedback.
    promptSTRINGThe raw prompt sent to the model. Displayed in the Feedback Editor.
    summarySTRINGStructured summary from the Gemini Summarizer. Returned by the Reader.
    max_runsoptINT00–100Sliding window: keep only the last N entries. 0 = unlimited.

    Outputs (2)

    NameTypeDescription
    run_summarySTRINGβ€”
    session_idSTRINGβ€”