The memory system provides persistent storage for user information using Anthropic’s native memory tool. It implements a filesystem-like interface where the agent can create, view, edit, and delete virtual files in a /memories directory.
Not contain directory traversal patterns (../, ..\\, %2e%2e)
function validatePath(path: string): void { if (!path.startsWith("/memories")) { throw new Error("All memory paths must start with /memories"); } if (path.includes("../") || path.includes("..\\") || path.includes("%2e%2e")) { throw new Error("Invalid path: directory traversal detected"); }}
/memories/facts.txtImportant Facts About User==========================Name: Alex JohnsonSchool: Boston UniversityMajor: Computer Science (sophomore)Canvas Preferences:- Calls "MATH 225 - Calculus II" -> "Calc"- Calls "CS 112 - Data Structures" -> "DS"- Calls "PHYS 201 - Physics I" -> "Physics"Study Habits:- Studies best with music- Takes breaks every 45 minutes- Prefers evening study sessionsKnown Issues:- Canvas API sometimes slow for Physics class- Prefers not to schedule todos before 9am
10. **memory**: Store and retrieve important information about the user - Use to remember user preferences, facts, goals, etc. - Check memory before asking users to repeat information - Proactively save important facts the user shares
Behavioral notes:
- **Use memory to avoid asking redundant questions** - check stored memory before asking for more information- **Proactively save important facts** about the user to memory
Always view memory files before asking the user to repeat information:
# Agent should do this before asking about preferencesresult = memory({"command": "view", "path": "/memories/preferences.txt"})if "does not exist" not in result: # Use existing preferences preferences = resultelse: # Ask user for preferences and save them
Proactive Saving
When users share important information, save it immediately:
User: "I prefer studying in the evening, usually around 7pm"Agent: [Saves to memory]{ "command": "create", "path": "/memories/preferences.txt", "file_text": "Preferred study time: Evening (around 7pm)\n"}[Then responds] "Got it! I'll remember that you prefer evening study sessions around 7pm."
Organize Hierarchically
Use subdirectories for better organization:
/memories/preferences.txt - Core user preferences
/memories/academic/ - Academic-related notes
/memories/personal/ - Personal facts and interests