Slides · LangChain ecosystem
The LangChain map and Runnables
1 / 33
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
Concept
What each piece is, from the docs
- LangChain: its overview presents
create_agentas 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.
Sources[1] 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
| Piece | Reach for it when |
|---|---|
langchain-core | It is already underneath: shared interfaces for models, messages and tools |
langchain | A standard tool-calling agent quickly, or one model interface across vendors |
| Provider packages | A vendor or store is swapped or added without rewriting application code |
langgraph | Explicit state, branching, loops, approvals, or a job that resumes |
| Deep Agents | A long, open-ended task and a planning-and-subagents harness ready made |
| LangSmith | Anything run in production that must be debugged, with or without LangChain |
- Moving from a
create_agentcall 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.
Sources[1] LangChain overview (LangChain documentation)[2] LangGraph overview (LangGraph documentation)
Diagram
How the pieces relate
Concept
What 1.0 changed, and why old tutorials mislead
create_agentis described in the release notes as the new standard for building agents, replacingcreate_react_agentfromlanggraph.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_blocksproperty 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 listsLLMChainandConversationChainamong the legacy pieces and requires Python 3.10 or higher for all LangChain packages.
Sources[5] 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.
| Fact | Evidence |
|---|---|
| Versions a clean pip install gave on 2026-10-24 | langchain 1.4.7, langchain-core 1.7.0, langgraph 1.2.17 (measured) |
| Features still arrive inside a major version | the built-in middleware page states a minimum langchain version for some classes |
| Say which version you last read | an interview habit; most doc pages carry no version number |
- A year-old answer built on
AgentExecutoror memory classes dates you more than any missing feature.
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-core1.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 received | Context: 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
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']}")| Input | Dict 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")gaveABC-3and 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 cap | 10 on the test machine |
batch(inputs, config={"max_concurrency": 3}) | 3 |
- The models page documents
max_concurrencyin 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.
Compare
Where the pipe style stops
| Need | Pipe chain | Why |
|---|---|---|
| prompt, then model, then parse | fits | one-way flow |
| regenerate until a validator passes | does not fit | no loop and no memory of the last attempt |
| branch on something learned midway | awkward | the shape is fixed when you write it |
| wait for a person, resume tomorrow | does not fit | no 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
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 saysinclude_raw=Truereturns 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_responsein the final state. - With the tool strategy,
handle_errorscontrols whether a failed validation is retried with feedback; it defaults to retrying.
Sources[9] Structured output (LangChain documentation)[8] Models (LangChain documentation)
Diagram
How an agent picks the strategy
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 returns | Result | Reading |
|---|---|---|
{"category": "billing", "priority": 2} | a Ticket object | works |
priority 9 | ValidationError raised | the schema caught it |
same, with include_raw=True | dict with raw, parsing_error, parsed (None) | failure is inspectable |
{"category": "banana", "priority": 1} | a valid Ticket | valid 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.
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 sees | only order_id |
Caller context user u1, model asks for A-17 | the order |
Caller context user u9, same request | not found |
Model adds an extra user_id: "u2" argument | still scoped to u1’s data |
Unsafe version with user_id as a normal argument, model passes u2 | returns u2’s data |
Diagram
Why the user id stays out of the arguments
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.
| Shape | Control | Latency | Fits |
|---|---|---|---|
| Two-step | high | fast, predictable | FAQ and documentation bots |
| Agentic (retrieval as a tool) | low | variable | assistants with several tools |
| Hybrid (adds query rewriting and checks) | medium | variable | quality-sensitive domain Q&A |
- The framework provides plumbing. Good answers still depend on chunking, retrieval quality and evaluation, covered in the RAG module.
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.
| Design | Retrievals | Model calls | Why |
|---|---|---|---|
| Two-step | 100 | 100 | always retrieve, then answer |
| Agentic | 40 | 140 | 100 first calls, plus 40 more to answer after a retrieval |
- 100+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
| Option | Strength | Cost | Pick when |
|---|---|---|---|
| LangChain with LangGraph | portability, resumable runtime, approvals, streaming | a large API surface and release history to follow | multi-step, stateful agents on a team wanting one stack |
| Provider SDK and plain Python | transparent, few dependencies | you write retries, state and streaming yourself (LangSmith tracing can be added to either) | one model call, or maximum control |
| A workflow engine already in use | proven durable execution | not model-aware | reliability rules are strict and it is already run |
| Another agent framework or a vendor SDK | ergonomics for a style, or tight vendor integration | a different state model | a 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
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
langchain1.4.7 andlanggraph1.2.17 on 2026-10-24.
References
References & Sources (1 of 3)
LangChain overview (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langchain/overview
Used for What LangChain is, create_agent as a minimal configurable harness, agents built on LangGraph, Deep Agents and LangSmith as neighbours.
LangGraph overview (LangGraph documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langgraph/overview
Used for LangGraph as a low-level orchestration framework and runtime, and that LangChain is not required to use it.
Deep Agents overview (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/deepagents/overview
Used for Deep Agents features, and that it sits on LangChain's agent building blocks and the LangGraph runtime.
Observability (LangSmith documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/langsmith/observability
Used for LangSmith works with many frameworks and providers, with named examples.
LangChain v1 release notes (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/releases/langchain-v1
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)
Migrate to LangChain v1 (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/migrate/langchain-v1
Used for Legacy chain classes in langchain-classic and the Python 3.10 or higher requirement.
Versioning (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/versioning
Used for Breaking changes only in major releases, deprecation, LTS status of 1.0 and Deep Agents being pre-1.0 when read.
Models (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langchain/models
Used for Tool message call ids, max_concurrency for batch, the default of 6 retries and include_raw.
Structured output (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langchain/structured-output
Used for Provider and tool strategies, the structured_response key and handle_errors.
Tools (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langchain/tools
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)
Retrieval (LangChain documentation) (opens in a new tab)
LangChain2026Documentation
https://docs.langchain.com/oss/python/langchain/retrieval
Used for The retriever definition and the control and latency of two-step, agentic and hybrid retrieval.
Keys: ← → move, Home End first and last, F full screen.