Streaming message chunks from nodes #33

Closed
opened 2026-02-15 17:05:56 -05:00 by yindo · 1 comment
Owner

Originally created by @claritise on GitHub (Jun 3, 2024).

Currently it is possible to stream results from graphs per node, but is it possible to stream message chunks from LLM invocations per node as well? Currently UX is not great having to wait for invocations to finish entirely before message could be display to user.

Originally created by @claritise on GitHub (Jun 3, 2024). Currently it is possible to stream results from graphs per node, but is it possible to stream message chunks from LLM invocations per node as well? Currently UX is not great having to wait for invocations to finish entirely before message could be display to user.
yindo closed this issue 2026-02-15 17:05:57 -05:00
Author
Owner

@nfcampos commented on GitHub (Jun 3, 2024):

hi,

You can use astream_events for this purpose, eg.

for await (
  const event of await graph.streamEvents(
    { messages: [["user", "What's the weather like today?"]] },
    { streamMode: "values", version: "v1" },
  )
) {
  if (event.event === "on_llm_stream") {
    const msg = event.data?.chunk.message as AIMessageChunk;
    if (msg.tool_call_chunks && msg.tool_call_chunks.length > 0) {
      console.log(msg.tool_call_chunks);
    } else {
      console.log(msg.content);
    }
  }
}

See longer example here https://github.com/langchain-ai/langgraphjs/blob/main/examples/how-tos/stream-tokens.ipynb

@nfcampos commented on GitHub (Jun 3, 2024): hi, You can use `astream_events` for this purpose, eg. ```js for await ( const event of await graph.streamEvents( { messages: [["user", "What's the weather like today?"]] }, { streamMode: "values", version: "v1" }, ) ) { if (event.event === "on_llm_stream") { const msg = event.data?.chunk.message as AIMessageChunk; if (msg.tool_call_chunks && msg.tool_call_chunks.length > 0) { console.log(msg.tool_call_chunks); } else { console.log(msg.content); } } } ``` See longer example here https://github.com/langchain-ai/langgraphjs/blob/main/examples/how-tos/stream-tokens.ipynb
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#33