Skip to main content

A LangChain agent middleware that provides a plain-text scratchpad/notepad.

Project description

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

pip install langchain-notepad-middleware

Usage

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.
  4. notepad_is_exist(): Check if a non-empty note exists.
  5. notepad_clear(): Clear the note.

The state is stored in a simple string field notepad within the agent state.

Best Practices

  • Use append for logging cumulative steps.
  • Use replace when summarizing or changing topics.
  • The middleware automatically injects prompt guidance, so you don't typically need to manually prompt the agent to use it, although specific task instructions help.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_notepad_middleware-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_notepad_middleware-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file langchain_notepad_middleware-0.1.0.tar.gz.

File metadata

File hashes

Hashes for langchain_notepad_middleware-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7c7c170dc922640b58ceef27beef7510327267793df6c62e276e2cd9b0ac6272
MD5 5453e87028dd600cf0a343b0fa803f88
BLAKE2b-256 c6267518c7f914a15bc081ca8754459536a2bea98ccfc277c9acce85ef442461

See more details on using hashes here.

File details

Details for the file langchain_notepad_middleware-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_notepad_middleware-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ef2effcb7646ea587208fe5cac2b8dcd700981ad00a87b1d8b198be99cc3461
MD5 7220712a01d9c0045990049640ace73d
BLAKE2b-256 2f283ba9795c0098b8766fe49c4b1302b184259451af4127c15511e2dc87ae5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page