Skip to content

Fixed bug HuggingFacePipeline lacks#35095

Closed
Nitin75408 wants to merge 3 commits intolangchain-ai:masterfrom
Nitin75408:Fixes/34134
Closed

Fixed bug HuggingFacePipeline lacks#35095
Nitin75408 wants to merge 3 commits intolangchain-ai:masterfrom
Nitin75408:Fixes/34134

Conversation

@Nitin75408
Copy link

  1. PR title: fix(core,huggingface): add async streaming capability contract to prevent AttributeError

  2. PR description:

Summary

Previously, ChatHuggingFace._astream would attempt to access async_client on HuggingFacePipeline instances, causing AttributeError since HuggingFacePipeline uses synchronous transformers pipelines and doesn't have an async_client attribute. This fix introduces an explicit capability declaration system where providers must declare their async streaming support, and the code checks this capability before attempting async operations.

Changes

Core Layer (langchain_core)

  • Added supports_async_streaming() method to BaseChatModel and BaseLLM as a capability contract
  • Default implementation checks if _astream is overridden from base class
  • Updated BaseChatModel._astream documentation to clarify fallback behavior

HuggingFace Provider Layer

  • HuggingFacePipeline: Explicitly declares supports_async_streaming() returns False
  • HuggingFaceEndpoint: Explicitly declares supports_async_streaming() returns True
  • ChatHuggingFace: Overrides supports_async_streaming() to check underlying LLM capability
  • ChatHuggingFace._astream: Now checks capability before accessing async_client, preventing AttributeError

Testing

  • Added comprehensive unit tests verifying capability declarations for all LLM types
  • Added tests verifying capability checks prevent AttributeError
  • Added tests verifying correct fallback behavior for unsupported async streaming

Architecture Benefits

This architectural approach provides several benefits:

  1. Prevents runtime errors by checking capabilities before accessing provider-specific attributes
  2. Makes capabilities explicit and discoverable through the API
  3. Guides future provider implementations to declare their capabilities
  4. Maintains backward compatibility with existing code
  5. Separates concerns cleanly between core contract definition and provider implementation

Fixes #34134

Verification

All tests pass locally. The fix was verified by:

  1. Running unit tests for ChatHuggingFace with HuggingFacePipeline - no AttributeError occurs
  2. Verifying HuggingFaceEndpoint still uses async_client correctly when capability is True
  3. Confirming fallback to synchronous streaming works correctly for unsupported providers
  4. Running full test suite to ensure no regressions

AI Assistance Disclaimer

This contribution was developed with assistance from AI coding tools. The architectural approach, implementation details, and test cases were reviewed and refined to ensure they follow LangChain patterns and best practices.

@github-actions github-actions bot added integration PR made that is related to a provider partner package integration core `langchain-core` package issues & PRs huggingface `langchain-huggingface` package issues & PRs external labels Feb 9, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 9, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 13 untouched benchmarks
⏩ 21 skipped benchmarks1


Comparing Nitin75408:Fixes/34134 (83ce846) with master (f0a808d)

Open in CodSpeed

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Nitin75408 Nitin75408 marked this pull request as draft February 10, 2026 17:42
@mdrxy mdrxy closed this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external huggingface `langchain-huggingface` package issues & PRs integration PR made that is related to a provider partner package integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HuggingFacePipeline lacks async_client when used with LangGraph Studio

2 participants