LangChain Classic: Reading Old Code
Most YouTube videos and blogs were written for LangChain 0.x: LLMChain, ConversationChain, RetrievalQA, initialize_agent. In v1 these moved to the package langchain-classic. They still run (with deprecation warnings), so you can read and convert old code. For new projects, use the v1 way you learned in Labs 01–15.
In this session
- Why langchain-classic exists
- LLMChain → prompt | llm | parser
- SimpleSequentialChain and SequentialChain
- ConversationChain with buffer, window and summary memory
- RetrievalQA and create_retrieval_chain
- Old → new conversion table
01The big idea: old notes, new syllabus
Think of your senior’s old notes. The concepts are still right, but the syllabus changed: chapter names moved and some methods are no longer taught. You can still learn from them if you know the mapping. This lab is that mapping, from LangChain 0.x to v1.
The real warning printed by the hands-on run below. Classic classes are scheduled for removal in 2.0.
02Old → new cheat sheet
| Old (classic) | New (v1) |
|---|---|
LLMChain(llm, prompt) | prompt | llm | StrOutputParser() |
SimpleSequentialChain / SequentialChain | {"x": chain1} | chain2, RunnablePassthrough.assign |
ConversationChain + ConversationBufferMemory | RunnableWithMessageHistory or agent + checkpointer |
ConversationBufferWindowMemory | trim_messages |
ConversationSummaryMemory | SummarizationMiddleware |
RetrievalQA | LCEL RAG chain (Lab 11) |
initialize_agent, AgentExecutor | create_agent |
.run(), .predict() | .invoke() |
from langchain.chains import … | from langchain_classic.chains import … |
03Hands-on: run it here
Old and new side by side: LLMChain returns a dict with text, LCEL returns the string directly. Window memory with k=1 forgets the name, just like the notebook says.
import warnings; warnings.filterwarnings("ignore")
from standins import RuleModel, KeywordEmbeddings
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_classic.chains import LLMChain, SimpleSequentialChain, ConversationChain, RetrievalQA
from langchain_classic.memory import ConversationBufferMemory, ConversationBufferWindowMemory
from langchain_community.vectorstores import FAISS
llm = RuleModel(rules={"organic tea": "Chai Bloom", "company name for electric": "VoltRide",
"slogan": "VoltRide: Silent rides, bright future.", "upi limit": "Rs 25,000 in the first 24 hours."}, default="OK")
prompt = PromptTemplate.from_template("Suggest one name for a {business} company")
print("LLMChain (old):", LLMChain(llm=llm, prompt=prompt).invoke({"business": "organic tea"}))
print("LCEL (new):", (prompt | llm | StrOutputParser()).invoke({"business": "organic tea"}))
name_chain = LLMChain(llm=llm, prompt=PromptTemplate.from_template("Give one company name for electric {product}. Only the name."))
slogan_chain = LLMChain(llm=llm, prompt=PromptTemplate.from_template("Write a slogan for the company {name}."))
print("SimpleSequentialChain:", SimpleSequentialChain(chains=[name_chain, slogan_chain]).invoke("scooters"))
class Rememberer(RuleModel):
def _pick(self, messages):
t = messages[-1].content
hist = t.split("Current conversation:")[-1].rsplit("Human:", 1)[0]
q = t.rsplit("Human:", 1)[-1].lower()
if "name" in q: return "Your name is Ajeet." if "Ajeet" in hist else "I'm sorry, I don't know your name."
return "Nice to meet you!"
for mem in [ConversationBufferMemory(), ConversationBufferWindowMemory(k=1)]:
conv = ConversationChain(llm=Rememberer(), memory=mem)
conv.invoke({"input": "My name is Ajeet."}); conv.invoke({"input": "I like cricket."})
print(f"{type(mem).__name__:32s} -> {conv.invoke({'input': 'What is my name?'})['response']}")
retriever = FAISS.from_texts(["Report a lost card within 3 days for zero liability.", "UPI limit for a new payee is Rs 25,000 in the first 24 hours.",
"Video KYC is available from 9 AM to 9 PM."], KeywordEmbeddings()).as_retriever(search_kwargs={"k": 1})
out = RetrievalQA.from_chain_type(llm=llm, retriever=retriever, chain_type="stuff", return_source_documents=True).invoke({"query": "What is the UPI limit for a new payee?"})
print("RetrievalQA:", out["result"], "| source:", out["source_documents"][0].page_content)RuleModel or ScriptedModel from standins.py), so every output below is from a real run of this code. In Colab you swap one line: llm = ChatGroq(model="openai/gpt-oss-20b").04Hands-on: Ajeetkumar’s Colab notebook
groq_key with your free key from console.groq.com, switch on Notebook access, then run the cells from the top.05Summary
- Old 0.x classes live in
langchain-classicand print deprecation warnings. LLMChain→prompt | llm | parser;.run()→.invoke().- Memory classes → message history,
trim_messages, checkpointers,SummarizationMiddleware. RetrievalQA→ LCEL RAG chain; agents →create_agent.- Read old code, write new code.
06Quick quiz
1. Where do LLMChain and RetrievalQA live in v1?
2. v1 replacement for LLMChain(llm, prompt)?
3. ConversationBufferWindowMemory(k=1) keeps…
4. v1 replacement for initialize_agent?
5. .run() and .predict() became…
07References
- LangChain v1 migration guide
- langchain-classic on PyPI
- Ajeetkumar’s notebook: LC_16_LangChain_Classic_Legacy_Chains.ipynb (download)