Where to add config to streamEvents? #61

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

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

Maybe a stupid question, but I can't find it in the docs.

If I want to add a thread_id to a final response of a graph (specific node), how to add this thread id as config?

let config = {
    configurable: {
      thread_id: "1",
    }
const eventStream = await graph.streamEvents(
  { messages: [["user", "What's the capital of Nepal?"]] },
  { version: "v2" },
  { includeNames: ["Summarizer"] }
);

And why do you need to use version v1 or v2?

Originally created by @guidorietbroek on GitHub (Aug 15, 2024). Maybe a stupid question, but I can't find it in the docs. If I want to add a thread_id to a final response of a graph (specific node), how to add this thread id as config? ``` let config = { configurable: { thread_id: "1", } ``` ``` const eventStream = await graph.streamEvents( { messages: [["user", "What's the capital of Nepal?"]] }, { version: "v2" }, { includeNames: ["Summarizer"] } ); ``` And why do you need to use version v1 or v2?
yindo closed this issue 2026-02-15 17:15:16 -05:00
Author
Owner

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

In the second positional location (where version is passed)

Here's the ref doc for streamEvents. options extends RunnableConfig, which contains the configuration values you're looking for. It also contains info about the differences between the versions.

We version the endpoints explicitly since streamEvents returns all the sub-events. Streaming is critical for any application, and we plan to make some improvements to tracing in the future that might influence some of the characteristics of those events. Things that would influence these characteristics would be scoped to a new version.

@hinthornw commented on GitHub (Aug 15, 2024): In the second positional location (where version is passed) Here's the [ref doc](https://v02.api.js.langchain.com/classes/_langchain_core.runnables.Runnable.html#streamEvents) for streamEvents. options extends RunnableConfig, which contains the configuration values you're looking for. It also contains info about the differences between the versions. We version the endpoints explicitly since streamEvents returns *all* the sub-events. Streaming is critical for any application, and we plan to make some improvements to tracing in the future that might influence some of the characteristics of those events. Things that would influence these characteristics would be scoped to a new version.
Author
Owner

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

Perhaps somewhat related, but how would I limit only the last node to stream to a response client?

If I have several nodes and each node invokes a chain, currently I'm seeing on_chat_model_stream events for all chains and I only want to forward on chunks from the last generation node.

@justinlevi commented on GitHub (Aug 15, 2024): Perhaps somewhat related, but how would I limit only the last node to stream to a response client? If I have several nodes and each node invokes a chain, currently I'm seeing on_chat_model_stream events for all chains and I only want to forward on chunks from the last generation node.
Author
Owner

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

Thanks @hinthornw

Can you just confirm this is how it is supposed to work?

const eventStream = await graph.streamEvents(
  { messages: [["user", "What's the capital of Nepal?"]] },
  { version: "v2", ...config },
  { includeNames: ["Summarizer"] }
);

@justinlevi see this js example for your answer: https://langchain-ai.github.io/langgraphjs/how-tos/stream-tokens/#other-graphs

@guidorietbroek commented on GitHub (Aug 15, 2024): Thanks @hinthornw Can you just confirm this is how it is supposed to work? ``` const eventStream = await graph.streamEvents( { messages: [["user", "What's the capital of Nepal?"]] }, { version: "v2", ...config }, { includeNames: ["Summarizer"] } ); ``` @justinlevi see this js example for your answer: https://langchain-ai.github.io/langgraphjs/how-tos/stream-tokens/#other-graphs
Author
Owner

@guidorietbroek commented on GitHub (Aug 16, 2024):

So the confusing was caused by the fact that I get an error when using Claude in my LangGraph in combination with streamEvents. When changing to GPT4o the streaming is working.

This is the error I get:

An error occurred: Error: No parseable tool calls provided to AnthropicToolsOutputParser.

I am using a Zod schema with the structuredoutput:

const securitySchema = z.object({
        securityCheck: z.enum(["safe", "unsafe"])
        .describe("Response if an incoming user input is safe to handle or not. "),
    });

    // const model = new ChatAnthropic({
    //     temperature: 0,
    //     apiKey: process.env.ANTHROPIC_API_KEY,
    //     model: "claude-3-haiku-20240307",
    // })

    const model = new ChatOpenAI({
        temperature: 0,
        apiKey: process.env.OPENAI_API_KEY,
        model: "gpt-4o-2024-05-13",
    })

const structuredModel = model.withStructuredOutput(securitySchema, {name: "securitySchema"});

Is this a bug?

@guidorietbroek commented on GitHub (Aug 16, 2024): So the confusing was caused by the fact that I get an error when using Claude in my LangGraph in combination with streamEvents. When changing to GPT4o the streaming is working. This is the error I get: `An error occurred: Error: No parseable tool calls provided to AnthropicToolsOutputParser.` I am using a Zod schema with the structuredoutput: ``` const securitySchema = z.object({ securityCheck: z.enum(["safe", "unsafe"]) .describe("Response if an incoming user input is safe to handle or not. "), }); // const model = new ChatAnthropic({ // temperature: 0, // apiKey: process.env.ANTHROPIC_API_KEY, // model: "claude-3-haiku-20240307", // }) const model = new ChatOpenAI({ temperature: 0, apiKey: process.env.OPENAI_API_KEY, model: "gpt-4o-2024-05-13", }) const structuredModel = model.withStructuredOutput(securitySchema, {name: "securitySchema"}); ``` Is this a bug?
Author
Owner

@hwchase17 commented on GitHub (Aug 16, 2024):

do you have a langsmith trace to share?

@hwchase17 commented on GitHub (Aug 16, 2024): do you have a langsmith trace to share?
Author
Owner

@guidorietbroek commented on GitHub (Aug 16, 2024):

@hwchase17 Sure!

https://smith.langchain.com/public/96a53a9c-a47a-4f46-8558-e5ec23d31307/r

@guidorietbroek commented on GitHub (Aug 16, 2024): @hwchase17 Sure! https://smith.langchain.com/public/96a53a9c-a47a-4f46-8558-e5ec23d31307/r
Author
Owner

@dqbd commented on GitHub (Jul 7, 2025):

Seems to be fixed in latest @langchain/anthropic, closing

@dqbd commented on GitHub (Jul 7, 2025): Seems to be fixed in latest `@langchain/anthropic`, closing
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#61