Skip to content

Conversation

ninjudd
Copy link
Contributor

@ninjudd ninjudd commented Jul 28, 2025

  • Fix ChatOpenAI._streamResponseChunks to pass runManager to responses._streamResponseChunks
  • Fix ChatOpenAIResponses._streamResponseChunks to accept and use runManager parameter
  • Add handleLLMEnd event emission for non-streaming responses
  • Add regression test to verify handleLLMNewToken events are emitted
  • Resolves token-by-token streaming issue when useResponsesApi=true is enabled

Fixes #8577

- Fix ChatOpenAI._streamResponseChunks to pass runManager to responses._streamResponseChunks
- Fix ChatOpenAIResponses._streamResponseChunks to accept and use runManager parameter
- Add handleLLMEnd event emission for non-streaming responses
- Add regression test to verify handleLLMNewToken events are emitted
- Resolves token-by-token streaming issue when useResponsesApi=true is enabled
Copy link

vercel bot commented Jul 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Aug 4, 2025 7:48am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Aug 4, 2025 7:48am

@ninjudd
Copy link
Contributor Author

ninjudd commented Jul 28, 2025

I believe this PR also fixes #8283

Copy link
Member

@hntrl hntrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch @ninjudd! I don't believe this is something that was ever supported. The writeup + PR is very much appreciated ❤️

One note I had about handleLLMEnd, and I don't think the params being passed to handleLLMNewToken are exactly accurate. I'll pick up on this tomorrow since I think it's a little tricker then what is initially let on.

Comment on lines 1543 to 1550

// Emit handleLLMEnd event for non-streaming responses
await runManager?.handleLLMEnd({
generations: [result.generations],
llmOutput: result.llmOutput,
});

return result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is necessary? This gets handled upstream from the base chat model (if it doesn't it should, I'll take a look)

https://github.com/ninjudd/langchainjs/blob/fa9f31a90212a7ed41f998e89a59099e971b3981/langchain-core/src/language_models/chat_models.ts#L479-L482

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you may be right! Given that everything but streaming works without this PR, emitting handleLLMEnd here is probably not necessary. I can update the PR to remove this if you agree.

@hntrl hntrl linked an issue Aug 4, 2025 that may be closed by this pull request
5 tasks
@hntrl hntrl merged commit cc4ff80 into langchain-ai:main Aug 4, 2025
31 of 32 checks passed
@ninjudd
Copy link
Contributor Author

ninjudd commented Aug 4, 2025

Thanks @hntrl! Any idea when the next release will go out?

Also, where do I track that? Looks like the last tagged release on Github was June 19.

@hntrl
Copy link
Member

hntrl commented Aug 7, 2025

Hey @ninjudd! Apologies for the delay! We haven't dont a good job of posting our releases as of late. This was published under @langchain/openai==0.6.4

hntrl added a commit that referenced this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streaming Does not Work with OpenAI Responses API Unable to stream output when using OpenAI's Responses API to call the web_search tool

2 participants