semvec/pypi-packages huggingface dataset:
langchain-notepad-middleware 0.1.1
A LangChain agent middleware that provides a plain-text scratchpad/notepad.
License: MIT
Requires Python: >=3.10
Keywords: langchain, middleware, notepad, scratchpad, agent

# LangChain Notepad Middleware

A production-grade LangChain middleware that provides a plain-text persistent "scratchpad" (notepad) for agents to store intermediate state across multi-hop tasks.

## Installation

```bash
pip install langchain-notepad-middleware
```

## Usage

```python
from langchain.agents import create_agent
from langchain_middleware_notepad import NotePadMiddleware

# Create an agent with the middleware
agent = create_agent(
    model="openai:gpt-4o",
    tools=[...],  # Your other tools
    middleware=[NotePadMiddleware()],
)
```

## How it Works

The middleware injects a system prompt instructing the model to use the notepad for scratchpad memory. It also registers 5 tools for manipulating the notepad state:

1.  **`notepad_append(text)`**: Append text to the note.
2.  **`notepad_replace(text)`**: Overwrite the entire note.
3.  **`notepad_read()`**: Read the current note content.

The state is stored in a simple string field `notepad` within the agent state.