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
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.
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.
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 — included in the starter ZIP from Project Setup.Run it
python architecture_demo.pyHow this maps to your files
| File | Architecture layer |
|---|---|
| hello_langchain.py | Client + HumanMessage |
| hello_ollama.py | Same pattern, local provider |
| model_params_demo.py | Constructor options on the client |
| architecture_demo.py | Client + SystemMessage + HumanMessage |
Deeper reading: Messages.
What's Next
You know how messages and clients connect. Next: reuse prompt patterns with placeholders.