# 🧠 GPT Memory
> Memory-Driven Reasoning for Smarter AI Agents
GPT Memory is a Python library that introduces a new approach to improving LLM reasoning through actionable insights (beliefs) learned over time from memory. Supercharge your AI agents with personalized, context-aware responses.
[](https://badge.fury.io/py/gpt-memory)
[](https://opensource.org/licenses/MIT)
## Why GPT Memory?
Current AI memory systems face significant drawbacks that limit their ability to mimic human-like intelligence. These include their static nature (vector dbs / semantic search), lack of contextual understanding, inability to learn from experience or form beliefs, poor handling of contradictions, limited associative capabilities, and absence of emotional intelligence. Additionally, AI agents struggle with abstraction, lack meta-cognitive abilities, and don't have mechanisms for selectively retaining or forgetting information. These shortcomings collectively restrict AI agents' adaptability, decision-making, and ability to navigate complex, real-world scenarios effectively.
The proposed AI agent memory system is designed to augment human memory and enhance AI agents' capabilities. Its purpose is to create more personalized, adaptive, and context-aware AI interactions by simulating human-like memory processes. This system aims to bridge the gap between static knowledge bases and dynamic, experience-based learning, allowing AI agents to evolve their understanding and behavior over time.
The system is a comprehensive memory and belief management framework for AI agents. It includes components for processing events, storing short-term and long-term memories, managing beliefs, creating associations, and informing decision-making processes. The core concept revolves around converting experiences (events) into memories, which in turn shape beliefs. These beliefs then influence the agent's reasoning, responses, and actions.
## 🌟 Features
- Memory Management
- `update_user_memory()`: Extract and store relevant information from user messages
- `get_user_memory()`: Retrieve stored memory for a specific user
- `get_memory_context()`: Generate formatted memory context for LLM input
- Belief Generation
- `get_beliefs()`: Create actionable insights based on user memory and business context
- Beliefs are AI-generated suggestions that help guide LLM responses, improving personalization and relevance
- Smart Data Handling
- Automatic deduplication of information
- Intelligent updating of existing data (e.g., location changes)
- Conflict resolution between new and existing information
- Simple API
- Easy-to-use methods for integrating memory and belief functionality into your AI applications
- Persistent Storage
- Automatic saving and loading of user memory in JSON format
## 🏗️ Architecture
<img width="663" alt="Screenshot 2024-08-21 at 9 04 07" src="https://github.com/user-attachments/assets/2bdfdaa8-e91c-45b0-b200-2e567daadc5d">
## 🚀 Quick Start
1. Install GPT Memory:
```bash
pip install gpt-memory
```
2. Use it in your project:
```python
from gpt_memory import GPTMemoryManager
business_description = "an AI therapist"
# Initialize with your OpenAI API key
memory_manager = GPTMemoryManager(api_key="your-api-key-here", business_description=business_description, include_beliefs=True)
# Update user memory
memory_manager.update_user_memory("user123", "I just moved from New York to Paris for work.")
# Get user memory
user_memory = memory_manager.get_user_memory("user123")
print(user_memory) # Output: {'location': 'Paris', 'previous_location': 'New York'}
# Get memory context for LLM
context = memory_manager.get_memory_context("user123")
print(context) # Output: 'User Memory:\n location: Paris,\n previous_location: New York'
# Get beliefs
beliefs = memory_manager.get_beliefs("user123")
print(beliefs) # Output: {"beliefs": "- Suggest spending time with Charlie and Luna when user is feeling down\n- Suggest family activities with Lisa and Mai for emotional well-being\n- Recommend playing basketball for physical exercise and stress relief"}
```
## 🧠 Belief Generation: The Secret Sauce
GPT Memory introduces a new approach to LLM reasoning: actionable beliefs generated from user memory. These beliefs provide personalized insights that can significantly enhance your agent's planning, reasoning and responses.
### Examples
#### Input:
- `business_description`: "a commerce site"
- `memory`: {'pets': ['dog named charlie', 'horse named luna']}
#### Output:
```json
{"beliefs": ",- suggest pet products for dogs and horses"}
```
#### Input:
- `business_description`: "an AI therapist"
- `memory`: {'pets': ['dog named charlie', 'horse named luna', 'sleep_time: 10pm']}
#### Output:
```json
{"beliefs": ",- Suggest mediation at 9:30\n- Suggest spending time with Charlie and Luna when user is sad"}
```
## 🛠️ API Reference
### AIMemoryManager
- `get_memory(user_id: str) -> JSON`: Fetch user memory
- `update_memory(user_id: str, message: str) -> JSON`: Update memory with relevant information if found in message
- `get_memory_context(user_id: str) -> str`: Get formatted memory context
- `get_beliefs(user_id: str) -> str`: Get actionable beliefs context
## 🤝 Contributing
We welcome contributions! Found a bug or have a feature idea? Open an issue or submit a pull request. Let's make GPT Memory even better together! 💪
## 📄 License
GPT Memory is MIT licensed. See the [LICENSE](LICENSE) file for details.
---
Ready to empower your AI agents with memory-driven reasoning? Get started with GPT Memory! 🚀 If you find it useful, don't forget to star the repo! ⭐
Raw data
{
"_id": null,
"home_page": "https://github.com/assafelovic/gpt-memory",
"name": "gptmem",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Assaf Elovic",
"author_email": "assaf.elovic@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ba/15/686cf6d641205cc215a46218947f1edc30773446aad6d69e1ddad902dc8d/gptmem-0.0.2.tar.gz",
"platform": null,
"description": "# \ud83e\udde0 GPT Memory\n\n> Memory-Driven Reasoning for Smarter AI Agents\n\nGPT Memory is a Python library that introduces a new approach to improving LLM reasoning through actionable insights (beliefs) learned over time from memory. Supercharge your AI agents with personalized, context-aware responses.\n\n[](https://badge.fury.io/py/gpt-memory)\n[](https://opensource.org/licenses/MIT)\n\n## Why GPT Memory?\nCurrent AI memory systems face significant drawbacks that limit their ability to mimic human-like intelligence. These include their static nature (vector dbs / semantic search), lack of contextual understanding, inability to learn from experience or form beliefs, poor handling of contradictions, limited associative capabilities, and absence of emotional intelligence. Additionally, AI agents struggle with abstraction, lack meta-cognitive abilities, and don't have mechanisms for selectively retaining or forgetting information. These shortcomings collectively restrict AI agents' adaptability, decision-making, and ability to navigate complex, real-world scenarios effectively.\n\nThe proposed AI agent memory system is designed to augment human memory and enhance AI agents' capabilities. Its purpose is to create more personalized, adaptive, and context-aware AI interactions by simulating human-like memory processes. This system aims to bridge the gap between static knowledge bases and dynamic, experience-based learning, allowing AI agents to evolve their understanding and behavior over time.\n\nThe system is a comprehensive memory and belief management framework for AI agents. It includes components for processing events, storing short-term and long-term memories, managing beliefs, creating associations, and informing decision-making processes. The core concept revolves around converting experiences (events) into memories, which in turn shape beliefs. These beliefs then influence the agent's reasoning, responses, and actions.\n\n## \ud83c\udf1f Features\n\n- Memory Management\n - `update_user_memory()`: Extract and store relevant information from user messages\n - `get_user_memory()`: Retrieve stored memory for a specific user\n - `get_memory_context()`: Generate formatted memory context for LLM input\n- Belief Generation\n - `get_beliefs()`: Create actionable insights based on user memory and business context\n - Beliefs are AI-generated suggestions that help guide LLM responses, improving personalization and relevance\n- Smart Data Handling\n - Automatic deduplication of information\n - Intelligent updating of existing data (e.g., location changes)\n - Conflict resolution between new and existing information\n- Simple API\n - Easy-to-use methods for integrating memory and belief functionality into your AI applications\n- Persistent Storage\n - Automatic saving and loading of user memory in JSON format\n\n## \ud83c\udfd7\ufe0f Architecture\n<img width=\"663\" alt=\"Screenshot 2024-08-21 at 9 04 07\" src=\"https://github.com/user-attachments/assets/2bdfdaa8-e91c-45b0-b200-2e567daadc5d\">\n\n\n\n## \ud83d\ude80 Quick Start\n\n1. Install GPT Memory:\n```bash\npip install gpt-memory\n```\n\n2. Use it in your project:\n```python\nfrom gpt_memory import GPTMemoryManager\n\nbusiness_description = \"an AI therapist\"\n# Initialize with your OpenAI API key\nmemory_manager = GPTMemoryManager(api_key=\"your-api-key-here\", business_description=business_description, include_beliefs=True)\n\n# Update user memory\nmemory_manager.update_user_memory(\"user123\", \"I just moved from New York to Paris for work.\")\n\n# Get user memory\nuser_memory = memory_manager.get_user_memory(\"user123\")\nprint(user_memory) # Output: {'location': 'Paris', 'previous_location': 'New York'}\n\n# Get memory context for LLM\ncontext = memory_manager.get_memory_context(\"user123\")\nprint(context) # Output: 'User Memory:\\n location: Paris,\\n previous_location: New York'\n\n# Get beliefs\nbeliefs = memory_manager.get_beliefs(\"user123\")\nprint(beliefs) # Output: {\"beliefs\": \"- Suggest spending time with Charlie and Luna when user is feeling down\\n- Suggest family activities with Lisa and Mai for emotional well-being\\n- Recommend playing basketball for physical exercise and stress relief\"}\n```\n\n## \ud83e\udde0 Belief Generation: The Secret Sauce\n\nGPT Memory introduces a new approach to LLM reasoning: actionable beliefs generated from user memory. These beliefs provide personalized insights that can significantly enhance your agent's planning, reasoning and responses.\n\n### Examples\n#### Input:\n- `business_description`: \"a commerce site\"\n- `memory`: {'pets': ['dog named charlie', 'horse named luna']}\n#### Output:\n\n```json\n{\"beliefs\": \",- suggest pet products for dogs and horses\"}\n```\n\n#### Input:\n\n- `business_description`: \"an AI therapist\"\n- `memory`: {'pets': ['dog named charlie', 'horse named luna', 'sleep_time: 10pm']}\n#### Output:\n\n```json\n{\"beliefs\": \",- Suggest mediation at 9:30\\n- Suggest spending time with Charlie and Luna when user is sad\"}\n```\n\n## \ud83d\udee0\ufe0f API Reference\n\n### AIMemoryManager\n\n- `get_memory(user_id: str) -> JSON`: Fetch user memory\n- `update_memory(user_id: str, message: str) -> JSON`: Update memory with relevant information if found in message\n- `get_memory_context(user_id: str) -> str`: Get formatted memory context\n- `get_beliefs(user_id: str) -> str`: Get actionable beliefs context\n\n## \ud83e\udd1d Contributing\n\nWe welcome contributions! Found a bug or have a feature idea? Open an issue or submit a pull request. Let's make GPT Memory even better together! \ud83d\udcaa\n\n## \ud83d\udcc4 License\n\nGPT Memory is MIT licensed. See the [LICENSE](LICENSE) file for details.\n\n---\n\nReady to empower your AI agents with memory-driven reasoning? Get started with GPT Memory! \ud83d\ude80 If you find it useful, don't forget to star the repo! \u2b50\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Memory management system to enhance AI agents with personalized, context-aware responses",
"version": "0.0.2",
"project_urls": {
"Homepage": "https://github.com/assafelovic/gpt-memory"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "751d0adc78211049c68bff79473e5be017c7c06dc91975e5129dbcca2fa8eae7",
"md5": "1ec0998276f48ffc0ba0103cdd07d7ba",
"sha256": "7047313cd3ea0fc2c8d2ca8eaac3fb968819ef09b72e2652244408f72cd1d40a"
},
"downloads": -1,
"filename": "gptmem-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1ec0998276f48ffc0ba0103cdd07d7ba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 13138,
"upload_time": "2024-08-21T11:15:31",
"upload_time_iso_8601": "2024-08-21T11:15:31.607456Z",
"url": "https://files.pythonhosted.org/packages/75/1d/0adc78211049c68bff79473e5be017c7c06dc91975e5129dbcca2fa8eae7/gptmem-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ba15686cf6d641205cc215a46218947f1edc30773446aad6d69e1ddad902dc8d",
"md5": "d36f6e27b06771b863dc90878e442e17",
"sha256": "8ab3ffaab99142930beee7e8b138f0eca65dadf5c1e9485c4c02032b6ccaca57"
},
"downloads": -1,
"filename": "gptmem-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "d36f6e27b06771b863dc90878e442e17",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 10054,
"upload_time": "2024-08-21T11:15:32",
"upload_time_iso_8601": "2024-08-21T11:15:32.525352Z",
"url": "https://files.pythonhosted.org/packages/ba/15/686cf6d641205cc215a46218947f1edc30773446aad6d69e1ddad902dc8d/gptmem-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-21 11:15:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "assafelovic",
"github_project": "gpt-memory",
"github_not_found": true,
"lcname": "gptmem"
}