streamEvents - How can I only stream the last node in the graph? #62

Closed
opened 2026-02-15 17:15:16 -05:00 by yindo · 2 comments
Owner

Originally created by @justinlevi on GitHub (Aug 15, 2024).

I have a simple rag graph and the first node is a rewrite query node. the last node is my generation node. I only want to stream content from the last node in the graph. How can I do that?

const eventStream = await this.agentGraph
.createGraph()
.streamEvents(inputs, config );

for await (const { event, data } of eventStream) {
  if (event === 'on_chat_model_stream') {
    await this.handleChatModelStream(data, res, model, metrics);
    if (typeof data.chunk.content === 'string') {
      result += data.chunk.content;
    }
  }
}


I could create a state variable for "currentNode" but I'm thinking there must be a better way?
Originally created by @justinlevi on GitHub (Aug 15, 2024). I have a simple rag graph and the first node is a rewrite query node. the last node is my generation node. I only want to stream content from the last node in the graph. How can I do that? const eventStream = await this.agentGraph .createGraph() .streamEvents(inputs, config ); for await (const { event, data } of eventStream) { if (event === 'on_chat_model_stream') { await this.handleChatModelStream(data, res, model, metrics); if (typeof data.chunk.content === 'string') { result += data.chunk.content; } } } I could create a state variable for "currentNode" but I'm thinking there must be a better way?
yindo closed this issue 2026-02-15 17:15:16 -05:00
Author
Owner

@hinthornw commented on GitHub (Aug 15, 2024):

I believe the event will have metadata containing infromation about the node that it's within, but otherwise/ in general I use tagging pretty often to narrow down the events I'll actually publish.

A python example we did is here: https://langchain-ai.github.io/langgraph/how-tos/streaming-from-final-node/#stream-outputs-from-the-final-node

@hinthornw commented on GitHub (Aug 15, 2024): I believe the event will have metadata containing infromation about the node that it's within, but otherwise/ in general I use tagging pretty often to narrow down the events I'll actually publish. A python example we did is here: https://langchain-ai.github.io/langgraph/how-tos/streaming-from-final-node/#stream-outputs-from-the-final-node
Author
Owner

@justinlevi commented on GitHub (Aug 15, 2024):

Huge help. thank you.

@justinlevi commented on GitHub (Aug 15, 2024): Huge help. thank you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#62