LLM Lab

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.

Where this sits in a LangChain agent
Model→Tools→Agent loop (create_agent)→Middleware→Memory (checkpointer)→Integrations (MCP)→Guardrails

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.

system prompt→messages→model→tool calls → tools→tool results→final answer
The agent loop at the centre of LangChain: the model reads the system prompt and messages, may call tools, reads their results, and repeats until it answers. LangChain’s phrase for it is “Agent = Model + Harness”: everything around the model is the harness.

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.

messageshookstool callsresultssaves stateno more callsusersystem promptmiddlewarechat model"provider:model"tools@tool functionscheckpointerthread_idansweror structured_response
modeltoolsmiddlewareinputs and storage
Everything create_agent puts together. The model and the tools form the loop; the system prompt and messages go in, middleware hooks around each step, the checkpointer saves the state, and the run ends with an answer.

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

Check yourself · 1 of 3

In LangChain v1, which function builds an agent?

Check yourself · 2 of 3

What does the model string "provider:model-name" do?

Check yourself · 3 of 3

Where does a structured answer appear when you pass response_format?

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.
All books
Labassemble an agent
How to read this
  • Tick the parts you want in the agent. The stage map lights the parts in use, and the code panel shows the matching create_agent call.
  • The line under the code says what the agent can now do that it could not before.