::: title
LM04 LangChain introduction
Development framework designed to stitch all these pieces of AI ::: César Freire::: image

:::
What is LangChain
- Open-source framework (by LangChain) for building applications powered by LLMs — the de facto standard toolkit for agentic AI in Python
- Orchestration layer — connects LLMs to prompts, tools, memory, documents and APIs
- Model-agnostic — swap OpenAI, Anthropic, Ollama, Hugging Face… with one-line changes
LLM alone = brain. LangChain gives it the hands (tools), the notebook (memory) and the workflow (graph).
LangChain Modules
| Package | Role |
|---|---|
langchain-core | Base abstractions: messages, prompts, runnables |
langchain | Chains, agents, generic higher-level logic |
langgraph | Graph-based agent runtime (loops, state, control) |
langsmith | Tracing, evaluation and monitoring platform |
langserve | The Deployment Engine |
Components of LangChain
LangChain Expression Language (LCEL)
- Declarative way to compose components with the pipe operator
| - Any LCEL chain is a Runnable — free streaming, batch, async, retries, fallbacks
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI
prompt = ChatPromptTemplate.from_template("Explain {topic} simply")
model = ChatOpenAI(model="gpt-4o-mini")
parser = StrOutputParser()
chain = prompt | model | parser # LCEL pipeline
chain.invoke({"topic": "agents"})- Compose branches, parallel steps and cycles (with LangGraph) from the same primitives