Skip to content
niadra
Integration · LangChain

Memory for LangChain and LangGraph.js.

In Python, with langchain-core only: context_runnable() places the context in the prompt's messages, NiadraCallbackHandler records the turns and history_tools() hands over the kit as StructuredTools. In JavaScript, @niadra/sdk/langchain brings niadraContext() for LCEL chains, withNiadraContext() for LangGraph.js nodes, the callback handler and niadraTools().

LangChain's conversation memory is this chain's history, in a session of your application. It does not cross vendors, does not cross channels and does not know what a system of record changed. Every agent in the company keeps its own version of the customer.

Niadra comes in as a runnable in the middle of the chain: the prompt's messages go in, and come out with the customer's context as a SystemMessage right after the system messages and the turn_block at the end. The callback records what the customer said and what the model answered, with the usage_metadata.

The minimal example, as the documentation has it
pip install 'niadra[langchain]'   # langchain-core 1.6 or newer, below 2
"""An LCEL chain with the customer's context and the history tools."""

from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI

from niadra import Niadra, phone
from niadra.integrations.langchain import NiadraCallbackHandler, context_runnable, history_tools

niadra = Niadra(channel="chat")
prompt = ChatPromptTemplate.from_messages([("system", "You are Acme's agent."), ("human", "{question}")])

with niadra.conversation("thread-81", subject=phone("+5511912345678")) as conversation:
    model = ChatOpenAI(model="gpt-4.1").bind_tools(history_tools(conversation))
    chain = prompt | context_runnable(conversation) | model
    reply = chain.invoke(
        {"question": "Where is my replacement lid?"},
        config={"callbacks": [NiadraCallbackHandler(conversation)]},
    )
    print(reply.content)
  • Python
  • TypeScript

The same code is in examples/langchain_chain.py, examples/langgraph-js.ts in the SDK repositories, where it runs in CI against the framework's real types and Niadra's emulator. To try it without Niadra's cloud, niadra-mock and NIADRA_BASE_URL=http://127.0.0.1:8765.

How the adapter wires in

The five primitives of every Niadra integration, in this framework's extension points.

Context
In Python, context_runnable() takes the prompt's messages, a list or a PromptValue, and returns them with the pack as a SystemMessage right after the leading system messages and the turn_block as a SystemMessage at the end; with_context() and awith_context() do the same for a list you build. In JavaScript, niadraContext(session) is a runnable for LCEL chains (niadraContext(convo).pipe(model)); withNiadraContext(session, messages) does the same inside a LangGraph.js node, right before the model call, so nothing lands in the graph's state.
Turns
NiadraCallbackHandler records the customer's messages when a chat model starts, keyed by position, and the model's answer with its usage_metadata when it ends. In JavaScript, it records the answers with the usage_metadata LangChain standardizes; answers that only call tools record nothing.
Tools
history_tools(): StructuredTools with the kit's names, descriptions and schemas, bound to the customer. In JavaScript, niadraTools(session).
Verification
conversation.verify() before the call.
Handoff
conversation.handoff() where the chain transfers.

What the agent receives

The context is compiled when the memory changes and served ready, with no AI model on the read. What another channel said during the conversation arrives as a delta, at the end of the prompt.

  • Who the customer is, by what the conversation has proven: the verification level decides what goes in
  • Facts, open items and promises, with the date and the channel they came from
  • What other agents did inside the company, confirmed by the system of record
  • Patterns computed by rule, with the evidence and the expiry
  • The three history tools: search, timeline and open an item, bound to the customer in your code
  • A receipt of every read, chained by SHA-256

What the adapter does not do

  • No BaseChatMessageHistory or BaseStore of its own: Niadra is not the state store of the chain or the graph, and the checkpointer never stores a pack.
  • Nothing here fails the chain: with Niadra slow or down, the messages go to the model as they came.
  • Tested against langchain-core 1.6 and @langchain/core 1.2 with a fake chat model and Niadra on the emulator.

Frequently asked questions

Do I need all of langchain or only the core?

In Python, only langchain-core: the runnable, the callback and the tools use the core's interfaces. The example uses langchain-openai for the model, but any chat model works.

Does LangChain's conversation memory keep working?

It does, and it is yours. The chain's history is what the model saw in this session; Niadra is what the company knows of the person, from every channel and system. The callback records the turns once, by position, so the history replayed on the next call does not go in twice.

And in a chain that calls tools several times?

In JavaScript, answers that only call tools record nothing; the agent's turn is the answer with text. The history tools run through the ToolNode, like any other, bound to the customer your code opened.

Do I have to change my model, my prompt or my vendor?

No. The adapter places the context after your instructions and the delta at the end of the prompt, in the extension points the framework already has. Your model, your prompt and your vendor stay the same, and switching any of them later does not erase the memory.

Where does the data live, and what does it cost?

The data stays in a single region, stated in the contract, encrypted with AES-256-GCM under a key exclusive to your company and protected in a FIPS 140-3 HSM. The price is per conversation or task in which an agent read the memory: US$ 2 to 3 per thousand, by volume, with reads, searches and system events included. Niadra is opening to companies by request, before the public launch.

Tell us what you are building.

A work email and two lines about your agents are enough. The people who write the code reply, with an early-access proposal for your case.

Rather tell us more about your company? Use the full form

Company email only. We use this data only to answer your request; to have it deleted, ask through this form.

The next agent can already show up knowing.

Niadra is opening to companies by request, before the public launch. Tell us what you are building: the people who reply are the people who write the code.