Upgrade LangChain SDK versions safely with import path migration, LCEL conversion from legacy chains, and agent API updates. Trigger: "upgrade langchain", "langchain migration", "langchain breaking changes", "update langchain version", "langchain 0.3", "langchain deprecation".
89
88%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
!npm list @langchain/core @langchain/openai 2>/dev/null | head -10
Safely upgrade LangChain versions: check compatibility, migrate import paths, convert legacy chains to LCEL, update agent APIs, and validate with tests.
@langchain/core extracted as separate package@langchain/openai, @langchain/anthropic)langchain/* to @langchain/core/*LLMChain, ConversationChain deprecatedinitialize_agent deprecated (use createToolCallingAgent)ConversationBufferMemory replaced by RunnableWithMessageHistory# Node.js
npm ls @langchain/core @langchain/openai langchain 2>&1 | head -20
# Python
pip show langchain langchain-core langchain-openai | grep -E "Name|Version"// OLD (pre-0.2)
import { ChatOpenAI } from "langchain/chat_models/openai";
import { PromptTemplate } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { BufferMemory } from "langchain/memory";
// NEW (0.3+)
import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
// LLMChain replaced by LCEL: prompt.pipe(model).pipe(parser)# OLD (pre-0.2)
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain.chains import LLMChain
# NEW (0.3+)
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser// OLD: LLMChain (deprecated)
import { LLMChain } from "langchain/chains";
const chain = new LLMChain({ llm, prompt });
const result = await chain.call({ input: "hello" });
// NEW: LCEL pipe syntax
import { StringOutputParser } from "@langchain/core/output_parsers";
const chain = prompt.pipe(model).pipe(new StringOutputParser());
const result = await chain.invoke({ input: "hello" });# OLD
from langchain.chains import LLMChain
chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run(input="hello")
# NEW
chain = prompt | llm | StrOutputParser()
result = chain.invoke({"input": "hello"})// OLD: initialize_agent (deprecated)
import { initializeAgentExecutorWithOptions } from "langchain/agents";
const executor = await initializeAgentExecutorWithOptions(tools, llm, {
agentType: "chat-conversational-react-description",
});
// NEW: createToolCallingAgent
import { createToolCallingAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant."],
new MessagesPlaceholder("chat_history"),
["human", "{input}"],
new MessagesPlaceholder("agent_scratchpad"),
]);
const agent = createToolCallingAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });// OLD: BufferMemory (deprecated)
import { BufferMemory } from "langchain/memory";
const memory = new BufferMemory();
const chain = new ConversationChain({ llm, memory });
// NEW: RunnableWithMessageHistory
import { RunnableWithMessageHistory } from "@langchain/core/runnables";
import { ChatMessageHistory } from "@langchain/community/stores/message/in_memory";
const store = new Map<string, ChatMessageHistory>();
function getHistory(sessionId: string) {
if (!store.has(sessionId)) store.set(sessionId, new ChatMessageHistory());
return store.get(sessionId)!;
}
const chainWithHistory = new RunnableWithMessageHistory({
runnable: chain,
getMessageHistory: getHistory,
inputMessagesKey: "input",
historyMessagesKey: "history",
});
await chainWithHistory.invoke(
{ input: "Hello" },
{ configurable: { sessionId: "user-1" } }
);# Node.js — update all @langchain/* together
npm install @langchain/core@latest @langchain/openai@latest langchain@latest
# Verify no version conflicts
npm ls @langchain/core
# Python
pip install --upgrade langchain langchain-core langchain-openai langchain-community
pip show langchain langchain-core | grep Version# TypeScript
npx vitest run
npx tsc --noEmit
# Python — check for deprecation warnings
pytest tests/ -W error::DeprecationWarning -vlangchain/* imports updated to @langchain/core/* or provider packagesLLMChain replaced with LCEL .pipe() chainsinitializeAgent replaced with createToolCallingAgentBufferMemory replaced with RunnableWithMessageHistory@langchain/* packages on compatible versions| Error | Cause | Fix |
|---|---|---|
Cannot find module | Old import path | Update to @langchain/core/* or provider package |
LLMChain is not a constructor | Removed in 0.3+ | Convert to LCEL |
DeprecationWarning | Using old API | Follow migration guide for replacement |
| Version conflict | Mixed @langchain/* versions | Update all packages together |
After upgrade, use langchain-common-errors to troubleshoot any issues.
c8a915c
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.