LangChain building blocks
LangChain is a library for building applications on LLMs. Its core idea is small: a model, some tools, and a loop around them.
The building blocks
A chat model takes a list of messages (system, user, assistant, tool) and returns the next message. Tools are functions the model may ask to call. An agent runs the model and the tools in a loop until the task is done. Around that loop sit optional parts: a system prompt, a response format for structured answers, middleware that hooks into each step, and a checkpointer that saves the conversation.
In code
In LangChain v1 one function assembles all of this: create_agent. You choose the model with a "provider:model-name" string, which keeps the rest of the code the same if you switch providers, and pass Python functions decorated with @tool. The result is a LangGraph graph, so it can stream, pause for a human and resume, like any graph you will build in Part 08.
A worked example
A support agent needs to look up orders and answer in a fixed shape. Give it a lookup_order tool, a system prompt with the house rules, and a response_format with fields for the answer and the order ID. Add a checkpointer so follow-up questions in the same thread remember the order, and middleware that asks a person before any refund tool runs. Each requirement maps to one argument.
Easy to confuse
- LangChain builds single agents and their parts; LangGraph is the lower-level library for custom graphs of steps and agents. create_agent is built on LangGraph.
- A tool is code you run; the model only proposes the call. Nothing happens unless your application executes it.
In LangChain v1, which function builds an agent?
create_agent (from langchain.agents) takes a model, tools, a system prompt and optional parts such as middleware and a checkpointer, and returns a runnable agent built on LangGraph.
What does the model string "provider:model-name" do?
LangChain wraps providers behind one chat-model interface; the string names which one to use.
Where does a structured answer appear when you pass response_format?
With response_format set, the agent validates its final answer against your schema and returns it under structured_response, next to the messages.
Read more in the books
- LangChain and LangGraph documentation, LangChain: LangChain: Overview, Agents and Models.
- Learning LangChain, Mayo Oshin, Nuno Campos: the chapters on LangChain’s building blocks and agents.
- AI Engineering, Chip Huyen: Ch. 6, “RAG and Agents”: agents.