10 Build Context Pack
Give the LLM its memory back — ZMongo 10 Build Context Pack
- text_agent_config
- context_pack
- json
- context_document_id
- success
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:
- Queries
source_collection(defaulttext_agent_memory) for up tolimitrecords for your project, newest first. - Extracts the
field_paths_csvfields (defaultmemory_name,memory_type,tags,text,summary,notes,payload) from each record, capped atmax_source_chars. - 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.
- If
save_context_packis 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 from07 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: falseand emptycontext_pack- the Gemini call failed. Check the session's API key and that your07 Text Agent Sessionmodel is reachable. Thejsonoutput has the underlying error.- Empty source records - nothing in
text_agent_memoryfor your project. Save some memory first (07 Save Prompt Memoryetc.), or changesource_collection. - Context too short/long - tune
limitandmax_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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| text_agent_config | ZMONGO_TEXT_AGENT_CONFIG | — | |
| query_text | STRING | — | |
| source_collection | STRING | text_agent_memory | — |
| limit | INT | 81–50 | — |
| field_paths_csvopt | STRING | memory_name,memory_type,tags,text,summary,notes,payload | — |
| max_source_charsopt | INT | 120001000–64000 | — |
| save_context_packopt | BOOLEAN | true | — |
| context_pack_nameopt | STRING | latest_context_pack | — |
| extra_filter_jsonopt | STRING | {} | — |
| refresh_tokenopt | STRING | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| context_pack | STRING | — |
| json | STRING | — |
| context_document_id | STRING | — |
| success | BOOLEAN | — |