Skill-Lite

Practical tutorials & tools for modern developers.

Home/LangChain/Introduction

Introduction to LangChain

LangChain is a framework for building applications powered by large language models (LLMs). It provides composable building blocks — models, prompts, chains, memory, agents, and tools — that let you go from a raw LLM call to a production-grade AI application.

Why LangChain?

Calling an LLM API directly works for simple use cases, but real applications need more: multi-step reasoning, memory of past conversations, access to external data, and the ability to take actions. LangChain provides standardised abstractions for all of these so you can focus on your application logic, not the glue code.

ProblemLangChain solution
LLM outputs are unstructuredOutput parsers & structured output
Context window limitsMemory + RAG (retrieval-augmented generation)
LLM can't act on the worldAgents + Tools (search, code execution, APIs)
Hard to switch LLM providersUnified model interface (OpenAI, Anthropic, Ollama, …)
Complex multi-step pipelinesChains & LCEL (composable pipe syntax)

Core components

Models

  • LLMs & Chat Models
  • Embeddings
  • OpenAI, Anthropic, Ollama…

Prompts

  • PromptTemplate
  • ChatPromptTemplate
  • Few-shot examples

Chains / LCEL

  • Sequential steps
  • | pipe operator
  • Parallel branches

Memory

  • Conversation history
  • Summarisation
  • Buffer window

Agents & Tools

  • ReAct pattern
  • Web search, code, APIs
  • Custom tools

RAG

  • Document loaders
  • Text splitters
  • Vector stores

Installation

# Core package
pip install langchain

# LLM provider integrations
pip install langchain-openai          # OpenAI / Azure OpenAI
pip install langchain-anthropic       # Anthropic Claude
pip install langchain-community       # Ollama, HuggingFace, 100+ integrations

# Vector stores and RAG
pip install langchain-chroma          # Chroma vector DB
pip install faiss-cpu                 # FAISS vector search

# Useful utilities
pip install python-dotenv             # load .env secrets
pip install tiktoken                  # token counting for OpenAI

Your first LangChain app

from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage

# 1. Instantiate a model
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.7)

# 2. Send a message
messages = [
    SystemMessage(content="You are a helpful coding assistant."),
    HumanMessage(content="Explain what a Docker container is in 2 sentences."),
]

response = llm.invoke(messages)
print(response.content)

Environment setup

# .env file (never commit this!)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...

# Load in Python
from dotenv import load_dotenv
load_dotenv()   # reads .env automatically

import os
key = os.getenv("OPENAI_API_KEY")

LangChain ecosystem

PackagePurpose
langchain-coreBase abstractions: Runnable, BaseMessage, PromptTemplate
langchainChains, agents, memory — the main framework
langchain-openaiChatOpenAI, OpenAIEmbeddings
langchain-anthropicChatAnthropic (Claude models)
langchain-community100+ community integrations (Ollama, HuggingFace, loaders)
langchain-chromaChroma vector store integration
langgraphGraph-based stateful multi-agent workflows
langserveDeploy chains as REST APIs (FastAPI-based)
langsmithTracing, debugging, evaluation for LLM apps
LangChain Expression Language (LCEL) is the modern way to compose chains using the | pipe operator. It supports streaming, async, batching, and tracing out of the box. All examples in this tutorial use LCEL.