Nodes/ComfyUI-ZMongo/10 Build Context Pack
ComfyUI Node

10 Build Context Pack

Give the LLM its memory back — ZMongo 10 Build Context Pack

By CentralFloridaAttorney·Created 5 months ago·Updated 2 months ago· 1
10 Build Context Pack
  • text_agent_config
  • context_pack
  • json
  • context_document_id
  • success
query_text
source_collectiontext_agent_memory
limit8
field_paths_csvmemory_name,memory_type,tags,text,summary,notes,payload
max_source_chars12000
save_context_packtrue
context_pack_namelatest_context_pack
extra_filter_json{}
refresh_token

10 Build Context Pack is the memory-retrieval node in ZMongo's text-agent layer. You give it a query, it pulls the relevant stored records out of your memory collection, feeds them to Gemini, and returns a compact "context pack" - a distilled summary of what your project knows - that other text-agent nodes can use as their backdrop. Think of it as "ask the database what we learned, and hand the LLM a cheat sheet."

This is the piece that makes the prompt-hub idea recursive: you're not just storing prompts, you're storing what worked, and this node turns that accumulated history back into context for the next generation. Long-running projects build a memory that actually influences later prompts instead of forgetting everything between runs.

How it works

The node needs a text_agent_config, which comes from 07 Text Agent Session (ZMongo's config node - it bundles your session, project name, model, temperature, and the collection names to use). Give it query_text and it:

  1. Queries source_collection (default text_agent_memory) for up to limit records for your project, newest first.
  2. Extracts the field_paths_csv fields (default memory_name,memory_type,tags,text,summary,notes,payload) from each record, capped at max_source_chars.
  3. Builds a prompt asking Gemini to distill that into a reusable context pack - style constraints, prompt fragments, project warnings, prior patterns - explicitly instructed not to invent stored facts.
  4. If save_context_pack is on, saves the result to the context collection and returns its ID.

Outputs: context_pack (the distilled text), json (full payload with source counts and the Gemini response), context_document_id (where it was saved), and success.

The inputs that matter

  • text_agent_config - required; wire from 07 Text Agent Session.
  • query_text - what you're asking the memory about.
  • limit - 1–50, default 8. How many memory records to pull.
  • extra_filter_json - extra query filters beyond the project scope, if you need to narrow.
  • save_context_pack / context_pack_name - whether to persist the pack and under what name.

Install

Standard:

cd ComfyUI/custom_nodes
git clone https://github.com/CentralFloridaAttorney/ComfyUI-ZMongo
cd ComfyUI-ZMongo
pip install -r requirements.txt

or ComfyUI Manager → "ComfyUI-ZMongo" → restart. Real talk on dependencies: this node calls Gemini through your session, so you need a session with a Gemini-capable backend configured (an API key), and the pack's Gemini layer pulls in google-genai from the full requirements.

Troubleshooting

  • success: false and empty context_pack - the Gemini call failed. Check the session's API key and that your 07 Text Agent Session model is reachable. The json output has the underlying error.
  • Empty source records - nothing in text_agent_memory for your project. Save some memory first (07 Save Prompt Memory etc.), or change source_collection.
  • Context too short/long - tune limit and max_source_chars (1000–64000, default 12000).
  • Same pack every time - you're querying an empty or unchanged memory store. Context is only as good as what's saved.

Build Context Pack is where ZMongo stops being a database and starts being an agent loop - it's the node that turns stored history into active context, and it's well worth wiring once you have memory records to draw on.

CategoryZMongo/07 Text Agents/Memory

Inputs (10)

NameTypeDefaultDescription
text_agent_configZMONGO_TEXT_AGENT_CONFIG
query_textSTRING
source_collectionSTRINGtext_agent_memory
limitINT81–50
field_paths_csvoptSTRINGmemory_name,memory_type,tags,text,summary,notes,payload
max_source_charsoptINT120001000–64000
save_context_packoptBOOLEANtrue
context_pack_nameoptSTRINGlatest_context_pack
extra_filter_jsonoptSTRING{}
refresh_tokenoptSTRING

Outputs (4)

NameTypeDescription
context_packSTRING
jsonSTRING
context_document_idSTRING
successBOOLEAN