examples/long_term_memory/agentic_memory/README.md
This example demonstrates AgenticMemoryMiddleware, a long-term memory middleware backed by human-readable Markdown files.
No vector database or embedding model is required.
main.py runs a single Agent against one workspace directory for two turns:
Turn 1 — persist
Read / Write tools to create or update files under demo_workspace/Memory.Turn 2 — recall
After the first turn, the script prints the generated Markdown files so you can inspect exactly what was persisted.
Install the dependencies by the following commands:
git clone -b main https://github.com/agentscope-ai/agentscope
uv pip install agentscope
# or from source
# uv pip install -e .
Run the example with the commands:
cd agentscope/examples/long_term_memory/agentic_memory
export DASHSCOPE_API_KEY=sk-...; python main.py
The demo workspace is created at:
examples/long_term_memory/agentic_memory/demo_workspace/
The middleware creates this directory automatically:
<workdir>/Memory/
`-- MEMORY.md
The Agent should write each durable memory into its own Markdown file with frontmatter, then add a short pointer to MEMORY.md:
---
name: User profile
description: User lives in Hangzhou and prefers concise Chinese answers
type: user
---
Alice Chen lives in Hangzhou and prefers concise Chinese answers.
MEMORY.md is an index, not the memory body:
- [User profile](user_profile.md) — User location and answer-style preference.
On future turns, MEMORY.md is always included in the system prompt. The middleware can then select relevant topic files by filename and frontmatter description and inject their contents as a hint.
workdir to reuse the same Markdown memory.Agent.state.MEMORY.md should stay concise because it is included in every system prompt.