Slides · LangChain ecosystem

The LangChain map and Runnables

The LangChain map and Runnables

Which part of the toolkit does a job need, how its pieces snap together, and when to leave all of it on the shelf.

By the end you can say what LangChain, LangGraph, LangSmith and Deep Agents are each for, predict what a pipe or a dict does, get typed output and tool calls with identity injected, and decide when a plain SDK call is the better build.

Concept

One word, several products

  • A team opens the agent toolkit’s documentation and finds a row of pieces that snap together, plus a long list of other packages.
  • The ticket for the day says “build the support agent”. Nothing says which package that means.
  • “We used LangChain” can mean a model interface, a ready-made agent, a graph runtime or a tracing service.
  • Naming the job first, then taking the one part that does it, is the habit this lesson builds.

Concept

Mental model: three counters in one shop

  • LangChain sells pieces that fit together and a ready-made agent: quick, with sensible defaults.
  • LangGraph is the workflow map. You draw steps and the paths between them, and shared state carries information along, so a job can pause, loop and resume.
  • LangSmith is the recorder you attach to an application. It is a separate service, not a feature of one library.
  • Deep Agents is a packaged, longer-running agent harness built on the rest.
  • Rule of thumb: you rarely need the whole shop.

Diagram

Name the job, then take the part

Diagram: A quick tool-calling agent or a portable model interface points to LangChain.

Tool agent, fast

Loops, state, pauses

Debug and evaluate

One prompt, one parse

What is the job?

LangChain

LangGraph

LangSmith

Provider SDK

Diagram summary: A quick tool-calling agent or a portable model interface points to LangChain. Loops, shared state and pauses point to LangGraph. Seeing and evaluating any run points to LangSmith. A single prompt and a parser needs only the provider SDK.

Concept

What each piece is, from the docs

  • LangChain: its overview presents create_agent as a minimal, configurable harness: the prompt, tools and middleware around a model loop.
  • LangGraph: a low-level orchestration framework and runtime for long-running, stateful agents. The LangChain overview says LangChain agents are built on it; the LangGraph overview says LangChain is not required to use it.
  • Deep Agents: described as a batteries-included option with a virtual filesystem, subagents and context compression. Its own page says it sits on LangChain’s agent building blocks and uses the LangGraph runtime.
  • LangSmith: tracing, debugging and evaluation. Its observability page says it works with many frameworks and providers, and lists examples such as OpenAI, Anthropic and CrewAI.

Sources1 LangChain overview (LangChain documentation)2 LangGraph overview (LangGraph documentation)3 Deep Agents overview (LangChain documentation)4 Observability (LangSmith documentation)

Compare

Reach for each piece when

PieceReach for it when
langchain-coreIt is already underneath: shared interfaces for models, messages and tools
langchainA standard tool-calling agent quickly, or one model interface across vendors
Provider packagesA vendor or store is swapped or added without rewriting application code
langgraphExplicit state, branching, loops, approvals, or a job that resumes
Deep AgentsA long, open-ended task and a planning-and-subagents harness ready made
LangSmithAnything run in production that must be debugged, with or without LangChain
  • Moving from a create_agent call to LangGraph later is a step down a level, because the agent already runs on it.
  • Which piece belongs to which package is a teaching map, not an official dependency chart.

Sources1 LangChain overview (LangChain documentation)2 LangGraph overview (LangGraph documentation)

Diagram

How the pieces relate

Diagram: LangGraph and LangChain both depend on the shared core, LangChain agents run on the graph runtime, and Deep Agents builds on LangChain.

agents run on

traces

traces

traces

langchain-core

langgraph runtime

langchain agents

Deep Agents

LangSmith

Other code

Diagram summary: LangGraph and LangChain both depend on the shared core, LangChain agents run on the graph runtime, and Deep Agents builds on LangChain. LangSmith is beside the stack: it receives traces from LangChain, from LangGraph or from other code. This is a teaching sketch based on the docs’ descriptions, not an official dependency chart.

Concept

What 1.0 changed, and why old tutorials mislead

  • create_agent is described in the release notes as the new standard for building agents, replacing create_react_agent from langgraph.prebuilt.
  • Middleware is the main customisation point for that loop (next lesson).
  • Structured output is produced in the main loop, not in an extra model call, which the notes say reduces cost.
  • A content_blocks property gives one provider-neutral view of text, reasoning and tool calls; the notes list the integrations supported at the time and say broader support will come gradually.
  • Legacy chains, retrievers, the indexing API and the hub moved to langchain-classic. The migration page lists LLMChain and ConversationChain among the legacy pieces and requires Python 3.10 or higher for all LangChain packages.

Sources5 LangChain v1 release notes (LangChain documentation)6 Migrate to LangChain v1 (LangChain documentation)

Worked example

Reading stability honestly

The versioning page says breaking changes arrive only in major releases and that deprecated APIs are removed in a later major version. It also says LangChain and LangGraph 1.0 are long-term-support releases, and that Deep Agents was pre-1.0 when read, so its API may change between minor versions.

FactEvidence
Versions a clean pip install gave on 2026-10-24langchain 1.4.7, langchain-core 1.7.0, langgraph 1.2.17 (measured)
Features still arrive inside a major versionthe built-in middleware page states a minimum langchain version for some classes
Say which version you last readan interview habit; most doc pages carry no version number
  • A year-old answer built on AgentExecutor or memory classes dates you more than any missing feature.

Source7 Versioning (LangChain documentation)

Check yourself

Check: which package do you need?

A script must build a graph with a state, three nodes and a checkpointer. It has no model loop and never calls create_agent. Which package does it need at minimum, and which of the three products is optional for debugging it?

Answer

langgraph. It pulls in langchain-core but not the langchain package (pip metadata, langgraph 1.2.17). Its overview says LangChain is not needed to use it, and create_agent is the LangChain piece the script never calls. LangSmith is the optional one: a separate service that can trace the run when tracing is switched on, and the script works without it.

Concept

Every component has the same shape

  • A model, a prompt template, an output parser, a retriever and a plain wrapped function are all Runnables.
  • Each can be called once (invoke), over a list (batch) or as a stream (stream), plus async versions.
  • Because the shape is shared, pieces compose without glue code: a pipe joins two Runnables in sequence, and a dict of Runnables runs its branches on the same input and returns a dict.
  • The payoff is that one definition gives synchronous, batch and streaming calls, and tracing hooks in once for the whole chain.
  • Checked on langchain-core 1.7.0 (2026-10-24) with a scripted stand-in model, so no API key was used.

Code

A retrieval chain in the pipe style

Python

chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | model
    | StrOutputParser()
)
answer = chain.invoke("What is a KV cache?")

Read it left to right. The dict fans the question out: one branch retrieves and formats documents, the other passes the question through. The prompt fills two slots, the model answers and the parser turns the message into a string.

Call on the same chain (scripted model)Result
invoke("What is a KV cache?")one string
the prompt text the model receivedContext: the formatted documents, then Q: the question
batch(["q1", "q2"])a list of two strings
stream("q3")an iterator of string chunks

Diagram

The data flow, step by step

Diagram: The question goes to two branches at once.

question

retrieve and format

pass through

dict: context, question

prompt

model

string parser

Diagram summary: The question goes to two branches at once. Their results meet as one dict with the keys context and question, which fills the prompt; the model answers and the parser turns the reply into text. Every box is a Runnable, so the whole chain can be invoked, batched or streamed.

Worked example

Worked example: trace a dict into a pipe

Python

step = {"n": RunnableLambda(len), "up": RunnableLambda(str.upper)} \
       | RunnableLambda(lambda d: f"{d['up']}-{d['n']}")
InputDict result (both branches ran)Final output
"abc"{"n": 3, "up": "ABC"}"ABC-3"
"hey"{"n": 3, "up": "HEY"}"HEY-3"
batch(["ab", "wxyz"])one dict per input["AB-2", "WXYZ-4"]
  • Run and checked: invoke("abc") gave ABC-3 and the batch gave ['AB-2', 'WXYZ-4'].
  • The next step receives the dict, so its code reads keys. Forgetting that is a common first error.

Worked example

Batching: cap the parallelism

batch runs calls in parallel from the client. A rate-limited provider answers too many at once with 429 errors, so the cap is a setting you choose.

Test (10 inputs, 50 ms each)Peak simultaneous calls
batch(inputs) with no cap10 on the test machine
batch(inputs, config={"max_concurrency": 3})3
  • The models page documents max_concurrency in the config and a default of 6 retries for network errors, rate limits and server errors; client errors such as a bad key are not retried.
  • A retry that works still costs latency, and for a write it can repeat a side effect.

Source8 Models (LangChain documentation)

Compare

Where the pipe style stops

NeedPipe chainWhy
prompt, then model, then parsefitsone-way flow
regenerate until a validator passesdoes not fitno loop and no memory of the last attempt
branch on something learned midwayawkwardthe shape is fixed when you write it
wait for a person, resume tomorrowdoes not fitno saved state

Test run: a two-step chain whose first step returns “bad” and whose second step maps anything but “good” to “INVALID” called the first step once and returned “INVALID”. Nothing in the chain went back to try again.

  • A chain can still sit inside one step of a graph.
  • A three-step pipeline is often clearer as three plain function calls.

Check yourself

Check: predict the output

Python

step = {"n": RunnableLambda(len), "up": RunnableLambda(str.upper)} \
       | RunnableLambda(lambda d: f"{d['n'] * 2}:{d['up']}")

What does step.invoke("hello") return, and what does the final lambda receive?

Answer

"10:HELLO". The final lambda receives the dict {"n": 5, "up": "HELLO"}, because the dict ran both branches on the input "hello". Then 5 * 2 is 10. (Checked by running it.)

Diagram

Messages: a tool call needs its answer

Diagram: Messages come in four kinds: system, human, AI and tool.
Chat modelYour loopChat modelYour loopsystem + human messagesAI message, tool call id c1run the tooltool message, call id c1AI message, final answer
Diagram summary: Messages come in four kinds: system, human, AI and tool. The models page says a tool message carries a tool call id matching the original request, which lets the model pair each result with its call. A tool result without the matching id breaks that pairing, so hand-written loops must carry the id through.

Source8 Models (LangChain documentation)

Concept

Two routes to typed output

  • On a bare model: with_structured_output(schema) takes a Pydantic model, a typed dict or JSON schema. The models page says include_raw=True returns the parsed result and the raw message together.
  • In an agent: pass response_format. The structured-output page describes a provider strategy (the vendor’s native structured output, called the most reliable when available) and a tool strategy (tool calling, for models without native support). A bare schema lets LangChain choose.
  • The validated result appears under structured_response in the final state.
  • With the tool strategy, handle_errors controls whether a failed validation is retried with feedback; it defaults to retrying.

Sources9 Structured output (LangChain documentation)8 Models (LangChain documentation)

Diagram

How an agent picks the strategy

Diagram: A model with native structured output uses the provider strategy; otherwise the tool strategy gets the same result through tool calling.

yes

no

yes

no

response_format given

Native support?

Provider strategy

Tool strategy

Validation fails?

Error back to model

structured_response

Diagram summary: A model with native structured output uses the provider strategy; otherwise the tool strategy gets the same result through tool calling. With the tool strategy, a failed validation returns an error to the model, which can fix its output, before a valid object lands in structured_response.

Source9 Structured output (LangChain documentation)

Code

Typed does not mean right

Python

class Ticket(BaseModel):
    category: str = Field(description="billing, bug or how-to")
    priority: int = Field(ge=1, le=5)

typed = model.with_structured_output(Ticket)
Scripted model returnsResultReading
{"category": "billing", "priority": 2}a Ticket objectworks
priority 9ValidationError raisedthe schema caught it
same, with include_raw=Truedict with raw, parsing_error, parsed (None)failure is inspectable
{"category": "banana", "priority": 1}a valid Ticketvalid and wrong: the schema does not know the three allowed categories
  • Run with a scripted stand-in for the model. Truncation at the token limit is a further real-world failure this test did not cover.
  • Validate, retry a bounded number of times, and decide what the program does when it still fails.

Source8 Models (LangChain documentation)

Code

Identity arrives by injection

Python

@tool
def get_order(order_id: str, runtime: ToolRuntime[Ctx]) -> str:
    """Look up one order by id."""
    return DB.get((order_id, runtime.context.user_id), "not found")

The tools page says the runtime parameter is injected at call time and is not part of the schema sent to the model; context holds immutable per-call data such as a user id.

Test (scripted model, in-memory table)Result
Properties in the schema the model seesonly order_id
Caller context user u1, model asks for A-17the order
Caller context user u9, same requestnot found
Model adds an extra user_id: "u2" argumentstill scoped to u1’s data
Unsafe version with user_id as a normal argument, model passes u2returns u2’s data

Source10 Tools (LangChain documentation)

Diagram

Why the user id stays out of the arguments

Diagram: The model supplies only the order id.

Model sees: order_id

Tool call

Caller session

runtime.context.user_id

Tool runs

Query scoped to user

Diagram summary: The model supplies only the order id. The user id comes from the caller’s authenticated session through the injected runtime, so a prompt-injected document or a persuasive user cannot change whose data is read. Anything that decides whose data or which tenant belongs here, not in the model’s arguments.

Source10 Tools (LangChain documentation)

Check yourself

Check: argument or injected?

A refund tool needs five values: the order id, the tenant id, the refund amount, a database connection and the customer’s free-text reason. Which come from the model, and which should be injected?

Answer

Model arguments: order id, refund amount and reason, because only the model’s reading of the conversation can supply them. Injected through the runtime: tenant id (it decides whose data is touched) and the database connection (it is infrastructure, not a decision). The amount is model-chosen but still needs a business rule or an approval for large values, which is the next lesson’s job.

Compare

Retrieval: fixed step or tool

The retrieval page defines a retriever as an interface that returns documents for an unstructured query, and names three architectures.

ShapeControlLatencyFits
Two-stephighfast, predictableFAQ and documentation bots
Agentic (retrieval as a tool)lowvariableassistants with several tools
Hybrid (adds query rewriting and checks)mediumvariablequality-sensitive domain Q&A
  • The framework provides plumbing. Good answers still depend on chunking, retrieval quality and evaluation, covered in the RAG module.

Source11 Retrieval (LangChain documentation)

Worked example

Worked example: counting calls per 100 messages

Illustrative assumptions: 100 user messages, 40 of them need documents, and an agentic model that retrieves once when it needs to.

DesignRetrievalsModel callsWhy
Two-step100100always retrieve, then answer
Agentic40140100 first calls, plus 40 more to answer after a retrieval
  • 100+40=140100 + 40 = 140. Agentic saves 60 retrievals and spends 40 more model calls, so which is cheaper depends on what a retrieval costs against a model call.
  • It also makes worst-case latency harder to bound, because the model decides how many searches to run.

Check yourself

Check: pick the shape

An internal assistant has six tools. About 60 of every 100 messages are greetings, small talk or tool requests that need no documents. Choose a retrieval shape and name one control you would add.

Answer

Agentic retrieval: retrieval is one of the six tools, so messages that need no documents skip it. The cost is variable latency and weaker control. Add a cap on tool calls per run and evaluate a sample for missed retrievals, where the model should have searched and did not.

Compare

When not to use it

OptionStrengthCostPick when
LangChain with LangGraphportability, resumable runtime, approvals, streaminga large API surface and release history to followmulti-step, stateful agents on a team wanting one stack
Provider SDK and plain Pythontransparent, few dependenciesyou write retries, state and streaming yourself (LangSmith tracing can be added to either)one model call, or maximum control
A workflow engine already in useproven durable executionnot model-awarereliability rules are strict and it is already run
Another agent framework or a vendor SDKergonomics for a style, or tight vendor integrationa different state modela fast prototype or a single-vendor product
  • These rows are judgment about trade-offs, not feature claims about specific releases.
  • Name the benefit you are buying. If the answer is “the tutorial had it”, remove it.

Diagram

A decision path you can say out loud

Diagram: Use the framework where you can name the benefit: portability, a resumable runtime, approvals or streaming.

yes

no

no

yes

yes

no

Resume, approvals,
or many vendors?

LangChain with LangGraph

More than one call
or any saved state?

Provider SDK

Workflow engine
in use?

Add model calls to it

Prototype and measure

Diagram summary: Use the framework where you can name the benefit: portability, a resumable runtime, approvals or streaming. A single prompt and a parser needs the provider SDK. If a durable workflow engine already runs, add model calls to it; otherwise decide from a measured prototype.

Summary

Recap

  • Name the job, then take the part: LangChain for a quick agent and a model interface, LangGraph for state and pauses, LangSmith for seeing any run, a plain SDK call for one prompt.
  • Every component is a Runnable; a pipe runs in sequence, a dict runs branches and returns a dict, and neither loops.
  • Typed output lowers malformed output but does not remove it. Validate and bound retries.
  • Identity and tenant reach a tool by injection, never as a model-chosen argument.
  • Two-step retrieval is predictable; agentic retrieval is flexible and variable.
  • Say which version you last read: this deck was checked against langchain 1.4.7 and langgraph 1.2.17 on 2026-10-24.

References

References & Sources (1 of 3)

  1. LangChain overview (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for What LangChain is, create_agent as a minimal configurable harness, agents built on LangGraph, Deep Agents and LangSmith as neighbours.

  2. LangGraph overview (LangGraph documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for LangGraph as a low-level orchestration framework and runtime, and that LangChain is not required to use it.

  3. Deep Agents overview (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for Deep Agents features, and that it sits on LangChain's agent building blocks and the LangGraph runtime.

  4. Observability (LangSmith documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for LangSmith works with many frameworks and providers, with named examples.

  5. LangChain v1 release notes (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for What 1.0 changed: create_agent, middleware, structured output in the main loop, content blocks and langchain-classic.

References

References & Sources (2 of 3)

  1. Migrate to LangChain v1 (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for Legacy chain classes in langchain-classic and the Python 3.10 or higher requirement.

  2. Versioning (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for Breaking changes only in major releases, deprecation, LTS status of 1.0 and Deep Agents being pre-1.0 when read.

  3. Models (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for Tool message call ids, max_concurrency for batch, the default of 6 retries and include_raw.

  4. Structured output (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for Provider and tool strategies, the structured_response key and handle_errors.

  5. Tools (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for The injected runtime parameter that is hidden from the model's schema and what the runtime carries.

References

References & Sources (3 of 3)

  1. Retrieval (LangChain documentation) (opens in a new tab)

    LangChain2026Documentation

    Used for The retriever definition and the control and latency of two-step, agentic and hybrid retrieval.