2.5

Stream modes at their source, and the v3 projection buffer

Read one v3 projection per message, or the raw events, because a loop that reads reasoning first showed a reasoning model's answer 8.8 to 9.0 s late.

You switch a chat UI to a reasoning model and to stream_events(version="v3"). The thinking streams live for half a minute. Then the answer appears in one block, after a pause as long as the answer itself. Your server log shows the model sent the answer token by token. The tokens were in the process all along, in a buffer you did not know you had.

When you finish this section, you can name the function that produces each stream mode and the moment in the superstep when it does. You can also explain issue langchain#38484 from the code, and write a v3 consumer that shows every token when it arrives.

One queue, seven modes, six producers

Every stream mode of stream() writes to one queue. The loop drains it between task completions, and the v2 format wraps each item as a StreamPart with type, ns, and data. We recorded the call stack at the moment each item went onto the queue:

ModeProducerWhen
checkpoints, debug_prepare_tasks_and_emit_checkpointat the start of the next superstep
taskstickwhen the tasks are planned, and again with each result
updatesput_writes, then output_writesas each task finishes
valuesafter_tickafter the update phase
messagesStreamMessagesHandler.on_llm_new_tokenfor each model token, by callback
customthe stream_writer closurewhen your code calls the writer

Two rows matter in practice. updates arrives per task, so a slow parallel task does not hold back the update of a fast one. values waits for the whole superstep. One create_agent run with every mode on, with Qwen3 4B on the x86 server guest, shows the order:

outputevery mode of one agent run, by timeFull log
     1894.5 ms  messages    AIMessageChunk chunk text='' node=model step=1
     1894.6 ms  messages    AIMessageChunk chunk text='' node=model step=1
     1894.6 ms  updates     keys=['model']
     1894.6 ms  tasks       result model
     1894.6 ms  debug       type=task_result step=1
     1895.5 ms  values      2 messages
     1895.5 ms  checkpoints step=1 next=['tools']
     1895.5 ms  debug       type=checkpoint step=1
     1895.5 ms  tasks       start tools
     1895.5 ms  debug       type=task step=2
     1899.6 ms  custom      {'progress': 'looking up Paris'}
     1899.6 ms  messages    ToolMessage chunk text='Paris: sunny' node=tools step=2
…
     2658.7 ms  messages    AIMessageChunk chunk text='The' node=model step=3
     2726.1 ms  messages    AIMessageChunk chunk text=' weather' node=model step=3
The end of the first model step, the tools step, and the start of the answer. The rest of the run is cut.

The first model step took 1.89 s and streamed no text, because its reply was a tool call. The tools step took 4.5 ms. The answer then streamed one token about every 67 ms. These times come from one run on a loaded guest, so read the order of the modes and not the times. Figure 2.7 places each mode on the phases of the run.

Fig. 2.7where each stream mode is produced in one agent runtimeline
Where each stream mode is produced in one agent run Seven rows, one per stream mode, on a time axis in milliseconds for one create_agent run with Qwen3 4B on the x86 server guest, all modes on and version v2. The axis has three zoomed spans with breaks: the start, the end of the first model step and the tools step around 1.9 s, and the answer from 2.6 s. The supersteps are model from 5 to 1895.5 ms, tools from 1895.5 to 1900 ms, model from 1900 to 3335.9 ms. Each tick is one item: tasks 6, messages 13, custom 1, updates 3, values 4, checkpoints 5, debug 11. messages, custom, and updates items appear while a task runs or as it finishes. A values item comes after the update phase. The checkpoints and debug items of a step appear at the start of the next superstep, together with the tasks start item. The answer tokens arrived from 2658.7 ms, about one every 67 ms. STREAM MODE start model ends tools model answers tasks 6 messages 13 custom 1 updates 3 values 4 checkpoints 5 debug 11 0 4 8 1894 1896 1898 1900 2600 2800 3000 3200 3400 ms 1 2 3 4 1 custom: the tool calls stream_writer at 1899.6 ms, inside the tools task 2 updates: the tools task finishes at 1899.6 ms, and its writes go out at once 3 values: after the update phase of the superstep, at 1900 ms 4 checkpoints: emitted when the next superstep plans, at 1900 ms
updates, messages, and custom are produced while tasks run, values after the update phase, and checkpoints only when the next superstep starts. The x axis is milliseconds from the start of one create_agent run, in three zoomed spans with breaks between them. Each row is one stream mode, and each tick is one item. The shaded band is the tools superstep, the labels above name the model steps, and the numbers follow the notes under the axis.

The v3 stream is pulled by the reader

stream_events(version="v3") runs no background thread. It runs the graph only when the reader asks for more. A projection such as message.text keeps a list of deltas and a cursor. When the cursor reaches the end of the list, the iterator calls _request_more, which runs the graph until a new event arrives. The iterator stops when the projection is marked done.

Each pulled event goes to every projection of its message. A text delta goes to the list of message.text, even when nobody reads that list yet.

The cause of langchain#38484

Issue langchain#38484 reports that a v3 consumer gets the final answer in one burst. Section 5.1 reproduced it. The code shows why.

All three projections of a message are marked done in one place, when the whole message finishes. The end of the reasoning block finalizes that block, and it does not complete message.reasoning. So this loop cannot leave its first for until the last text token has arrived:

pythonthe three consumer loops of the captureFull log
    for message in stream.messages:
        if pattern == "reasoning_then_text":
            for d in message.reasoning:
                got.append((now(), "reasoning", d))
            for d in message.text:
                got.append((now(), "text", d))
        elif pattern == "text_only":
            for d in message.text:
                got.append((now(), "text", d))
        elif pattern == "raw_events":
            for ev in message:
                if ev.get("event") == "content-block-delta":
                    delta = ev.get("delta", {})
                    kind = "reasoning" if delta.get("type") == "reasoning-delta" else "text"
                    got.append((now(), kind, delta.get("reasoning") or delta.get("text")))

While the reasoning loop waits, it pulls the text deltas into the list of message.text. When the message ends, the second loop finds all of them there.

We measured the three loops on the x86 server guest with Qwen3 8B, reasoning on, through create_agent, 5 runs per loop, the loops interleaved. The send time is when the Ollama HTTP stream gave LangChain the part. Each run had 211 reasoning deltas and then 60 text deltas: Raw runs

outputrun 0 of each loopFull log
  run 0 reasoning_then_text  emitted r/t=211/60 received r/t=211/60 text emit [31688.1, 40330.7] spread 8642.6 ms; text receive [40474.7, 40474.8] spread 0.1 ms; text lag median/max [4635.1, 8786.6]; reasoning lag median/max [0.7, 7.0]
  run 0 text_only            emitted r/t=211/60 received r/t=0/60 text emit [32307.5, 41001.4] spread 8693.9 ms; text receive [32308.2, 41002.2] spread 8694.0 ms; text lag median/max [0.7, 4.6]; reasoning lag median/max None
  run 0 raw_events           emitted r/t=211/60 received r/t=211/60 text emit [32819.0, 42027.1] spread 9208.1 ms; text receive [32819.8, 42027.8] spread 9208.0 ms; text lag median/max [0.7, 0.9]; reasoning lag median/max [0.7, 4.0]

In 5 of 5 runs, the loop that read reasoning first got all 60 text deltas within 0.1 ms of each other. The model had sent them over 8.6 to 8.9 s. This is one run on a loaded guest, so read it as an order. The Mac rows in section 5.1 give the lag as 4.0 to 8.5 s.

Its reasoning deltas arrived live. The text-only loop got the text with a median lag of 0.7 ms and a maximum of 4.9 ms over 300 deltas. The raw loop got them with a median of 0.7 ms and a maximum of 0.9 ms. Figure 2.8 puts run 0 of each loop on one axis.

Fig. 2.8text deltas sent and received under three v3 consumer loopstimeline
Text deltas sent and received under three v3 consumer loops Three pairs of rows on a time axis in seconds, run 0 of five per consumer loop over stream_events version v3 of one create_agent run. The model is Qwen3 8B with reasoning on, on Ollama on the x86 server guest. It sent about 211 reasoning deltas from the first second to about 31.3 s, then 60 text deltas over about 8.6 s. The upper row of each pair marks when each text delta was sent, and the lower row when the loop got it. The text-only and raw-events loops got each delta within a few milliseconds; over all five runs their largest lags were 4.9 and 0.9 ms. The loop that reads message.reasoning first got all 60 text deltas at 40.5 s, up to 8786.6 ms after the send. Over five runs its first text delta was 8786.6 to 9036.1 ms late. CONSUMER LOOP text only sent got largest lag 4.6 ms in this run raw events sent got largest lag 0.9 ms in this run reasoning, then text sent got all 60 deltas wait in the message.text list, up to 8.8 s 30 32 34 36 38 40 42 s reasoning streamed live before 31.3 s and is not drawn first text delta late by 8.79 to 9.04 s in 5 of 5 runs
The loop that reads reasoning first gets all 60 text deltas at once, 8.8 s after the first send, and the other loops get each within 5 ms. Each pair of rows is one loop, run 0 of five. Olive ticks are sends by the model, and the lower ticks are the moments the loop got a delta. The rose band is the span in which the text waited. The reasoning ran before the shown span.

A closed pull request for the issue, #38533, passed the run config to model_.invoke in create_agent. That change does not touch this mechanism. In the same agent, the text-only and raw loops already got every delta live, so the model callbacks reach the stream without it.

The consumer to write

Pick one of two shapes. When you show only the answer, read message.text alone. When you show reasoning and answer, read the raw events of each message and switch on the delta type, as the raw_events branch above does. Each delta then reaches your UI in the order the model sent it.

Do not read two projections of one message one after the other. The rule holds for message.tool_calls too, which section 5.1 measured. A projection that you read second always waits for the end of the message.

LangChain (Python): langchain, langchain-core, langgraph, deepagents, langsmith 1.5.0 · c2f4036 · 2026-11-11 · Edition 2026.11