Project 4: Building an Agent Memory Store

Project 4: Building an Agent Memory Store

Implement long-term persistent memory for an AI Agent. Build a system that tracks user preferences and past events across multiple sessions.

Project 4: Building an Agent Memory Store

Your challenge is to take a simple CLI chatbot and give it a "Memory Bank." The agent should remember a user's name, their favorite programming language, and the project they were working on three days ago.


1. Project Requirements

  • Agent Framework: Simple Python input() loop or a LangGraph agent.
  • Memory Type: Mix of Episodic (Recent chat logs) and Semantic (Extracted facts).
  • Consolidation: A daily "Summarizer" that turns chat logs into persistent facts.

2. Logic Flow

  1. User Input: "I'm move from Python to Go for my latest project."
  2. Action: The agent stores this interaction (Episodic).
  3. Trigger: Every 5 turns, the agent calls an LLM to "Extract Facts."
  4. New Memory: "Preference: Learning Go," "Current Task: Project Migration."
  5. Retrieval: Next time the user asks "What should I do next?", the agent retrieves these facts and suggests Go-related tasks.

3. Implementation (Python)

def consolidate_memory(session_id, collection):
    # 1. Get recent chat logs
    recent_logs = collection.query(
        where={"session_id": session_id, "type": "episodic"},
        n_results=10
    )
    
    # 2. Extract Facts via LLM
    text_to_analyze = " ".join(recent_logs['documents'][0])
    facts = llm.extract_facts(text_to_analyze)
    
    # 3. Store as Semantic Truths
    for fact in facts:
        collection.add(
            documents=[fact],
            metadatas=[{"type": "semantic", "confidence": 0.9}],
            ids=[generate_uid()]
        )

4. Evaluation Criteria

  • Knowledge Retrieval: After telling the agent a fact, can it recall it 20 turns later (after the context window has cleared)?
  • Fact Accuracy: Does the consolidation process correctly extract the "Truth" or does it misinterpret the conversation?
  • Speed: Does the "Recall" step significantly delay the chat response?

Deliverables

  1. A Python script where the agent demonstrates memory across two different execution runs.
  2. A technical diagram of your "Memory Consolidation" pipeline.

Building agents with memory is the key to creating AI that feels truly intelligent. Good luck!

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn