Metadata-Version: 2.4
Name: neruva-langchain
Version: 0.1.0
Summary: Drop-in LangChain integration for Neruva agent memory. Wraps BaseChatMessageHistory + BaseMemory + BaseRetriever to auto-pipe agent turns into the Neruva substrate (records + KG + federated agent_context). One-line install, works with every LangChain LLM.
Author-email: Clouthier Simulation Labs <info@neruva.io>
License: MIT
Project-URL: Homepage, https://neruva.io/integrations/
Project-URL: Documentation, https://neruva.io/docs/
Project-URL: Source, https://github.com/CloutSimLabs/neruva
Keywords: langchain,neruva,agent-memory,memory,ai,llm,rag
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Requires-Dist: langchain-core>=0.3.0
Dynamic: license-file

# neruva-langchain

Drop-in LangChain integration for [Neruva](https://neruva.io) agent memory.
Three wrappers cover the common LangChain plug points: chat history,
conversation memory, and document retriever.

```bash
pip install neruva-langchain
```

## NeruvaChatMessageHistory

Auto-records every turn into the Neruva Records substrate. Drop into any
LangChain primitive that accepts a `BaseChatMessageHistory`:

```python
from neruva_langchain import NeruvaChatMessageHistory

history = NeruvaChatMessageHistory(
    api_key="nv_...",          # or env NERUVA_API_KEY
    namespace="user_alice",    # one per user / session
)

history.add_user_message("My name is Alice and I live in Toronto.")
history.add_ai_message("Nice to meet you, Alice!")

# Later — even after process restart, substrate-backed:
print(history.messages)
```

## Use with RunnableWithMessageHistory (modern pattern)

```python
from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables.history import RunnableWithMessageHistory
from neruva_langchain import NeruvaChatMessageHistory

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant."),
    MessagesPlaceholder(variable_name="history"),
    ("human", "{input}"),
])
chain = prompt | ChatAnthropic(model="claude-opus-4-7")

chain_with_history = RunnableWithMessageHistory(
    chain,
    lambda session_id: NeruvaChatMessageHistory(namespace=session_id),
    input_messages_key="input",
    history_messages_key="history",
)
chain_with_history.invoke(
    {"input": "What did I tell you about my project last week?"},
    config={"configurable": {"session_id": "user_alice"}},
)
```

## NeruvaContextRetriever

`BaseRetriever` for `RetrievalQA` chains. Returns `Document` objects
sourced from federated `agent_recall`:

```python
from neruva_langchain import NeruvaContextRetriever
from langchain.chains import RetrievalQA
from langchain_anthropic import ChatAnthropic

retriever = NeruvaContextRetriever(
    api_key="nv_...",
    namespaces=["session_a", "session_b"],   # multi-session fan-out
)
qa = RetrievalQA.from_chain_type(
    llm=ChatAnthropic(model="claude-opus-4-7"),
    retriever=retriever,
)
qa.invoke("Where does Alice work?")
```

## Why use Neruva instead of LangChain's built-in memory?

| Feature | LangChain default | Neruva |
|---|---|---|
| Persists across process restart | Manual setup | Built-in (GCS-backed) |
| Cross-session recall | No | Yes via `namespaces=[...]` |
| Fact extraction (KG) | No | Auto (`hd_kg_extraction_prompt` + caller LLM) |
| GDPR forget by user | Manual | `user_id=` auto-folds, one-call forget |
| Determinism / replayability | No | Bit-identical from seed |
| Portability | Pickle | `.neruva` zip container |

[Get an API key](https://app.neruva.io) · [Docs](https://neruva.io/docs/) · [Status](https://status.neruva.io)
