🤖 AI/ML

LangChain

LangChain

A framework for developing LLM applications. Combines chains, agents, and tools.

📖 Detailed Explanation

LangChain is an open-source framework for building LLM-based applications. Started by Harrison Chase in 2022, it is currently at v1.2.7 (as of January 2026) and can be used in Python 3.10+ environments. It combines chains, agents, tools, and memory to build complex AI applications.

Core concepts: Chain (connecting LLM calls), Agent (selecting tools to perform tasks), Tool (integrating external APIs/DBs), Memory (retaining conversation history), Retriever (document retrieval for RAG). Since 2025, LangGraph is recommended for agent development.

Latest features (2025-2026): MCP (Model Context Protocol) tool integration, multimodal tool support, LangSmith integration (debugging/monitoring), LangGraph-based agent orchestration. It supports all major providers, including Anthropic, OpenAI, Google, and Ollama.

Practical use: It is used as a standard for building RAG pipelines, chatbots, document QA, and agent workflows. However, since it adds significant overhead for simple API calls, adopt it when complex chains/agents are needed.

💻 Code Example

# pip install langchain langchain-openai langchain-community
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_community.tools import DuckDuckGoSearchRun

# 1. 기본 Chain (LCEL - LangChain Expression Language)
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ("system", "당신은 {role} 전문가입니다."),
    ("human", "{question}")
])
chain = prompt | llm | StrOutputParser()
result = chain.invoke({"role": "Python", "question": "데코레이터 설명해줘"})

# 2. RAG Chain (문서 기반 QA)
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings
from langchain.chains import create_retrieval_chain
from langchain.chains.combine_documents import create_stuff_documents_chain

embeddings = OpenAIEmbeddings()
vectorstore = FAISS.load_local("my_index", embeddings)
retriever = vectorstore.as_retriever(search_kwargs={"k": 3})

rag_prompt = ChatPromptTemplate.from_template(
    "컨텍스트를 참고해 답변하세요:\n{context}\n\n질문: {input}"
)
document_chain = create_stuff_documents_chain(llm, rag_prompt)
rag_chain = create_retrieval_chain(retriever, document_chain)
answer = rag_chain.invoke({"input": "우리 회사 휴가 정책은?"})

# 3. Agent with Tools
search_tool = DuckDuckGoSearchRun()
tools = [search_tool]

agent_prompt = ChatPromptTemplate.from_messages([
    ("system", "도구를 사용해 최신 정보를 검색하세요."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}")
])
agent = create_tool_calling_agent(llm, tools, agent_prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = executor.invoke({"input": "오늘 비트코인 가격은?"})

📊 Performance & Cost

This is pricing information for the LangChain ecosystem as of January 2025.

Services Pricing Features
LangChain Open Source Free (MIT License) Building chains, agents, and RAG
LangGraph Open Source Free Complex agent workflows
LangSmith Free Free 5,000 traces/month
LangSmith Developer $39/month Unlimited traces, 1 user
LangSmith Plus $1,200/month For teams, 10 seats included
LangSmith Enterprise Contact required SSO, SLA, dedicated support

Note: LangSmith is a tool for debugging, evaluation, and monitoring. It is essential for production quality management, but the free tier is sufficient during the development stage.

🗣️ Say It Like This in Practice

💬 In a Meeting
"I'm building an internal document search chatbot, so I'll build a RAG pipeline with LangChain and monitor quality with LangSmith. I'll index 100,000 documents in a FAISS vector store and set the Retriever to top-k=5 to reduce hallucination."
💬 In an Interview
"I implemented order processing automation with a LangChain Agent. I connected an inventory lookup API and a shipping API as Tools, and had GPT-4 analyze customer requests and call the appropriate Tool. I manage the branching logic as a DAG with LangGraph, so it handles complex workflows too."
💬 In a Technical Discussion
"Using LangChain for a simple LLM call is over-engineering. Calling the OpenAI SDK directly is cleaner. LangChain really shines when chain connections, tool calls, and memory management become complex."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Adopting LangChain for simple tasks

LangChain is excessive for making a single API call. Adopt it when you have two or more chains/agents.

❌
Using legacy syntax

LLMChain and SequentialChain are deprecated. Use LCEL (| operator) and create_* functions.

✅
The right way

Use LangGraph for complex agents. Debug with LangSmith. Use the split-package versions such as langchain-core and langchain-openai.

🔗 Related Terms

📚 Learn More