| name | langchain-upgrade-migration |
| description | Upgrade LangChain SDK versions safely with import path migration, Use when this capability is needed. |
| metadata | {"author":"flight505"} |
LangChain Upgrade Migration
Current State
!npm list @langchain/core @langchain/openai 2>/dev/null | head -10
Overview
Safely upgrade LangChain versions: check compatibility, migrate import paths, convert legacy chains to LCEL, update agent APIs, and validate with tests.
Breaking Changes Timeline
0.1.x to 0.2.x (Major Restructuring)
@langchain/core extracted as separate package
- Chat models moved to provider packages (
@langchain/openai, @langchain/anthropic)
- Imports changed from
langchain/* to @langchain/core/*
0.2.x to 0.3.x (LCEL Standardization)
- Legacy
LLMChain, ConversationChain deprecated
initialize_agent deprecated (use createToolCallingAgent)
- Memory API:
ConversationBufferMemory replaced by RunnableWithMessageHistory
- All chains should use LCEL pipe syntax
Step 1: Check Current Versions
npm ls @langchain/core @langchain/openai langchain 2>&1 | head -20
pip show langchain langchain-core langchain-openai | grep -E "Name|Version"
Step 2: Migrate Import Paths (TypeScript)
import { ChatOpenAI } from "langchain/chat_models/openai";
import { PromptTemplate } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { BufferMemory } from "langchain/memory";
import { ChatOpenAI } from "@langchain/openai";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain.chains import LLMChain
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
Step 3: Convert LLMChain to LCEL
import { LLMChain } from "langchain/chains";
const chain = new LLMChain({ llm, prompt });
const result = await chain.call({ input: "hello" });
import { StringOutputParser } from "@langchain/core/output_parsers";
const chain = prompt.pipe(model).pipe(new StringOutputParser());
const result = await chain.invoke({ input: "hello" });
from langchain.chains import LLMChain
chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run(input="hello")
chain = prompt | llm | StrOutputParser()
result = chain.invoke({"input": "hello"})
Step 4: Migrate Agents
import { initializeAgentExecutorWithOptions } from "langchain/agents";
const executor = await initializeAgentExecutorWithOptions(tools, llm, {
agentType: "chat-conversational-react-description",
});
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 });
Step 5: Migrate Memory
import { BufferMemory } from "langchain/memory";
const memory = new BufferMemory();
const chain = new ConversationChain({ llm, memory });
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(
{ : },
{ : { : } }
);
Step 6: Upgrade Packages
npm install @langchain/core@latest @langchain/openai@latest langchain@latest
npm ls @langchain/core
pip install --upgrade langchain langchain-core langchain-openai langchain-community
pip show langchain langchain-core | grep Version
Step 7: Run Tests and Check Deprecations
npx vitest run
npx tsc --noEmit
pytest tests/ -W error::DeprecationWarning -v
Migration Checklist
Error Handling
| 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 |
Resources
Next Steps
After upgrade, use langchain-common-errors to troubleshoot any issues.
Source: flight505/skill-forge — distributed by TomeVault.