Implementation Guide — Memory Examples

This directory originally contained Python example scripts that were removed from this archive.
An AI assistant can recreate them by following the instructions below.


conversation_memory.py

Purpose: Show how to maintain multi-turn conversation history with Claude.

What to implement:

  1. Basic message list: Maintain a messages = [] list and append {"role": "user", ...} / {"role": "assistant", ...} each turn.
  2. Sliding window: When len(messages) > N, drop the oldest user+assistant pair to stay within token limits.
  3. Summarization compression: When the window is full, call Claude once to summarize the conversation so far, then replace older messages with {"role": "user", "content": "Conversation summary: ..."}.
  4. Build a simple REPL (input loop) to demonstrate live multi-turn chat.

How to run: python conversation_memory.py
Dependencies: anthropic


external_memory.py

Purpose: Implement long-term agent memory backed by a vector store.

What to implement:

  1. Use chromadb (in-memory mode) or a plain JSON file as the memory store.
  2. Save memory: After each assistant turn, embed the response and upsert it into the store with metadata {turn, timestamp, topic}.
  3. Retrieve memory: Before each user turn, embed the user’s message, retrieve the top-3 most relevant past memories, and inject them into the system prompt as “Relevant past context”.
  4. Demonstrate the agent “remembering” something mentioned several turns ago.

How to run: python external_memory.py
Dependencies: anthropic, chromadb, sentence-transformers