{
  "source_file": "0930",
  "source_platform": "Dev.to",
  "author": "Priyesh Dave",
  "title_listed": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from jarvix-memory and engram",
  "keywords": "",
  "domain": "大模型算法",
  "content_type": "技术教程",
  "is_paid_flag": "否",
  "url": "https://dev.to/priyeshdave6/deconstructing-multi-layer-persistent-memory-in-open-source-ai-agents-insights-from-jarvix-memory-5g62",
  "publish_date": "2026-09-28",
  "corpus_stage": "",
  "notes": "",
  "id": "fd4b3e49e518",
  "collected_at": "2026-10-02T13:48:52",
  "title": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from jarvix-memory and engram - DEV Community",
  "body_markdown": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from jarvix-memory and engram\nPersistent, multi-layer memory architectures are now required for robust open-source AI agents.\nRelying on vector DB retrieval alone undermines continuity and context retention. Stateless agents forget across sessions, which degrades reliability in multi-turn use cases.\njarvix-memory\nand\nengram\nboth implement structured, persistent memory in agentic workflows. This article breaks down their architectures, shows a tested code demo, and exposes the limits of vector-only “memory.”\nStateless and Vector-Only Agents Fail in Real Scenarios\nA single-layer or stateless agent cannot handle multi-turn tasks:\nCatastrophic forgetting\n: Vector retrieval alone discards information. Facts fall below similarity thresholds and become unrecoverable, breaking multi-session workflows.\nIdentity drift\n: No persistent state means agents forget who they are, lose track of active tasks, and contradict themselves.\nContext overflow\n: Stuffing entire histories into the prompt destroys prompt quality. There's no shortcut here; context overloading isn't an answer.\nThese are not corner cases—they’re standard failure modes in deployment.\nMulti-Layer Memory Architecture: Not Optional\nPractical agent memory combines at least three layers:\nVector retrieval (fast, fuzzy search)\n: Good for similarity and recency, but loses detail, logic, and explicit facts.\nLLM-generated summaries\n: Compresses long history into agent-readable state. Reduces context bloat.\nStructured store (SQL, JSON, key-value)\n: Holds critical, precise memory: tasks, user profiles, settings, etc.\nBoth\njarvix-memory\nand\nengram\nprovide APIs for these layers.\njarvix-memory: Concrete Layered Memory Orchestration\njarvix-memory uses a vector DB (Qdrant, Chroma, etc.), structured JSON storage, and LLM-generated summaries. For each user turn:\nInsert:\nMessages and state changes go to both vector and structured stores.\nRecall:\nPrompt construction pulls from similar vector entries, current summary, and structured memory.\nMutate:\nSummaries update at session boundaries or when memory exceeds set limits.\nOrchestration flow:\nUser input received.\nAgent loop ingests input.\nMemory layer retrieves relevant vectors, summary, and structured facts.\nPrompt assembles from all sources.\nLLM responds; new events persisted.\nThe\nJarvixMemory\nclass in the\nrepo\nhandles orchestration.\nengram: Hierarchical Context and Controlled Memory Routing\nengram implements:\nActive/inactive shards:\nOnly relevant memories enter the LLM’s context in a session.\nEvent-triggered updates:\nThe LLM can trigger structured memory writes (e.g., updating project status).\nHierarchical routing:\nMemory access depends on input type, intent, and source.\nThis prevents “context hijacking”—irrelevant but vector-similar memories overwhelming the prompt.\nengram’s docs\ncover schema routing and context gating.\nConcrete Example: Persistent Chat+Task Memory (Tested Code)\nBelow, a runnable Python 3.10+ example integrating OpenAI API (\nv1/embeddings\n,\nv1/chat/completions\n) and explicit error handling. Install dependencies:\npip\ninstall\nfaiss-cpu\n==\n1.7.4\nopenai\n==\n1.10.0\nnumpy\n==\n1.24.4\nEnter fullscreen mode\nExit fullscreen mode\nSample data:\nConversation about booking a trip\nStructured task: \"Book hotel in Kyoto\"\nLLM outputs included below\n# Requires: Python 3.10+, faiss-cpu==1.7.4, openai==1.10.0, numpy==1.24.4\nimport\nfaiss\nimport\nnumpy\nas\nnp\nimport\nopenai\nimport\njson\nimport\nos\nopenai\n.\napi_key\n=\nos\n.\ngetenv\n(\n\"\nOPENAI_API_KEY\n\"\n)\nVECTOR_DIM\n=\n1536\n# Matches text-embedding-ada-002\nclass\nVectorMemory\n:\ndef\n__init__\n(\nself\n):\nself\n.\nindex\n=\nfaiss\n.\nIndexFlatL2\n(\nVECTOR_DIM\n)\nself\n.\nmemory\n=\n[]\ndef\ninsert\n(\nself\n,\ntext\n,\nembedding\n):\nself\n.\nmemory\n.\nappend\n({\n'\ntext\n'\n:\ntext\n,\n'\nembedding\n'\n:\nembedding\n})\nself\n.\nindex\n.\nadd\n(\nnp\n.\narray\n([\nembedding\n]).\nastype\n(\nnp\n.\nfloat32\n))\ndef\nrecall\n(\nself\n,\nquery_embedding\n,\nk\n=\n3\n):\nif\nlen\n(\nself\n.\nmemory\n)\n==\n0\n:\nreturn\n[]\nD\n,\nI\n=\nself\n.\nindex\n.\nsearch\n(\nnp\n.\narray\n([\nquery_embedding\n]).\nastype\n(\nnp\n.\nfloat32\n),\nmin\n(\nk\n,\nlen\n(\nself\n.\nmemory\n)))\nreturn\n[\nself\n.\nmemory\n[\ni\n][\n'\ntext\n'\n]\nfor\ni\nin\nI\n[\n0\n]\nif\ni\n<\nlen\n(\nself\n.\nmemory\n)]\nclass\nStructuredMemory\n:\ndef\n__init__\n(\nself\n):\nself\n.\nstate\n=\n{}\ndef\ninsert\n(\nself\n,\nkey\n,\nvalue\n):\nself\n.\nstate\n[\nkey\n]\n=\nvalue\ndef\nrecall\n(\nself\n,\nkey\n):\nreturn\nself\n.\nstate\n.\nget\n(\nkey\n)\ndef\nupdate\n(\nself\n,\nkey\n,\nvalue\n):\nself\n.\nstate\n[\nkey\n]\n=\nvalue\ndef\nto_json\n(\nself\n):\nreturn\njson\n.\ndumps\n(\nself\n.\nstate\n,\nindent\n=\n2\n)\ndef\nget_embedding\n(\ntext\n):\ntry\n:\nresp\n=\nopenai\n.\nembeddings\n.\ncreate\n(\nmodel\n=\n\"\ntext-embedding-ada-002\n\"\n,\ninput\n=\n[\ntext\n]\n)\nreturn\nresp\n.\ndata\n[\n0\n].\nembedding\nexcept\nException\nas\ne\n:\nprint\n(\n\"\nEmbedding error:\n\"\n,\ne\n)\nreturn\n[\n0.0\n]\n*\nVECTOR_DIM\ndef\nsummarize\n(\nhistory\n):\nprompt\n=\n(\n\"\nSummarize the following conversation in 1-2 sentences:\n\\n\n\"\nf\n\"\n{\nhistory\n}\n\\n\nSummary:\n\"\n)\ntry\n:\nresponse\n=\nopenai\n.\nchat\n.\ncompletions\n.\ncreate\n(\nmodel\n=\n\"\ngpt-3.5-turbo\n\"\n,\nmessages\n=\n[\n{\n\"\nrole\n\"\n:\n\"\nsystem\n\"\n,\n\"\ncontent\n\"\n:\n\"\nYou summarize conversations for an AI agent context.\n\"\n},\n{\n\"\nrole\n\"\n:\n\"\nuser\n\"\n,\n\"\ncontent\n\"\n:\nprompt\n}\n],\nmax_tokens\n=\n50\n)\nreturn\nresponse\n.\nchoices\n[\n0\n].\nmessage\n.\ncontent\n.\nstrip\n()\nexcept\nException\nas\ne\n:\nprint\n(\n\"\nSummarization error:\n\"\n,\ne\n)\nreturn\n\"\nCould not summarize.\n\"\ndef\nagent_respond\n(\nprompt\n):\ntry\n:\nresponse\n=\nopenai\n.\nchat\n.\ncompletions\n.\ncreate\n(\nmodel\n=\n\"\ngpt-3.5-turbo\n\"\n,\nmessages\n=\n[\n{\n\"\nrole\n\"\n:\n\"\nsystem\n\"\n,\n\"\ncontent\n\"\n:\n\"\nYou are a helpful assistant. Use the provided task and memory to help the user.\n\"\n},\n{\n\"\nrole\n\"\n:\n\"\nuser\n\"\n,\n\"\ncontent\n\"\n:\nprompt\n}\n],\nmax_tokens\n=\n60\n)\nreturn\nresponse\n.\nchoices\n[\n0\n].\nmessage\n.\ncontent\n.\nstrip\n()\nexcept\nException\nas\ne\n:\nprint\n(\n\"\nAgent error:\n\"\n,\ne\n)\nreturn\n\"\nI\n'\nm unable to reply right now.\n\"\n# --- Main Loop (real sample data) ---\nvector_memory\n=\nVectorMemory\n()\nstructured_memory\n=\nStructuredMemory\n()\nconversation_history\n=\n[]\nsample_inputs\n=\n[\n\"\nHi, I want to plan a trip to Japan.\n\"\n,\n\"\nBook hotel in Kyoto. task: Book hotel in Kyoto\n\"\n,\n\"\nRemind me where I\n'\nm staying.\n\"\n,\n\"\nWhat\n'\ns my current task?\n\"\n]\nfor\nuser_msg\nin\nsample_inputs\n:\nprint\n(\n\"\n> User:\n\"\n,\nuser_msg\n)\nuser_emb\n=\nget_embedding\n(\nuser_msg\n)\nvector_memory\n.\ninsert\n(\nuser_msg\n,\nuser_emb\n)\nconversation_history\n.\nappend\n(\nuser_msg\n)\nif\n\"\ntask:\n\"\nin\nuser_msg\n:\ntask\n=\nuser_msg\n[\nuser_msg\n.\nindex\n(\n\"\ntask:\n\"\n)\n+\n5\n:].\nstrip\n()\nstructured_memory\n.\ninsert\n(\n\"\ncurrent_task\n\"\n,\ntask\n)\nrecent\n=\nvector_memory\n.\nrecall\n(\nuser_emb\n,\nk\n=\n3\n)\nsummary\n=\nsummarize\n(\n\"\n\"\n.\njoin\n(\nconversation_history\n[\n-\n10\n:]))\ncurrent_task\n=\nstructured_memory\n.\nrecall\n(\n\"\ncurrent_task\n\"\n)\nprompt_parts\n=\n[\nf\n\"\nTask Memory:\n{\ncurrent_task\nor\n'\nNone\n'\n}\n\"\n,\nf\n\"\nSummary:\n{\nsummary\n}\n\"\n,\nf\n\"\nRecall:\n{\n'\n;\n'\n.\njoin\n(\nrecent\n)\n}\n\"\n,\nf\n\"\nUser:\n{\nuser_msg\n}\n\"\n]\nagent_prompt\n=\n\"\n\\n\n\"\n.\njoin\n(\nprompt_parts\n)\nagent_reply\n=\nagent_respond\n(\nagent_prompt\n)\nprint\n(\n\"\nAgent:\n\"\n,\nagent_reply\n)\nconversation_history\n.\nappend\n(\nagent_reply\n)\nEnter fullscreen mode\nExit fullscreen mode\nExpected Output:\n> User: Hi, I want to plan a trip to Japan.\nAgent: Great! What cities or activities are you interested in for your Japan trip?\n\n> User: Book hotel in Kyoto. task: Book hotel in Kyoto\nAgent: Noted. Your current task is to book a hotel in Kyoto. Would you like recommendations or should I proceed with a booking?\n\n> User: Remind me where I'm staying.\nAgent: You are booking a hotel in Kyoto as your current task.\n\n> User: What's my current task?\nAgent: Your current task is: Book hotel in Kyoto.\nEnter fullscreen mode\nExit fullscreen mode\nTested Sequence:\nEach input is embedded and indexed in FAISS.\nAny\ntask:\nannotation is tracked in structured memory.\nA summary of the last 10 turns compresses history for the LLM.\nThe assistant reply is context-aware and task-accurate, using all three memory layers.\nDataset/statistics:\nFour sample turns, spanning one tracked task.\nStructured memory accuracy: 100% in this example (agent response matches tracked task).\nWhere Layered Memory Breaks and Where It Wins\nLLM hallucination:\nSummaries may degrade if model output is sloppy or incomplete.\nSchema drift:\nStructured memory needs versioning; schema must be kept consistent.\nPerformance:\nLayered memory adds read/write overhead. Throughput is not benchmarked here.\nAnecdotal context:\nUser reports (see\nHacker News\n) put vector-only retrieval error rates at ~30% for personal copilots, dropping to ~12% error with hybrid multilayer memory. This is not a controlled benchmark and depends on LLM, embedding, and orchestration design.\nVector-Only Memory Is Obsolete for Agentic Workflows\nOpen-source agents must now implement persistent, multi-layer memory. Vector-only setups are outclassed. jarvix-memory and engram set the minimum standard. If you’re designing memory, start with multilayered persistence. Stateless and vector-only approaches cannot support complex agent workflows—code and patterns above give you a foundation worth building on.",
  "metadata": {
    "title": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from jarvix-memory and engram - DEV Community",
    "description": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from... Tagged with ai, agenticai, machinelearning, llm.",
    "keywords": "ai, agenticai, machinelearning, llm, software, coding, development, engineering, inclusive, community",
    "author": null,
    "og:type": "article",
    "og:url": "https://dev.to/priyeshdave6/deconstructing-multi-layer-persistent-memory-in-open-source-ai-agents-insights-from-jarvix-memory-5g62",
    "og:title": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from jarvix-memory and engram",
    "og:description": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from...",
    "og:site_name": "DEV Community",
    "og:image": "https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa1xy43m7zjt63759khbo.png",
    "twitter:site": "@thepracticaldev",
    "twitter:creator": "@",
    "twitter:title": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from jarvix-memory and engram",
    "twitter:description": "Deconstructing Multi-Layer Persistent Memory in Open-Source AI Agents: Insights from...",
    "twitter:card": "summary_large_image",
    "twitter:widgets:new-embed-design": "on",
    "twitter:image:src": "https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa1xy43m7zjt63759khbo.png"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "file": "attachments/fd4b3e49e518/code/body-000.txt",
      "chars": 58,
      "language": "text"
    },
    {
      "file": "attachments/fd4b3e49e518/code/body-001.txt",
      "chars": 3805,
      "language": "text"
    },
    {
      "file": "attachments/fd4b3e49e518/code/body-002.txt",
      "chars": 494,
      "language": "text"
    }
  ],
  "images": [],
  "audio": [],
  "videos": [],
  "links": [
    {
      "href": "https://github.com/gat45/jarvix-memory",
      "label": "jarvix-memory",
      "type": "a"
    },
    {
      "href": "https://github.com/raya-ac/engram",
      "label": "engram",
      "type": "a"
    },
    {
      "href": "https://news.ycombinator.com/item?id=45329322",
      "label": "Hacker News",
      "type": "a"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T10:48:01Z",
  "source_url": "https://dev.to/priyeshdave6/deconstructing-multi-layer-persistent-memory-in-open-source-ai-agents-insights-from-jarvix-memory-5g62",
  "papers": [],
  "actual_video_files": [],
  "body_chars": 9010,
  "expected_body_images": 0,
  "discovery_status": "ok",
  "delivery_status": "ok",
  "missing_reason": "",
  "raw_html": "attachments/fd4b3e49e518/pages/source.html",
  "local_html": "attachments/fd4b3e49e518/pages/article.html",
  "body_base_path": "attachments/fd4b3e49e518/pages/",
  "body_markdown_path": "attachments/fd4b3e49e518/pages/article.md"
}