One LangChain agent, rewritten in DNotifier
Most migration guides open with a big feature table. I've never found those very helpful on their own, because they don't show you what your code will look like afterwards. So this post does it the other way round: one s
Most migration guides open with a big feature table. I've never found those very helpful on their own, because they don't show you what your code will look like afterwards. So this post does it the other way round: one small agent, written twice.
It's an order-lookup agent with one tool, a system prompt and a single call. The first version is LangChain in JavaScript, the second is DNotifier. In both, db stands in for your own data access.
The LangChain version
import { createAgent, tool } from "langchain";
import * as z from "zod";
const lookupOrder = tool(
async ({ orderId }) => {
const order = await db.orders.find(orderId);
return order ? JSON.stringify({ status: order.status, eta: order.eta }) : "No order with that id.";
},
{
name: "orders_lookup",
description: "Look up an order by id, like A-1042. Returns status and ETA.",
schema: z.object({ orderId: z.string() }),
}
);
const agent = createAgent({
model: "openai:gpt-4o",
tools: [lookupOrder],
systemPrompt: "You help customers with orders. Use tools for facts; never guess dates.",
});
const result = await agent.invoke(
{ messages: [{ role: "user", content: "Where is order A-1042?" }] },
{ recursionLimit: 10 }
);
console.log(result.messages.at(-1).content);
The DNotifier version
import { DNotifier } from "@dnotifier-realtime/dnotifier";
const notifier = new DNotifier({
appId: process.env.DNOTIFIER_APP_ID,
secret: process.env.DNOTIFIER_SECRET,
transport: "http",
userId: "orders-api",
permissionEnforcement: "backend",
});
await notifier.connect();
const lookupOrder = notifier.tools.register({
name: "orders.lookup",
description: "Look up an order by id, like A-1042. Returns status and ETA.",
inputSchema: { type: "object", properties: { orderId: { type: "string" } }, required: ["orderId"] },
async execute({ orderId }) {
const order = await db.orders.find(orderId);
return order ? { status: order.status, eta: order.eta } : { found: false, note: "No order with that id." };
},
});
const agent = DNotifier.defineAgent({
name: "order-help",
instructions: "You help customers with orders. Use tools for facts; never guess dates.",
provider: "open_ai",
model: "gpt-4o",
observability: true,
tools: [lookupOrder],
permissions: { "orders.lookup": ["execute"] },
});
const result = await notifier.runAgent(agent, { input: "Where is order A-1042?", maxToolRounds: 5 });
console.log(result.output);
So what changed?
Less than I expected. The body of the tool function is the same code. The Zod schema turns into a plain JSON schema, and the tool can hand back an object instead of a string. The description copies straight across, which matters, because it's what the model reads when deciding whether to call it.
The model string gets split in two: "openai:gpt-4o" becomes provider plus model. Moving to Claude or Gemini later is a change to those two fields and nothing else.
Permissions are the one part that is actually new. The agent declares which tools it's allowed to execute, and with permissionEnforcement: "backend" the server checks that list on every call. In LangChain, any tool you pass in can be called.
The limit counts something different, so don't just copy the number. recursionLimit counts graph steps, maxToolRounds counts rounds of tool calls. I'd set it to however many tool calls a normal question needs, plus one or two.
Reading the answer is result.output instead of digging the last message out of state. And observability: true replaces the LangSmith environment variables: every run shows up in Traces with its steps, tool calls and cost.
What carries over, and what doesn't
Most of the core concepts have a direct counterpart. createAgent maps to defineAgent, tool() to tools.register(), and a StateGraph becomes a Workflow where the branching is ordinary if and await. Parallel branches become ctx.runAgents(), interrupts become ctx.waitForMessage(), retrievers become the knowledge base. Checkpointers map to DNotifier's checkpoints, where you can resume, retry or replay a run, and LangSmith datasets map to datasets and experiments.
A few things don't have an equivalent today, and you should know them before you start:
- token-by-token streaming (you can push progress messages to the client, but not text as it's generated)
- structured output with a schema validator (ask for JSON and parse it with a fallback)
- LangChain's huge integration catalogue (in DNotifier an integration is a tool you register or an MCP server you connect)
If an agent leans heavily on one of those, I'd migrate it last, or just leave it on LangChain. The full guide, including moving a LangGraph graph across and the order I'd migrate things in, is on our blog: How to migrate from LangChain.
I work on DNotifier, so treat this as a vendor's comparison. I've tried to be upfront about the gaps. Drafted with AI help, edited by me.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.