Generative AI and Agentic AILangChain 1.4 · LangGraph 1.2 · Python 3.12 or 3.13
Dashboard
0%

LangChain essentials

LangChain is an open-source Python framework that gives every model provider the same interface, so you write messages, prompts, tools and agents once and change only a model string to move from Groq to Gemini or any other provider.

Last updated: 08 Oct, 2026 · LangChain 1.4 · LangGraph 1.2

The first part placed generative AI, agents and agentic AI side by side. LangChain is the toolkit the rest of the course builds them with. This lesson lists what it contains, so that every later lesson can use one piece without a detour.

Your code calls langchain, which hands the call to a provider package such as langchain-groq or langchain-google-genai, which calls the model API at Groq or Gemini. langchain is built on langgraph, which runs agents and keeps state, and the provider package is built on langchain-core, which defines message types, prompt templates and the Runnable interface.

What LangChain covers in version 1

What the LangChain version 1 docs cover · from the Complete Agentic AI Course video · 3:44 to 5:08

The video opens its LangChain chapter at the documentation. The docs hold three modules, LangChain, LangGraph and Deep Agents, and the LangChain part changed a lot in version 1: how to create agents, how to connect several different models, how to call a tool, how to get structured output, the message types (AI message, human message, tool message), short-term memory, streaming, middleware and guardrails. The second part of this course takes those topics one at a time, with the same calls the video uses.

LangChain, LangGraph and Deep Agents

The LangChain docs describe how the three libraries relate:

LibraryWhat it is forWhere this course uses it
LangChaincreate_agent, a minimal and customisable agent harness built from a model, tools, a prompt and middlewareEvery model call, and the agents in AI agents
LangGraphLow-level orchestration: steps that share state, with memory, pauses and branches. LangChain agents run on itLangGraph essentials
Deep AgentsA batteries-included agent with planning, a virtual file system and subagents, built on LangChain agentsDeep agents
LangSmithTracing, debugging and evaluating agents built with any of the threeNot needed to follow the lessons

The packages behind the imports

LangChain is split into packages so that you install only the integrations you use. The install docs call them independent provider packages: one for Groq, one for Google, and so on. What the langchain package itself needs can be read from the installed metadata.

ExampleRun on langchain 1.4.3
from importlib.metadata import requires

for requirement in requires("langchain"):
    if "extra ==" not in requirement:    # skip the optional provider extras
        print(requirement)

langchain declares three requirements: langchain-core, langgraph and pydantic. Everything else is a separate package:

PackageWhat it holdsWhere it appears
langchaininit_chat_model, the message classes, @tool, create_agent, middlewareInstalled in Installing Python for generative AI
langchain-coreThe base classes: messages, prompt templates, output parsers, the Runnable interfaceComes with langchain
langchain-groqChatGroq, the chat model for models hosted on GroqInstalled in the setup lesson
langchain-google-genaiChatGoogleGenerativeAI and GoogleGenerativeAIEmbeddings for GeminiInstalled in the setup lesson
langgraphThe runtime that executes agents and graphs and saves their memoryComes with langchain
langchain-text-splittersClasses that split long text into chunksThe RAG lessons
langchain-communityDocument loaders and many third-party integrationsThe RAG lessons

langchain-community emits a deprecation warning on import saying that it is being sunset in favour of standalone integration packages. The lessons that load documents and stores name the package each import comes from.

Choosing a model with init_chat_model

Loading the keys and creating a chat model · from the Complete Agentic AI Course video · 38:03 to 40:22

The video loads its keys with python-dotenv, then imports init_chat_model, which it describes as one of the functions used to initialise any kind of chat model, and passes a model name. The video's first model is an OpenAI model, which needs a paid key and the langchain-openai package. This course passes a Groq model instead, and the rest of the code stays the same.

Syntax: one string holds the provider and the model name, and extra settings follow as keyword arguments.

python
from langchain.chat_models import init_chat_model

model = init_chat_model("<provider>:<model name>", temperature=0)
reply = model.invoke("a string, or a list of messages")
print(reply.text)
Model stringPackage it needsClass it returnsKey
groq:openai/gpt-oss-120blangchain-groqChatGroqGROQ_API_KEY
google_genai:gemini-2.5-flash-litelangchain-google-genaiChatGoogleGenerativeAIGOOGLE_API_KEY

Write the provider prefix every time. Without it, LangChain guesses the provider from the start of the name, and a guess can pick the wrong one. A provider whose package is not installed raises an ImportError.

Messages and the reply

A chat model takes messages in and returns one message out. There are four kinds, and a plain string passed to invoke is treated as a single human message.

  • SystemMessage tells the model how to behave.
  • HumanMessage carries what the user said.
  • AIMessage is what the model returned: text, any tool calls it asked for, and token counts.
  • ToolMessage carries the result of a tool call back to the model.

Messages and prompts builds each of them. The reply is always an AIMessage, and reply.text is its text.

Runnables and the pipe operator

Chat models, prompt templates and output parsers are all runnables. Each one has invoke for one input, stream for chunks as they arrive and batch for several inputs, and the pipe operator | joins runnables so that the output of one is the input of the next. A prompt template that fills in values, a model, and a parser that returns the reply's text as a string make a chain of three.

ExampleAPI keyRun on Groq
from langchain.chat_models import init_chat_model
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

model = init_chat_model("groq:openai/gpt-oss-120b", temperature=0)
print(type(model).__module__, type(model).__name__)

prompt = ChatPromptTemplate.from_messages([("system", "Answer in {language}."), ("human", "{question}")])
chain = prompt | model | StrOutputParser()
print(chain.invoke({"language": "French", "question": "Say good morning."}))

Reading the chain

  • The first line shows that init_chat_model returned the provider's own class, from the langchain-groq package. LangChain is the shared interface; the provider package does the talking.
  • The second line is the chain's answer, a French greeting. The values in the dictionary filled the {language} and {question} slots, the model replied, and StrOutputParser turned the reply message into plain text.

Importing from the right package

Many older tutorials and notebooks import from modules that no longer exist in LangChain 1.x. The error is the first sign that a snippet was written for an older release.

ExampleAn import from LangChain 0.x
from langchain.text_splitter import RecursiveCharacterTextSplitter

The text splitters live in their own package now:

ExampleThe 1.x import
from langchain_text_splitters import RecursiveCharacterTextSplitter

print(RecursiveCharacterTextSplitter.__module__)

The same move happened to langchain.document_loaders, which became langchain_community.document_loaders, and to langchain.prompts and langchain.schema, whose contents are in langchain_core and langchain.messages.

Where each piece is taught

LangChain pieceWhat it doesTaught in
init_chat_model, invokeCreate a model and call itYour first LLM app
SystemMessage, HumanMessage, ChatPromptTemplateBuild the inputMessages and prompts
stream, batchChunks as they arrive; several questions at onceStreaming and batch
with_structured_outputGet a typed object instead of textStructured output
trim_messages, InMemorySaver, thread_idConversation memoryA chatbot with memory
Loaders, text splittersRead files and cut them into chunksLoading and chunking documents
Embeddings, vector storesSearch by meaningEmbeddings and vector stores
Document, retrieversText with metadata, and a search over a store that returns documentsBuilding a RAG pipeline
@tool, tool callsLet the model ask for a functionTool calling
create_agentA model that loops over toolsAI agents and ReAct agents
Summarisation and approval middlewareMemory limits and a human checkAgent memory and Human in the loop
LangGraph graphsCustom flows with shared stateLangGraph essentials

LangChain vs calling a provider's own SDK

LangChainA provider's own SDK
Switching providerChange the model stringRewrite the calls in that provider's format
Message formatOne set of message classes for every providerEach provider has its own dictionaries
Tools, agents, memoryIncludedYou write the loop
Control and sizeOne more layer to learn, and versions moveFewer layers, tied to one provider

Where you use LangChain

  • Switching models: try the same prompt on Groq and on Gemini by changing one string.
  • Building agents: create_agent gives a tool-calling loop with memory and approval steps ready to configure.
  • Connecting your data: loaders, splitters, embeddings and vector stores share one interface.
Watch out. LangChain changes quickly, and tutorials written for an older release use imports and names that have moved. Pin the versions as in Installing Python for generative AI, and when an import fails, check the version the snippet was written for before changing your code.
Try it yourself
  • Change the model string in the chain to groq:openai/gpt-oss-20b and run it again. What changes in the answer, and what stays the same?
  • Change French to Spanish in the dictionary passed to chain.invoke.
  • Remove | StrOutputParser() from the chain and print the result. Which type do you get now?

Every expert started right here.