Skip to content

LeoYeAI/agent-master-skills / skills/agent-memory

agent-memory

Verified

Persistent memory system for AI agents. Remember facts, learn from experience, and track entities across sessions.

FileKindSize
README.mdmarkdown5.5 KB
SKILL.mdskill md1.5 KB
cli/entity.pyscript3.5 KB
cli/fact.pyscript3.4 KB
cli/learn.pyscript2.3 KB
examples/basic_usage.pyscript2.8 KB
requirements.txtmanifest48 B
src/__init__.pyscript212 B
src/memory.pyscript21.6 KB
tests/test_memory.pyscript5.1 KB

tests/test_memory.py

View on GitHub
"""
Tests for AgentMemory
"""

import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from src.memory import AgentMemory
import tempfile
import os


def test_basic_facts():
    """Test basic fact operations."""
    with tempfile.NamedTemporaryFile(suffix='.db', delete=False) as f:
        db_path = f.name
    
    try:
        mem = AgentMemory(db_path)
        
        # Remember
        fact_id = mem.remember("Test fact", tags=["test"])
        assert fact_id is not None
        
        # Recall
        facts = mem.recall("Test fact")
        assert len(facts) >= 1
        assert facts[0].content == "Test fact"
        assert "test" in facts[0].tags
        
        # Get specific
        fact = mem.get_fact(fact_id)
        assert fact is not None
        assert fact.id == fact_id
        
        # Forget
        mem.forget(fact_id)
        fact = mem.get_fact(fact_id)
        assert fact is None
        
        print("✅ Basic facts test passed")
    finally:
        os.unlink(db_path)


def test_lessons():
    """Test lesson learning."""
    with tempfile.NamedTemporaryFile(suffix='.db', delete=False) as f:
        db_path = f.name
    
    try:
        mem = AgentMemory(db_path)
        
        # Learn
        lesson_id = mem.learn(
            action="Test action",
            context="testing",
            outcome="positive",
            insight="Tests are good"
        )
        assert lesson_id is not None
        
        # Get lessons
        lessons = mem.get_lessons(context="testing")
        assert len(lessons) >= 1
        assert lessons[0].action == "Test action"
        assert lessons[0].outcome == "positive"
        
        # Filter by outcome
        positive = mem.get_lessons(outcome="positive")
        assert len(positive) >= 1
        
        negative = mem.get_lessons(outcome="negative")
        assert len(negative) == 0
        
        print("✅ Lessons test passed")
    finally:
        os.unlink(db_path)


def test_entities():
    """Test entity tracking."""
    with tempfile.NamedTemporaryFile(suffix='.db', delete=False) as f:
        db_path = f.name
    
    try:
        mem = AgentMemory(db_path)
        
        # Track
        entity_id = mem.track_entity(
            "TestPerson",
            "person",
            {"role": "tester"}
        )
        assert entity_id is not None
        
        # Get
        entity = mem.get_entity("TestPerson", "person")
        assert entity is not None
        assert entity.name == "TestPerson"
        assert entity.attributes["role"] == "tester"
        
        # Update
        mem.track_entity("TestPerson", "person", {"role": "senior tester"})
        entity = mem.get_entity("TestPerson", "person")
        assert entity.attributes["role"] == "senior tester"
        
        print("✅ Entities test passed")
    finally:
        os.unlink(db_path)


def test_supersede():
    """Test fact superseding."""
    with tempfile.NamedTemporaryFile(suffix='.db', delete=False) as f:
        db_path = f.name
    
    try:
        mem = AgentMemory(db_path)
        
        # Create original
        old_id = mem.remember("Old fact")
        
        # Supersede
        new_id = mem.supersede(old_id, "New fact")
        
        # Old fact should be superseded
        old_fact = mem.get_fact(old_id)
        assert old_fact.superseded_by == new_id
        
        # Recall should return new fact, not old
        facts = mem.recall("fact")
        contents = [f.content for f in facts]
        assert "New fact" in contents
        # Old fact shouldn't appear in results (superseded)
        
        print("✅ Supersede test passed")
    finally:
        os.unlink(db_path)


def test_stats():
    """Test statistics."""
    with tempfile.NamedTemporaryFile(suffix='.db', delete=False) as f:
        db_path = f.name
    
    try:
        mem = AgentMemory(db_path)
        
        mem.remember("Fact 1")
        mem.remember("Fact 2")
        mem.learn("Action", "context", "positive", "insight")
        mem.track_entity("Entity", "type", {})
        
        stats = mem.stats()
        assert stats["active_facts"] == 2
        assert stats["lessons"] == 1
        assert stats["entities"] == 1
        
        print("✅ Stats test passed")
    finally:
        os.unlink(db_path)


def test_export():
    """Test JSON export."""
    with tempfile.NamedTemporaryFile(suffix='.db', delete=False) as f:
        db_path = f.name
    
    try:
        mem = AgentMemory(db_path)
        
        mem.remember("Export test fact", tags=["export"])
        mem.learn("Export action", "export", "neutral", "Export insight")
        mem.track_entity("ExportEntity", "test", {"key": "value"})
        
        data = mem.export_json()
        
        assert "exported_at" in data
        assert len(data["facts"]) >= 1
        assert len(data["lessons"]) >= 1
        assert len(data["entities"]) >= 1
        
        print("✅ Export test passed")
    finally:
        os.unlink(db_path)


if __name__ == "__main__":
    test_basic_facts()
    test_lessons()
    test_entities()
    test_supersede()
    test_stats()
    test_export()
    print("\n🎉 All tests passed!")
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall