{"id":30620483,"url":"https://langchain-ai.github.io/langmem/","last_synced_at":"2025-08-30T13:37:53.539Z","repository":{"id":278246200,"uuid":"920242883","full_name":"langchain-ai/langmem","owner":"langchain-ai","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-19T22:16:58.000Z","size":2835,"stargazers_count":972,"open_issues_count":26,"forks_count":111,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-08-20T00:22:11.004Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://langchain-ai.github.io/langmem/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/langchain-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-21T20:06:59.000Z","updated_at":"2025-08-19T22:17:01.000Z","dependencies_parsed_at":"2025-02-18T19:40:03.138Z","dependency_job_id":"faf36658-22a1-48af-992b-31e2c19f18ab","html_url":"https://github.com/langchain-ai/langmem","commit_stats":null,"previous_names":["langchain-ai/langmem"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/langchain-ai/langmem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangmem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangmem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangmem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangmem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/langchain-ai","download_url":"https://codeload.github.com/langchain-ai/langmem/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Flangmem/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272858486,"owners_count":25005092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-30T13:37:51.393Z","updated_at":"2025-08-30T13:37:53.534Z","avatar_url":"https://github.com/langchain-ai.png","language":"Python","funding_links":[],"categories":["8. Project Memory \u0026 Knowledge Bases","🛠️ Tools \u0026 Projects","💿 Products","2. The Design of the Harness"],"sub_categories":["Development Frameworks","Open-Source","2.2. Memory Systems"],"readme":"# LangMem\n\nLangMem helps agents learn and adapt from their interactions over time.\n\nIt provides tooling to extract important information from conversations, optimize agent behavior through prompt refinement, and maintain long-term memory.\n\nIt offers both functional primitives you can use with any storage system and native integration with LangGraph's storage layer.\n\nThis lets your agents continuously improve, personalize their responses, and maintain consistent behavior across sessions.\n\n## Key features\n\n- 🧩 **Core memory API** that works with any storage system\n- 🧠 **Memory management tools** that agents can use to record and search information during active conversations \"in the hot path\"\n- ⚙️ **Background memory manager** that automatically extracts, consolidates, and updates agent knowledge\n- ⚡ **Native integration with LangGraph's Long-term Memory Store**, available by default in all LangGraph Platform deployments\n\n## Installation\n\n```bash\npip install -U langmem\n```\n\nConfigure your environment with an API key for your favorite LLM provider:\n\n```bash\nexport ANTHROPIC_API_KEY=\"sk-...\"  # Or another supported LLM provider\n```\n\n## Creating an Agent\n\nHere's how to create an agent that actively manages its own long-term memory in just a few lines:\n\n```python\n# Import core components (1)\nfrom langgraph.prebuilt import create_react_agent\nfrom langgraph.store.memory import InMemoryStore\nfrom langmem import create_manage_memory_tool, create_search_memory_tool\n\n# Set up storage (2)\nstore = InMemoryStore(\n    index={\n        \"dims\": 1536,\n        \"embed\": \"openai:text-embedding-3-small\",\n    }\n) \n\n# Create an agent with memory capabilities (3)\nagent = create_react_agent(\n    \"anthropic:claude-3-5-sonnet-latest\",\n    tools=[\n        # Memory tools use LangGraph's BaseStore for persistence (4)\n        create_manage_memory_tool(namespace=(\"memories\",)),\n        create_search_memory_tool(namespace=(\"memories\",)),\n    ],\n    store=store,\n)\n```\n\n1. The memory tools work in any LangGraph app. Here we use [`create_react_agent`](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.create_react_agent) to run an LLM with tools, but you can add these tools to your existing agents or build [custom memory systems](concepts/conceptual_guide.md#functional-core) without agents.\n\n2. [`InMemoryStore`](https://langchain-ai.github.io/langgraph/reference/store/#langgraph.store.memory.InMemoryStore) keeps memories in process memory—they'll be lost on restart. For production, use the [AsyncPostgresStore](https://langchain-ai.github.io/langgraph/reference/store/#langgraph.store.postgres.AsyncPostgresStore) or a similar DB-backed store to persist memories across server restarts.\n\n3. The memory tools ([`create_manage_memory_tool`](reference/tools.md#langmem.create_manage_memory_tool) and [`create_search_memory_tool`](reference/tools.md#langmem.create_search_memory_tool)) let you control what gets stored. The agent extracts key information from conversations, maintains memory consistency, and knows when to search past interactions. See [Memory Tools](guides/memory_tools.md) for configuration options.\n\nThen use the agent:\n\n```python\n# Store a new memory (1)\nagent.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"Remember that I prefer dark mode.\"}]}\n)\n\n# Retrieve the stored memory (2)\nresponse = agent.invoke(\n    {\"messages\": [{\"role\": \"user\", \"content\": \"What are my lighting preferences?\"}]}\n)\nprint(response[\"messages\"][-1].content)\n# Output: \"You've told me that you prefer dark mode.\"\n```\n\n1. The agent gets to decide what and when to store the memory. No special commands needed—just chat normally and the agent uses [`create_manage_memory_tool`](reference/tools.md#langmem.create_manage_memory_tool) to store relevant details.\n\n2. The agent maintains context between chats. When you ask about previous interactions, the LLM can invoke [`create_search_memory_tool`](reference/tools.md#langmem.create_search_memory_tool) to search for memories with similar content. See [Memory Tools](guides/memory_tools.md) to customize memory storage and retrieval, and see the [hot path quickstart](https://langchain-ai.github.io/langmem/hot_path_quickstart) for a more complete example on how to include memories without the agent having to explicitly search.\n\nThe agent can now store important information from conversations, search its memory when relevant, and persist knowledge across conversations.\n\n## Next Steps\n\nFor more examples and detailed documentation:\n\n- [Hot Path Quickstart](https://langchain-ai.github.io/langmem/hot_path_quickstart) - Learn how to let your LangGraph agent manage its own memory \"in the hot path\"\n- [Background Quickstart](https://langchain-ai.github.io/langmem/background_quickstart) - Learn how to use a memory manager \"in the background\"\n- [Core Concepts](https://langchain-ai.github.io/langmem/concepts/conceptual_guide) - Learn key ideas\n- [API Reference](https://langchain-ai.github.io/langmem/reference) - Full function documentation\n- Build RSI 🙂 ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/langchain-ai.github.io%2Flangmem%2F","html_url":"https://awesome.ecosyste.ms/projects/langchain-ai.github.io%2Flangmem%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/langchain-ai.github.io%2Flangmem%2F/lists"}