Name | langmem JSON |
Version |
0.0.28
JSON |
| download |
home_page | None |
Summary | Prebuilt utilities for memory management and retrieval. |
upload_time | 2025-07-09 01:59:48 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT License Copyright (c) 2025 LangChain Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# LangMem
LangMem helps agents learn and adapt from their interactions over time.
It provides tooling to extract important information from conversations, optimize agent behavior through prompt refinement, and maintain long-term memory.
It offers both functional primitives you can use with any storage system and native integration with LangGraph's storage layer.
This lets your agents continuously improve, personalize their responses, and maintain consistent behavior across sessions.
## Key features
- đź§© **Core memory API** that works with any storage system
- đź§ **Memory management tools** that agents can use to record and search information during active conversations "in the hot path"
- ⚙️ **Background memory manager** that automatically extracts, consolidates, and updates agent knowledge
- ⚡ **Native integration with LangGraph's Long-term Memory Store**, available by default in all LangGraph Platform deployments
## Installation
```bash
pip install -U langmem
```
Configure your environment with an API key for your favorite LLM provider:
```bash
export ANTHROPIC_API_KEY="sk-..." # Or another supported LLM provider
```
## Creating an Agent
Here's how to create an agent that actively manages its own long-term memory in just a few lines:
```python
# Import core components (1)
from langgraph.prebuilt import create_react_agent
from langgraph.store.memory import InMemoryStore
from langmem import create_manage_memory_tool, create_search_memory_tool
# Set up storage (2)
store = InMemoryStore(
index={
"dims": 1536,
"embed": "openai:text-embedding-3-small",
}
)
# Create an agent with memory capabilities (3)
agent = create_react_agent(
"anthropic:claude-3-5-sonnet-latest",
tools=[
# Memory tools use LangGraph's BaseStore for persistence (4)
create_manage_memory_tool(namespace=("memories",)),
create_search_memory_tool(namespace=("memories",)),
],
store=store,
)
```
1. 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.
2. [`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.
3. 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.
Then use the agent:
```python
# Store a new memory (1)
agent.invoke(
{"messages": [{"role": "user", "content": "Remember that I prefer dark mode."}]}
)
# Retrieve the stored memory (2)
response = agent.invoke(
{"messages": [{"role": "user", "content": "What are my lighting preferences?"}]}
)
print(response["messages"][-1].content)
# Output: "You've told me that you prefer dark mode."
```
1. 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.
2. 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 expliictly search.
The agent can now store important information from conversations, search its memory when relevant, and persist knowledge across conversations.
## Next Steps
For more examples and detailed documentation:
- [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"
- [Background Quickstart](https://langchain-ai.github.io/langmem/background_quickstart) - Learn how to use a memory manager "in the background"
- [Core Concepts](https://langchain-ai.github.io/langmem/concepts/conceptual_guide) - Learn key ideas
- [API Reference](https://langchain-ai.github.io/langmem/reference) - Full function documentation
- Build RSI 🙂
Raw data
{
"_id": null,
"home_page": null,
"name": "langmem",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/d3/18/b6ad694b99150113dd7e3df30dfbb5ed2abf07a1a72d2b8abde87d079bb4/langmem-0.0.28.tar.gz",
"platform": null,
"description": "# 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- \ud83e\udde9 **Core memory API** that works with any storage system\n- \ud83e\udde0 **Memory management tools** that agents can use to record and search information during active conversations \"in the hot path\"\n- \u2699\ufe0f **Background memory manager** that automatically extracts, consolidates, and updates agent knowledge\n- \u26a1 **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\u2014they'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\u2014just 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 expliictly 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 \ud83d\ude42 ",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2025 LangChain Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Prebuilt utilities for memory management and retrieval.",
"version": "0.0.28",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "408973d77b1f38c1df4a86b16ff77bb5951279b8463f81d32e31651bd6820762",
"md5": "7a781eb7e445487060bf17d05b31af95",
"sha256": "9b2a145f8ff61bdf3158e8ce46f4b76d6a946f9cd21f6dc51b0db95cae718033"
},
"downloads": -1,
"filename": "langmem-0.0.28-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7a781eb7e445487060bf17d05b31af95",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 66996,
"upload_time": "2025-07-09T01:59:46",
"upload_time_iso_8601": "2025-07-09T01:59:46.988344Z",
"url": "https://files.pythonhosted.org/packages/40/89/73d77b1f38c1df4a86b16ff77bb5951279b8463f81d32e31651bd6820762/langmem-0.0.28-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d318b6ad694b99150113dd7e3df30dfbb5ed2abf07a1a72d2b8abde87d079bb4",
"md5": "d5a6f2f4f733752d8d93695b7852f979",
"sha256": "625f76b457e6f052545a5949a7281c0ebb98d0eb78c68a29a6dce7e3e402f1a3"
},
"downloads": -1,
"filename": "langmem-0.0.28.tar.gz",
"has_sig": false,
"md5_digest": "d5a6f2f4f733752d8d93695b7852f979",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 231884,
"upload_time": "2025-07-09T01:59:48",
"upload_time_iso_8601": "2025-07-09T01:59:48.173588Z",
"url": "https://files.pythonhosted.org/packages/d3/18/b6ad694b99150113dd7e3df30dfbb5ed2abf07a1a72d2b8abde87d079bb4/langmem-0.0.28.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-09 01:59:48",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "langmem"
}