Module 1: Foundations

Why LangChain Exists

Learning objectives

  • Explain the core mental model behind Why LangChain Exists
  • Apply Why LangChain Exists within Foundations
  • Identify important boundaries, trade-offs, and failure modes
  • Produce concrete evidence from the practice exercise

Migration rule: when the vault reference uses AgentExecutor, ConversationBufferMemory, or imports from langchain.chains, translate the concept to create_agent, graph state with a checkpointer, or langchain-classic respectively.

Legacy and migration reference from the vault

Related: LangChain What Is LangChain | LangChain Core Concepts | LangChain Architecture Overview | LangChain Index


The Limits of Direct LLM Calls

A direct API call is a function: text in, text out. That works for single-turn Q&A, but breaks down for real applications.

Problem 1: No External Data

LLMs know only their training data. They cannot read your company's wiki, your email, or today's news.

LangChain solution: Document loaders + vector stores + retrievers.

Problem 2: No State

Each API call is stateless. If you want a conversation, you have to manually prepend history.

LangChain solution: Memory classes and prompt templates with MessagesPlaceholder.

Problem 3: No Tool Use

A raw LLM cannot search the web, run code, or query a database.

LangChain solution: Tools and agents.

Problem 4: No Composition

Every project reinvents the same boilerplate: prompt templating, retry logic, output parsing, error handling.

LangChain solution: Runnable abstractions and LCEL.

Problem 5: No Observability

When a complex pipeline fails, you cannot see which step broke.

LangChain solution: Callbacks and LangSmith tracing.


What LangChain Adds

CapabilityDirect APILangChain
Prompt templatingManual f-stringsChatPromptTemplate
Output parsingRegex / json.loadsPydanticOutputParser
MemoryManual list managementConversationBufferMemory
Tool useCustom code@tool + AgentExecutor
RetrievalCustom vector searchVectorStoreRetriever
TracingPrint debuggingLangSmith
StreamingRaw SSE parsingastream()
BatchCustom threadingabatch()

When Not to Use LangChain

  • Simple single-prompt apps. A direct API call is fine.
  • Custom inference servers. If you own the whole stack, you may not need the abstraction layer.
  • Research experiments. Rapid iteration may be faster without framework constraints.

Related

  • LangChain What Is LangChain — the working definition
  • LangChain Core Concepts — the vocabulary
  • LangChain Architecture Overview — the system design
  • LangChain Index — full topic map

Practice lab

Implement the smallest runnable agent workflow that demonstrates Why LangChain Exists. Trace inputs, state, model and tool calls, outputs, and cost; inject one failure and add a regression test that prevents it from returning.

Review questions

  1. What problem does Why LangChain Exists solve, and what assumptions does it rely on?
  2. Which boundary or failure case is easiest to miss, and how would you expose it?
  3. What alternative design would you consider, and what trade-off would change the decision?
  4. What artifact, trace, test, or metric proves that your implementation is correct?

Completion evidence

  • A working artifact, annotated trace, or reproducible experiment
  • At least one normal case and one deliberately failing or boundary case
  • A concise explanation of the design choice and its trade-offs
  • Saved output showing how correctness was evaluated