Ch 1 — Tech Stack Under the Hood
Code-level internals: Runnable protocol, StateGraph, Pregel engine, event loops, tracing
Under the Hood
-
Click play or press Space to begin...
A
The Runnable Protocol
LangChain's universal interface
1
api
Runnable
Base class for
every component
.invoke()
play_arrow
.invoke()
Single input
single output
.stream()
stream
.stream()
Yields chunks
as they arrive
.batch()
dynamic_feed
.batch()
Parallel execution
of multiple inputs
2
arrow_downward
Runnables compose via the | pipe operator
B
RunnableSequence & Composition
How the | pipe operator works
edit_note
Prompt
Runnable that
formats messages
|
smart_toy
Model
Runnable that
calls the LLM
|
output
Parser
Runnable that
extracts output
=
link
RunnableSequence
Also a Runnable!
Recursive composition
3
arrow_downward
LangGraph: StateGraph definition
C
StateGraph Definition
Nodes, edges, and typed state
data_object
TypedDict State
Schema for the
graph's memory
used by
hub
add_node()
Register a
function as node
wired by
4
call_split
add_edge()
Static or
conditional routing
compiles
compiled
.compile()
Produces a
CompiledGraph
5
arrow_downward
Under the hood: the Pregel execution engine
D
Pregel Execution Engine
How CompiledGraph actually runs
inbox
Channels
State fields as
message channels
read
hub
Nodes Execute
Read channels,
run function
write
6
edit
State Update
Reducer merges
partial updates
check
route
Edge Check
Evaluate edges,
pick next node
7
arrow_downward
The execution loop and checkpointing
E
The Execution Loop
Read state → execute node → write state → repeat
visibility
Read State
Snapshot current
state from channels
run
psychology
Execute Node
LLM call happens
HERE inside node
save
8
save
Checkpoint
Persist state
for resumability
loop?
loop
Continue?
Conditional edge
decides: loop or end
9
arrow_downward
Chainlit: event wiring and callbacks
F
Chainlit Event Wiring
Decorators, messages, streaming callbacks
alternate_email
@cl.on_message
Decorator registers
message handler
creates
chat
cl.Message
Object with content,
author, elements
streams
stream
stream_token()
Pushes tokens
to browser via WS
shows
account_tree
cl.Step()
Nested steps for
tool calls, reasoning
10
arrow_downward
LangSmith: how tracing hooks into every Runnable
G
LangSmith Tracing Internals
Callbacks, runs, and trace structure
settings
Env Variable
LANGCHAIN_
TRACING_V2=true
activates
webhook
CallbackHandler
Wraps every
Runnable execution
emits
account_tree
Run Tree
Parent → child
run hierarchy
captures
analytics
Trace Data
Inputs, outputs,
latency, tokens, $