This guide explains how the Agent Memory System is integrated into your project to automatically track all agent activities.
The Agent Memory System provides persistent memory across agent sessions, enabling:
- Learning from past decisions and errors
- Reusing patterns and solutions
- Maintaining project context
- Automatic health monitoring
When any agent works on this project, the memory system automatically initializes via:
__init__.py- Auto-loads when project is imported.claude_project_init.py- Specifically for Claude agents
The system automatically tracks:
from init_agent_memory import start_task
start_task("Your task description")This:
- Creates a checkpoint
- Stores task context
- Shows relevant memories
- Recommends patterns
from init_agent_memory import complete_task
complete_task(
"Your task description",
success=True,
files_modified=["file1.py", "file2.py"],
errors=[]
)This:
- Stores completion status
- Records files modified
- Stores any errors encountered
- Updates session statistics
from agent_memory import AgentMemory
# Initialize
memory = AgentMemory()
# Store context
memory.store_context("architecture", "Using microservices pattern", "high")
# Store decisions
memory.store_decision(
"Use PostgreSQL",
"ACID compliance needed",
"database.py",
"high",
"MongoDB, SQLite"
)
# Store patterns
memory.store_pattern(
"singleton",
"class Singleton:...",
"Global state management",
"design",
"oop,state"
)
# Query context
context = memory.query_context("architecture", "microservices")
# Get recommendations
patterns = memory.recommend_patterns("authentication", "user login")# Initialize
./agent_memory.sh init
# Store data
./agent_memory.sh store-context "architecture" "Using microservices" "high"
./agent_memory.sh store-decision "Use PostgreSQL" "ACID needed" "db.py" "high"
./agent_memory.sh store-error "TypeError" "Convert using int()" "TYPE_ERROR"
# Query data
./agent_memory.sh query-context "architecture"
./agent_memory.sh recommend "authentication" "login"
# Health check
./agent_memory.sh health
# Generate reports
./agent_memory.sh summary report.mdThe project includes automatic hooks in .agent_hooks/:
python .agent_hooks/pre_task.py "Task description"python .agent_hooks/post_task.py "Task description" true '{"files": [], "errors": []}'.agent_memory/
├── analytics/ # Usage statistics
├── checkpoints/ # Project state snapshots
├── codebase/ # File-specific knowledge
├── context/ # General context
├── decisions/ # Decision logs
├── errors/ # Error patterns
├── knowledge/ # Daily knowledge dumps
├── patterns/ # Reusable patterns
└── sessions/ # Session tracking
Always check existing memory:
# Export memory context
memory.export_for_ai()
# Check recent decisions
decisions = memory.query_context("decisions")
# Look for error patterns
errors = memory.query_context("errors", "similar to your task")- Store important decisions as they're made
- Document error solutions
- Save reusable patterns
- Create checkpoints before major changes
- Store completion status
- Document any issues found
- Update knowledge about modified files
# Agent starts work
memory = initialize_agent("agent-name")
# Check existing context
print("Recent project decisions:")
print(memory.query_context("decisions"))
# Start new task
start_task("Implement user authentication")
# During work - store decisions
memory.store_decision(
"Use JWT for auth",
"Stateless, good for APIs",
"auth.py, middleware.py",
"high"
)
# Store a pattern learned
memory.store_pattern(
"middleware_auth",
"""
@app.middleware
async def auth_middleware(request):
token = request.headers.get('Authorization')
if not verify_token(token):
raise HTTPException(401)
""",
"JWT authentication",
"security",
"auth,jwt,api"
)
# Complete task
complete_task(
"Implement user authentication",
success=True,
files_modified=["auth.py", "middleware.py"],
errors=[{
"type": "ImportError",
"solution": "Added jose package to requirements",
"prevention": "Check imports before implementation"
}]
)Regular health checks help maintain project quality:
./agent_memory.sh healthChecks for:
- Uncommitted changes
- High error frequency
- Stale code patterns
- Missing documentation
Add to .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Start Task with Memory",
"type": "shell",
"command": "python",
"args": [".agent_hooks/pre_task.py", "${input:taskDescription}"]
},
{
"label": "Complete Task with Memory",
"type": "shell",
"command": "python",
"args": [".agent_hooks/post_task.py", "${input:taskDescription}", "true"]
}
]
}- Check directory permissions
- Ensure Python 3.7+ is available
- Verify bash is accessible
- Initialize memory first:
./agent_memory.sh init - Check file permissions in
.agent_memory/
- Clean old sessions:
./agent_memory.sh cleanup 30 - Exclude from git: add
.agent_memory/to.gitignore
To add new memory types:
- Create storage function in
agent_memory.sh - Add query function
- Update Python wrapper in
agent_memory.py - Update documentation
- Memory stored locally by default
- No data sent to external services
- Can be encrypted if needed
- Checkpoint files may contain sensitive code
Add .agent_memory/ to .gitignore to keep memory local.