What You’ll Build
Five sentences about a fictional robotics company are remembered into a permanent graph. A six-turn session then runs on top of it, mixing rules, lessons, and preferences that appear nowhere in those seed documents with ordinary questions — and every turn prints the guidance the session absorbed from it. Every third turn, animprove() checkpoint distills that accumulated guidance into the graph. The payoff is the last two steps: the same lesson is asked for from a brand-new session that has no conversation history to lean on, and the graph is rendered to HTML with the distilled nodes ringed in gold.
The complete runnable script is
examples/demos/sessions/session_flow_stepwise_demo.py —
this page walks through its key moments rather than reproducing it.
Features in Play
- Remember — seeds the permanent graph with the five robotics documents in one call
- Sessions — the shared
session_idthat makes six separaterecall()calls one conversation - Sessions and Caching —
AUTO_FEEDBACKis what turns a stated rule into a gated guidance entry on the turn that states it - Session Distillation — curates those gated entries into permanent
session_learningslessons - Improve — the call the demo fires every third turn to trigger that distillation
- Graph Visualization — renders the finished graph so the distilled nodes can be found by eye
Before You Start
- Complete Quickstart to understand basic operations
- Ensure you have LLM Providers configured — every turn is a live recall, and the distillation checkpoints add more calls on top
- Keep caching enabled so the session cache is available;
CACHE_BACKEND=sqliteis the default, and the script warns on stderr and degrades if the cache is unavailable - Run it from a checkout of the cognee repo: it loads the repo-root
.envwithoverride=Truebefore importing cognee, and writes its narrated log and the graph HTML into a siblinglogs/folder - Expect it to set some environment for you — it forces
AUTO_FEEDBACK=true, defaultsLLM_MODELtoopenai/gpt-4o-minion the OpenAI path when unset, mirrorsLLM_API_KEYintoOPENAI_API_KEY, and skips cognee’s LLM preflight. SetDEMO_USE_OLLAMA=1instead to run it fully locally againstollama serve(see Local Ollama) - The run starts by pruning data and system metadata, so point it at a scratch instance rather than memory you want to keep
How It Works
Stage 1: Seed Permanent Memory
remember() with a dataset_name and no session_id takes the permanent path: add, cognify, then improve. The five documents describe products, firmware, and people at Aurora Robotics — the baseline the session will later be measured against, because nothing in them says what a technician must do after flashing firmware.
Stage 2: Script a Session of Rules and Questions
AUTO_FEEDBACK decides on its own what is worth keeping.
Stage 3: Absorb Guidance Turn by Turn
recall(); the only thing making them a conversation is the shared SESSION_ID. Because AUTO_FEEDBACK is on, each answered turn is also analyzed, and any rule or lesson it states is written into the session’s active-guidance layer as a gated entry — the raw material distillation will later curate.
Stage 4: Distill the Session into the Graph
improve(session_ids=[...]) is what promotes the session’s gated guidance into permanent lessons, so no explicit distillation call is needed. The demo fires it on a simple every-third-turn cadence and then prints the guidance entries with their sections and confidences, so you can see exactly what went in.
Stage 5: Verify from a Fresh Session
session_id, so there is no conversation history to answer from. If the answer still carries the firmware-and-calibration lesson, it can only have come from the graph, which is the whole point of the run.
Stage 6: Find the Distilled Nodes in the Graph
Run It
(A) through (E). (A) prints the RememberResult — status, dataset name, and item count — for the five seeded documents. (B+C) prints each of the six turns with its label and message, and after turns 3 and 6 an auto-extraction checkpoint followed by the absorbed guidance entries, each with its section, confidence, and truncated text. (D) prints the fresh-session question and the answer the long-term graph alone produced. (E) prints the path of the rendered HTML and whether the gold memory ring was found in it. A closing DONE banner repeats the log and visualization paths; the wording of answers and distilled lessons varies by model.
Session Distillation
How gated session guidance becomes permanent
session_learnings lessons.Improve
The operation behind the distillation checkpoints, and what else it bridges.
Sessions
Working with
session_id for conversational memory.Graph Visualization
Rendering a graph to HTML and controlling what it shows.