::: title

LM04 LangChain introduction

Development framework designed to stitch all these pieces of AI ::: César Freire

::: image
ai-future.jpeg
:::


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).

https://python.langchain.dev


LangChain Modules

PackageRole
langchain-coreBase abstractions: messages, prompts, runnables
langchainChains, agents, generic higher-level logic
langgraphGraph-based agent runtime (loops, state, control)
langsmithTracing, evaluation and monitoring platform
langserveThe 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