By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Streaming and tracing are two views of the same run. Streaming is for the customer: show tokens as they arrive and show agent steps so a multi-second tool call does not look like a frozen screen. Tracing is for you: a complete record of what ran, with which arguments, what came back, how long it took, how many tokens it cost and where it failed.
from langchain.messages import HumanMessage
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
model = GenericFakeChatModel(
messages=iter(["Rain is likely in Mumbai this evening. Take an umbrella."])
)
for chunk in model.stream(
[HumanMessage("Will it rain in Mumbai this evening?")]
):
print(chunk.text, end="")
print()An agent streams at two levels. stream_mode='updates' yields one state update after each agent step, keyed by node name — that is your "looking up order…" progress. stream_mode='messages' yields token chunks with metadata, which is your typing effect. You can also emit your own progress events from tools with get_stream_writer and the custom mode. Recent LangGraph releases can wrap every chunk as {'type': ..., 'data': ...} with version='v2'; check the version you deploy rather than mixing the two shapes.
| Stream mode | What you receive | Use it for |
|---|---|---|
updates | A state update after each step, keyed by node | "Looking up order…" progress and a live trace |
messages | Token chunks plus metadata (node, model, run id) | Typing UI, reasoning display, token accounting |
custom | Arbitrary data your tools write | "Fetched 10 of 100 records" progress |
LangChain names its runs. In a create_agent run the graph nodes are model and tools, and every tool and agent you name shows up in the trace with that name. Name your own nodes and tools after the action they take, then log the fields that let you reconstruct a decision without replaying the model.
thread_id, run id, customer/account id, channel and timestamp.Never log API keys, full prompts containing personal data, or raw card-like numbers. Redact at the logging boundary, not at the call site, so a new call site cannot forget. Log a prompt template version and the variable values separately when you need prompt reproducibility without storing the whole transcript.
LangSmith is the batteries-included option: set LANGSMITH_TRACING=true, LANGSMITH_API_KEY and a LANGSMITH_PROJECT name in the environment, then run the agent normally. The trace shows each model and tool step with inputs, outputs, latency and token counts. Without LangSmith, wrap invoke or stream in your own structured logging with the same fields.
Key takeaways
Streaming is user-facing progress: tokens from the model, step updates from the agent.
stream_mode='updates' shows steps; stream_mode='messages' shows tokens; custom carries your own events.
Trace names come from nodes, tools and agents — name them after the action they take.
Log model, step, tool, token, approval and retrieval fields; redact personal data and secrets at the logging boundary.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.