AI engineering glossary · Agents tools MCP

What is langChain?

LangChain: An open-source framework of building blocks for applications that use language models, including prompt templates, model wrappers, retrievers, tool interfaces and chains. It speeds up prototyping by providing ready-made integrations.

Level: beginnerTopic: Agents tools MCP

LangChain: an example

A team uses LangChain to connect a model to a vector store and a calculator tool in a few lines.

LangChain in Python

A short example you can run (Python 3.11). The output below is what it really prints.

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnableLambda
from langchain_core.output_parsers import StrOutputParser

prompt = ChatPromptTemplate.from_messages([
    ("system", "You answer in one short sentence."),
    ("human", "What is {topic}?"),
])
# A stand-in for a chat model so this runs without an API key; swap in ChatOpenAI(), ChatAnthropic() etc.
fake_llm = RunnableLambda(lambda p: f"[model saw {len(p.to_messages())} messages] {p.to_messages()[-1].content}")
chain = prompt | fake_llm | StrOutputParser()
print(chain.invoke({"topic": "RAG"}))

Output

[model saw 2 messages] What is RAG?

Related terms

More Agents tools MCP terms

Where you learn it

LangChain is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.