Metadata-Version: 2.4
Name: langmem0
Version: 0.1.0
Summary: Add your description here
Requires-Python: >=3.13
Description-Content-Type: text/markdown
Requires-Dist: langchain<2,>=1
Requires-Dist: langchain-openai>=1.1.6
Requires-Dist: mem0ai>=1.0.1
Requires-Dist: pydantic>=2.12.5

# LangMem0

![Python Version](https://img.shields.io/badge/python-3.13+-blue.svg)
![Version](https://img.shields.io/badge/version-0.1.0-green.svg)
[![Lint with Ruff](https://github.com/sammyne/langmem0/actions/workflows/lint.yml/badge.svg)](https://github.com/sammyne/langmem0/actions/workflows/lint.yml)

## Environment

- uv >= 0.9

## Quickstart

### 1. Clone the repository

```bash
git clone https://github.com/sammyne/langmem0.git
cd langmem0
```

### 2. Install dependencies

```bash
uv pip install -e .
```

### 3. Set up environment variables

Create a `.env` file in the project root with your OpenAI configuration:

```bash
OPENAI_API_KEY=your_api_key_here
OPENAI_API_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4o-mini
```

### 4. Run examples

LangMem0 provides two main ways to integrate memory into your LangChain applications:

#### Middleware Examples

Use `Mem0Middleware` to enable memory in LangChain agent conversations. This approach provides fine-grained control over memory operations.

```bash
# Synchronous example
uv run examples/middleware/helloworld.py
```

```bash
# Asynchronous example
uv run examples/middleware/helloworld_async.py
```

These examples demonstrate:
- Using `Mem0Middleware` to intercept and augment agent messages with memories
- How agents can remember and retrieve information across conversations
- Different thread contexts for separate conversation memories
- Integration with LangGraph checkpoints

#### Chat Examples

Use `ChatOpenAI` with built-in Mem0 memory capabilities for a simpler integration path.

```bash
# Basic synchronous example
uv run examples/chat/helloworld.py

# Basic asynchronous example
uv run examples/chat/helloworld_async.py

# Advanced synchronous with RunnableConfig:**
uv run examples/chat/runnable_config.py

# Advanced asynchronous with RunnableConfig:**
uv run examples/chat/runnable_config_async.py
```

These examples demonstrate:
- Direct integration with OpenAI-compatible chat models
- Memory-enabled conversations with minimal setup
- Using `RunnableConfig` for thread management
- Both sync and async API patterns

## FAQ
### Why not provide tool-based API like langmem
Tool-based API has a problem: system prompt needs augumenting with memories using a separate middleware as demonstrated
by [LangMem's Hot Path Quickstart](https://langchain-ai.github.io/langmem/hot_path_quickstart/#agent).

## References
- [LangChain Chatbot](https://chat.langchain.com/?threadId=e7011d54-12ce-4c14-8d2a-324996e0d0de)
- [LangChain forum](https://forum.langchain.com/c/oss-product-help-lc-and-lg/langchain/14)
- [Mem0 Open Source](https://docs.mem0.ai/open-source/overview)
