LangChain BasicsLesson 4

LangChain Architecture Overview

Your scripts already call ChatOpenAI or ChatOllama and pass messages. This lesson names those layers so later topics (prompts, memory, tools) have a clear place. The demo reuses the HTML question pattern from LangChain Basics.

The stack

Think of LangChain as middleware. Your Python file builds a list of messages; LangChain sends them to OpenAI or Ollama; the provider sends back text you print.

Data flows downward on each call:

Your app

architecture_demo.py

Messages

SystemMessage · HumanMessage

Client

ChatOpenAI · ChatOllama

Provider

OpenAI API · Ollama on localhost

LangChain formats your messages and talks to the provider. It does not host weights or run training.

Core pieces

Official docs list many components. For now, stick to Models and Messages — the same two sections behind every script you have run so far.

docs.langchain.com — Core components

Core components

  • Agents
  • Models
  • Messages
  • Tools
  • Short-term memory
  • Streaming

What you use in this lesson

Models

Docs label this section Models — here that means ChatOpenAI and ChatOllama plus llm.invoke()

Messages

System, Human, AI — message roles the API reads in order

Later: Prompts · Chains · Agents · Tools

Reusable prompt templates and multi-step flows come in later lessons — not needed for your first scripts.

Simplified from the LangChain docs overview. This lesson sticks to the Models and Messages sections you have already used in code.

Message roles

  • SystemMessage — instructions for how to answer (for example, "Keep each reply to one short sentence."). Optional, but handy when you want a fixed format.
  • HumanMessage — the question from your script. You used this in every file so far.
  • AIMessage — the assistant reply stored in chat history. You will use this when you keep earlier turns in memory.

The demo script

architecture_demo.py asks about the <title> tag with a system message plus a human message — then calls llm.invoke().

architecture_demo.py
"""architecture_demo.py — system and human messages"""
… imports, load_dotenv(), llm = ChatOpenAI(…) …
reply = llm.invoke([
SystemMessage(content="Keep each reply to one short sentence."),
HumanMessage(content="What does the <title> tag do?"),
])
Save as architecture_demo.py — included in the starter ZIP from Project Setup.

Run it

python architecture_demo.py
PowerShell — (.venv) active
(.venv) PS C:\projects\langchain-course> python architecture_demo.py
The <title> tag sets the text shown in the browser tab.
Same pattern as your earlier scripts — here with a system message added for context.

How this maps to your files

FileArchitecture layer
hello_langchain.pyClient + HumanMessage
hello_ollama.pySame pattern, local provider
model_params_demo.pyConstructor options on the client
architecture_demo.pyClient + SystemMessage + HumanMessage

Deeper reading: Messages.

What's Next

You know how messages and clients connect. Next: reuse prompt patterns with placeholders.