streamEvents with v2 schema doesn't seem to be working #48

Closed
opened 2026-02-15 17:14:59 -05:00 by yindo · 3 comments
Owner

Originally created by @lionkeng on GitHub (Jul 10, 2024).

Hello,
I implemented the streaming example and it works with v1 schema. But running the same script with v2 schema streaming stopped working. What has changed in v2 that would cause the following code snippet to not work? Thanks.

  let config = { configurable: { thread_id: 'conversation-num-1' } }
  let inputs = { messages: [['user', 'What is the weather in SF?']] }

  for await (const event of await graph.streamEvents(inputs, {
    ...config,
    streamMode: 'values',
    version: 'v2',
  })) {
    const eventName = event.event
    switch (eventName) {
      case 'on_llm_stream': {
        console.log('stream', eventName)
        let chunk: ChatGenerationChunk = event.data?.chunk
        let msg = 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)
        }
        break
      }
      case 'on_tool_start': {
        console.log('tool start', event.name)
        break
      }
      case 'on_tool_end': {
        console.log('tool end', event.data)
        break
      }
      default: {
        // console.log('event', eventName)
        break
      }
    }
  }

relevant snippet of my package.json

  "dependencies": {
    "@langchain/community": "^0.2.18",
    "@langchain/core": "^0.2.15",
    "@langchain/langgraph": "^0.0.26",
    "@langchain/openai": "^0.0.34",
    "langchain": "^0.2.9",
    "langsmith": "^0.1.36",
    "zod": "^3.23.8"
  }

Originally created by @lionkeng on GitHub (Jul 10, 2024). Hello, I implemented the streaming example and it works with v1 schema. But running the same script with v2 schema streaming stopped working. What has changed in v2 that would cause the following code snippet to not work? Thanks. ``` let config = { configurable: { thread_id: 'conversation-num-1' } } let inputs = { messages: [['user', 'What is the weather in SF?']] } for await (const event of await graph.streamEvents(inputs, { ...config, streamMode: 'values', version: 'v2', })) { const eventName = event.event switch (eventName) { case 'on_llm_stream': { console.log('stream', eventName) let chunk: ChatGenerationChunk = event.data?.chunk let msg = 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) } break } case 'on_tool_start': { console.log('tool start', event.name) break } case 'on_tool_end': { console.log('tool end', event.data) break } default: { // console.log('event', eventName) break } } } ``` relevant snippet of my package.json ``` "dependencies": { "@langchain/community": "^0.2.18", "@langchain/core": "^0.2.15", "@langchain/langgraph": "^0.0.26", "@langchain/openai": "^0.0.34", "langchain": "^0.2.9", "langsmith": "^0.1.36", "zod": "^3.23.8" } ```
yindo closed this issue 2026-02-15 17:14:59 -05:00
Author
Owner

@jacoblee93 commented on GitHub (Jul 10, 2024):

Hey @lionkeng, having a look now. Can you share a bit more about your graph's structure? Otherwise will try to repro with a basic implementation.

Also, do you have LANGCHAIN_CALLBACKS_BACKGROUND set to true?

@jacoblee93 commented on GitHub (Jul 10, 2024): Hey @lionkeng, having a look now. Can you share a bit more about your graph's structure? Otherwise will try to repro with a basic implementation. Also, do you have `LANGCHAIN_CALLBACKS_BACKGROUND` set to `true`?
Author
Owner

@jacoblee93 commented on GitHub (Jul 10, 2024):

Ah it's actually much simpler - we updated the events format in v2 to be more accurate/ergonomic. Please try the following:

    for await (const event of await reactAgent.streamEvents(inputs, {
      ...config,
      streamMode: 'values',
      version: 'v2',
    })) {
      const eventName = event.event
      console.log(event);
      switch (eventName) {
        case 'on_chat_model_stream': {
          console.log('stream', eventName)
          let chunk = event.data?.chunk
          let msg = chunk
          if (msg.tool_call_chunks && msg.tool_call_chunks.length > 0) {
            console.log(msg.tool_call_chunks)
          } else {
            console.log(msg.content)
          }
          break
        }
        case 'on_tool_start': {
          console.log('tool start', event.name)
          break
        }
        case 'on_tool_end': {
          console.log('tool end', event.data)
          break
        }
        default: {
          // console.log('event', eventName)
          break
        }
      }
    }

See here for details - will also update the main guide:

https://js.langchain.com/v0.2/docs/versions/v0_2/migrating_astream_events

@jacoblee93 commented on GitHub (Jul 10, 2024): Ah it's actually much simpler - we updated the events format in `v2` to be more accurate/ergonomic. Please try the following: ```ts for await (const event of await reactAgent.streamEvents(inputs, { ...config, streamMode: 'values', version: 'v2', })) { const eventName = event.event console.log(event); switch (eventName) { case 'on_chat_model_stream': { console.log('stream', eventName) let chunk = event.data?.chunk let msg = chunk if (msg.tool_call_chunks && msg.tool_call_chunks.length > 0) { console.log(msg.tool_call_chunks) } else { console.log(msg.content) } break } case 'on_tool_start': { console.log('tool start', event.name) break } case 'on_tool_end': { console.log('tool end', event.data) break } default: { // console.log('event', eventName) break } } } ``` See here for details - will also update the main guide: https://js.langchain.com/v0.2/docs/versions/v0_2/migrating_astream_events
Author
Owner

@lionkeng commented on GitHub (Jul 10, 2024):

@jacoblee93 thanks for the quick response and yes, that works!

@lionkeng commented on GitHub (Jul 10, 2024): @jacoblee93 thanks for the quick response and yes, that works!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#48