LangChain building blocks
Agentic AI Foundations · Lesson 4 of 20 · 20:40
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Oracle Agentic AI Foundations Associate exam (1Z0-1157-26). In this lesson: chat models and messages, prompt templates, tools defined with the @tool decorator and bound to a model, and chains built with the LangChain Expression Language (LCEL). Includes three original practice questions, with Fairhaven Furniture, a fictional furniture seller, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Why a framework?
Fairhaven's engineers start their prototype on a laptop, and they do not want to rewrite it every time they try a different model. They also want reusable prompts, tools that the model can call, and steps that connect cleanly. That's what LangChain gives them: a set of building blocks for applications and agents on top of language models.
Chat models
LangChain is an open source framework for building applications and agents on top of language models. Its first abstraction is the chat model: one interface for every provider. With init_chat_model, you name the provider and the model in one string, and switching provider means changing only that string. And invoke is the universal way to run any LangChain component.
Chat models work with messages, and each message has a role. A system message sets the behavior, a human message is the user's turn, and an AI message is the model's reply. A fourth type, the tool message, carries the result of a tool back to the model, and you meet it again in lesson five. A conversation is just the list of these messages, and the model reads the whole list on every call.
Prompt templates
Prompt templates are reusable prompts with placeholders that you fill in later: you write the wording once, and reuse it many times. A PromptTemplate is a single string with blanks. A ChatPromptTemplate is built from roles, a system message and a human message, which is how chat models expect their input. When you fill the placeholders, it returns the list of messages, ready for the model.
Tools
Tools are plain Python functions with the tool decorator. LangChain turns the function's name, its docstring, and its type hints into the schema that the model reads, so a clear docstring matters: it's how the model decides when to use the tool. Then bind_tools tells the model which tools are available. And remember the boundary from lesson one: a model with bound tools only returns a tool call, with a name and arguments. Running the tool and sending the result back is the agent's job.
Chains
Chains connect the pieces with the LangChain Expression Language, LCEL for short. The pipe operator glues components into a pipeline, and each step's output flows into the next, from left to right: prompt, then model, then output parser. A string output parser turns the model's message into plain text. And one invoke call runs the whole chain, with the values for the placeholders. Notice that a chain always runs the same steps in the same order: it's a pipeline, not an agent.
Recap
Let's recap. LangChain is an open source framework, and init_chat_model gives one interface to every provider. Messages have roles: system, human, AI, and tool. Prompt templates are reusable prompts with placeholders, and a ChatPromptTemplate is built from roles. Tools are functions with the tool decorator, described by their docstring, and bind_tools makes them available, while the model only requests the calls. And LCEL chains components with the pipe operator, into a fixed pipeline.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
Fairhaven’s prototype calls a model from one provider. The team wants to try a model from another provider, with the smallest possible code change. What should they change?
- The model string passed to init_chat_model
- The prompt template, to add the new provider
- Every tool, rewritten for the new provider
- The chain, with a provider-specific parser
Show the answer
The model string passed to init_chat_model
Init_chat_model gives one interface to every provider, so switching means changing the provider and model string. “The prompt template, to add the new provider” would change what the model is asked, not which model answers. “Every tool, rewritten for the new provider” is not needed: tools are defined once, and they work with any chat model that supports tool calling. And “The chain, with a provider-specific parser” is not needed either, because the parser works on the model's output, whatever the provider.
Fairhaven’s prototype often picks the wrong tool between an order status tool and a return window tool. Both functions work, but their docstrings are empty. What should the team fix first?
- Change the model string in init_chat_model
- Raise the maximum number of iterations
- Use a PromptTemplate instead of chat messages
- Write clear docstrings for both tools
Show the answer
Write clear docstrings for both tools
LangChain builds each tool's schema from its name, docstring, and type hints, and the description is how the model decides when to use a tool. “Change the model string in init_chat_model” would switch models, but even a better model has to guess when the descriptions are empty. “Raise the maximum number of iterations” would give the agent more turns to pick the wrong tool again. And “Use a PromptTemplate instead of chat messages” changes the format of the prompt, not what the model knows about the tools.
Fairhaven builds a chain from a prompt, a model, and a string output parser, joined with the pipe operator, to explain its policies. What does this chain do when it’s invoked?
- It decides at each step which tool to call
- It runs the tools that the model requests
- It runs the same three steps, in order
- It stores the conversation in long-term memory
Show the answer
It runs the same three steps, in order
The pipe operator builds a fixed pipeline, so the prompt is filled, the model answers, and the parser returns text, in that order, every time. “It decides at each step which tool to call” describes an agent, which chooses its next step, and a chain has no such loop. “It runs the tools that the model requests” needs an agent loop as well, and this chain has no tools at all. And “It stores the conversation in long-term memory” is not part of this chain: nothing here stores the conversation.