LangChainLangChain 1.4 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
46 small wins to finish your pathNext lesson →

Streaming steps with stream_mode

stream is an agent method that hands back each step as it happens, so you can watch what the agent is doing and see why it stopped, instead of waiting for the finished conversation from invoke.

Last updated: 27 Sep, 2026 · LangChain 1.4

Every agent from lesson 7 on can be watched this way, so it is worth learning before something goes wrong. The agent here is lesson 7's, without the system prompt.

The stream method

python
for step in agent.stream(inputs, stream_mode="updates"):   # one item per step
    print(step)                                            # {node_name: {"messages": [...]}}

Building a bare agent

Build a bare agent: one tool, one model, nothing wrapped around the call.

Exampleagent.py
from langchain.agents import create_agent
from shop_model import ShopModel
from tools import lookup_order

agent = create_agent(ShopModel(), tools=[lookup_order])

Streaming each step

Loop over stream with stream_mode="updates". Each item names the part of the agent that ran and the messages it added.

python
question = {"messages": [{"role": "user", "content": "Where is my order A17?"}]}

for step in agent.stream(question, stream_mode="updates"):
    for name, update in step.items():          # name is the part that ran
        for message in update["messages"]:     # the messages it added
            print(f"{name:<6} {message.type:<4} {message.text or message.tool_calls}")

The steps of one question

Streaming one question shows each step as the loop takes it.

Example
question = {"messages": [{"role": "user", "content": "Where is my order A17?"}]}

for step in agent.stream(question, stream_mode="updates"):
    for name, update in step.items():
        for message in update["messages"]:
            print(f"{name:<6} {message.type:<4} {message.text or message.tool_calls}")

For the finished conversation you can still call invoke and print every message.

Example
result = agent.invoke({"messages": [{"role": "user", "content": "Where are A17 and C40?"}]})

for message in result["messages"]:
    message.pretty_print()

What each step showed

  • With stream_mode="updates", each item is one step: the name of the part that ran and the messages it added.
  • model is a model call and tools is the tools running. Three steps for one question: ask, look up, answer.
  • Two orders in one question give two tool calls in one AI message, and two tool messages back.
  • pretty_print from lesson 2 shows the tool calls with their arguments and ids, which is often enough to see why an agent did what it did.

invoke vs stream

invokestream
ReturnsThe finished conversationOne item per step
You see stepsOnly at the endAs they happen
Use it toGet the final answerWatch and debug the loop

When to stream steps

  • Showing progress in a user interface while an agent works.
  • Debugging: seeing which tool ran, with what arguments, and where the loop stopped.
Watch out. stream_mode="updates" gives only what each step added, while stream_mode="values" gives the whole conversation so far at every step. Pick updates when you want the new message, values when you want the running total.
Try it yourself
  • Stream a question with no order in it and count the steps.
  • Stream with stream_mode="values" and print how many messages each item holds.
  • Stream a question about B22 and find the step where the tool says it has no such order.

This is what real progress feels like.