neruva-langchain
Drop-in LangChain integration for Neruva agent memory + reasoning substrate. Three wrappers cover the common LangChain plug points: chat history, document retriever, and (new in 0.2.0) auto-pilot intent routing + reflection.
pip install neruva-langchain
What's new in 0.2.0 — Auto-pilot
Two new exports complete the auto-pilot integration. The agent now proactively uses the right Neruva cognitive tool (counterfactual / analogy / theory-of-mind / rule induction / EFE planning / causal / etc.) based on the user's intent — without you wiring each one.
NeruvaAutoPilot— framework-agnostic core. Pass your LangChain LLM; get backclassify_intent(),reflect(), andextract_facts()methods that round-trip through the substrate's canonical prompts (Layer 2 / 3 / 1 respectively).NeruvaAutoPilotCallback—BaseCallbackHandlersubclass that auto-fires intent classification onon_chain_startand (opt-in) reflection onon_chain_endafter every 10 turns. Drop into any chain viacallbacks=[NeruvaAutoPilotCallback(...)].
Plus NeruvaCodeGraph (5 sub-ms code-navigation methods —
callers / callees / class_of / module_of / imports) and
NeruvaCognitive (13 cognitive-primitive methods —
counterfactual rollout / theory-of-mind / schema lifting / EFE
planning / continual K-gram / hierarchical chunking / rule
induction). Thin wrappers over NeruvaClient so they're callable
from anywhere in your chain.
Pattern-C: substrate stays $0/call. The classification + extraction work runs in YOUR LangChain LLM's turn.
from langchain_anthropic import ChatAnthropic
from neruva_langchain import NeruvaAutoPilot, NeruvaAutoPilotCallback
llm = ChatAnthropic(model="claude-3-7-sonnet-20250219")
ap = NeruvaAutoPilot(api_key="nv_...", namespace="my_app", llm=llm)
# Layer 2 — classify a user message
result = ap.classify_intent("what if we had picked Mailgun?")
# {'primary_intent': 'counterfactual', 'confidence': 0.92,
# 'suggested_tool': 'agent_counterfactual_rollout', ...}
# Layer 3 — reflect over recent turns + auto-write durable records
ap.reflect(recent_turns=[
{"role": "user", "text": "ship the ticket system"},
{"role": "assistant", "text": "shipped 5 phases including notes + audit"},
])
# Auto-writes decisions/facts/mistakes to substrate.
# Or auto-fire via callback in any LCEL chain / agent:
chain = prompt | llm | parser
result = chain.invoke({"q": "..."}, config={"callbacks": [
NeruvaAutoPilotCallback(api_key="nv_...", namespace="my_app", llm=llm,
enable_route=True, enable_reflect=True),
]})
What's new in the substrate (v0.5.7, May 2026)
The substrate this adapter wraps has gained a lot since the last release.
All of it is available via the same agent_* API the wrappers already
call, so existing code keeps working — new capabilities just become
available.
- Deterministic replay — every query is bit-identical across reruns from the same seed. Replay any past state for audit or debugging.
- Typed-shape context — pull structured JSON from records with
per-field citations.
{question, shape: {field: type}}→ typed result without an LLM at query time. Natural fit for tool-calling chains that need a specific output schema. - Tenant-specific PII rules — register your custom ID formats (employee codes, patient codes, order IDs) from 3-5 examples. The substrate redacts them automatically. Sub-microsecond per span.
- Depth-unlimited nested-belief tracking — store and retrieve
chains like
Alice → Bob → Carol thinks Xat any depth, with inner-position-swap rejection. - Counterfactual rollouts — "what if action k had been a' instead?" Replay an action sequence with one step substituted.
- Active inference planning — score candidate action sequences by KL distance to a goal-marginal. Caller-owned dynamics.
- Continual K-gram learning — provable no-forgetting via
integer-add commutativity; repeated
train()calls accumulate.
NeruvaChatMessageHistory
Auto-records every turn into the Neruva Records substrate. Drop into any
LangChain primitive that accepts a BaseChatMessageHistory:
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)
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:
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 · Docs · Status
Metadata
Release files for neruva-langchain 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neruva_langchain-0.2.1.tar.gz | 17.4 kB | Without provenance | Details for neruva_langchain-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neruva_langchain-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for neruva_langchain-0.2.1-py3-none-any.whl |
Total release size: 33.9 kB
Release files / neruva_langchain-0.2.1.tar.gz
| Download URL | neruva_langchain-0.2.1.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
200bd524f9aa6bbf8ed375fa5b07decfc2320df81620ca59a8ba419152973e38
|
|
BLAKE2b-256 checksum How to use checksums |
4242f1b5795036268b7e8e61fbcc87515024186d88846db438088e2acd6d62d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / neruva_langchain-0.2.1-py3-none-any.whl
| Download URL | neruva_langchain-0.2.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
455006c50936d862b8ab86424382b4906c5bf4365a9e2eb4e4b4285a9f9236d3
|
|
BLAKE2b-256 checksum How to use checksums |
d067d6f5add74a3c9c2204f0e149b061c1eb54cbe4312e9f1cc134d802498176
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for neruva-langchain 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.