Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mem0 conversation manager demo

  • Python 3.13 venv in .venv
  • Implements:
    1. Summarize every 6 user–assistant turns (~200 tokens) into a stripe
    2. Each new query loads 6 most relevant memories from mem0ai
    3. Total context = system prompt + long-term memory + stripes + compressed history + running history + latest query
    4. If context > 12k tokens, compress earliest ~6k tokens into ~500-token summary
    5. Long-term memory writes happen through the registered tool when required

Setup

pwsh python3.13 -m venv .venv .\.venv\Scripts\pip install --upgrade pip .\.venv\Scripts\pip install -r requirements.txt

Set environment variables before running:

  • KIMI_API_KEY (or use provided NEXT_PUBLIC_KIMI_API_KEY)
  • KIMI_BASE_URL (defaults to https://api.moonshot.cn/v1)
  • MEM0_API_KEY (optional if using hosted mem0)
  • PRELOADED_STATE_FILE (optional) – path to preprocessed stripes/compressed history JSON

Ingest historical conversations

If you exported all chats into conversations.json, preprocess them into a compact state:

pwsh .\.venv\Scripts\python ingest_conversations.py conversations.json preloaded_state.json

This streams the large JSON with ijson, replays the dialogue with lightweight summarisation/compression, and stores:

  • stripes: ~200-token summaries of every 6-turn window
  • compressed: previously-compressed history chunks (~500 tokens each)
  • history: the most recent uncompressed messages

You can limit ingestion for testing:

pwsh .\.venv\Scripts\python ingest_conversations.py conversations.json preloaded_state.json --limit 10 --dry-run

Finally set PRELOADED_STATE_FILE=preloaded_state.json before running to hydrate the manager with stripes and history.

Run demos

Baseline CLI (JSON output):

pwsh .\.venv\Scripts\python -m src.main

Rich console UI(图形化展示 token & 上下文来源):

pwsh .\.venv\Scripts\python -m src.ui_console

Type /ltm during the session to force a long-term memory write.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages