-
Notifications
You must be signed in to change notification settings - Fork 16
Add LangChain 1.x support #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LangChain 1.x support #75
Conversation
Additional Test EvidenceUnit Test Output (LangChain 1.1.0)Integration Test Output (Real OCI Inference)test_langchain_compatibility.pytest_chat_features.pytest_multi_model.pyBackwards Compatibility Test (LangChain 0.3.x)Test Environment
|
Review Request (Active Contributors)@YouNeedCryDear @paxiaatucsdedu @furqan-shaikh-dev - Would appreciate your review on this LangChain 1.x upgrade PR. |
|
#66 |
|
Thanks for the pointer @YouNeedCryDear! I reviewed PR #66 by @joseph-klein. Comparison: PR #75 vs PR #66
Key DifferencesPR #75 (this PR) - Laser-Focused Upgrade:
PR #66 - Combined Upgrade + Refactoring:
My RecommendationI believe smaller, focused PRs are easier to review and safer to merge. This PR (#75) intentionally does the minimum required for LangChain 1.x compatibility without bundling unrelated changes. If there are legitimate bug fixes in PR #66 (like the escaped JSON parsing), those could be submitted as a separate PR to keep concerns separated. @joseph-klein - Happy to collaborate! If you have specific fixes that should be included, we could coordinate. My goal was to keep this upgrade as low-risk as possible with extensive test coverage to validate nothing broke. |
|
HI, we should give an higher priority to reviewing and approving this PR. Customers DON'T want to stay on old Langchain releases. @YouNeedCryDear could you have a closer look? Thanks |
- Python 3.10+ required (dropped Python 3.9 support) - Requires langchain-core>=1.0.0,<2.0.0 - Requires langchain>=1.0.0,<2.0.0 - Requires langchain-openai>=1.0.0,<2.0.0 | Test Suite | Passed | Total | |------------|--------|-------| | Unit Tests | 35 | 35 | | Integration Tests | 66 | 67 | | **Total** | **101** | **102** | ``` langchain==1.1.0 langchain-core==1.1.0 langchain-openai==1.1.0 ``` - Unit tests: 35/35 passed (100%) - Integration tests: 66/67 passed (98.5%) ``` langchain==0.3.27 langchain-core==0.3.80 langchain-openai==0.3.35 ``` - Unit tests: 35/35 passed (100%) - Verified backwards compatibility works 1. **test_langchain_compatibility.py** (17 tests) - Basic invoke, streaming, async - Tool calling (single, multiple) - Structured output (function calling, JSON mode) - Response format tests - LangChain 1.x specific API tests 2. **test_chat_features.py** (16 tests) - LCEL chain tests (simple, with history, batch) - Async chain invocation - Streaming through chains - Tool calling in chain context - Structured output extraction - Model configuration tests - Conversation pattern tests 3. **test_multi_model.py** (33 tests) - Meta Llama models (4-scout, 4-maverick, 3.3-70b, 3.1-70b) - xAI Grok models (grok-3-70b, grok-3-mini-8b, grok-4-fast) - OpenAI models (gpt-oss-20b, gpt-oss-120b) - Cross-model consistency tests - Streaming tests across vendors | Model | Basic | Streaming | Tool Calling | Structured Output | |-------|-------|-----------|--------------|-------------------| | meta.llama-4-scout-17b-16e-instruct | ✅ | ✅ | ✅ | ✅ | | meta.llama-4-maverick-17b-128e-instruct-fp8 | ✅ | ✅ | ✅ | ✅ | | meta.llama-3.3-70b-instruct | ✅ | ✅ | ✅ | ✅ | | meta.llama-3.1-70b-instruct | ✅ | ✅ | ✅ | ✅ | | Model | Basic | Streaming | Tool Calling | Structured Output | |-------|-------|-----------|--------------|-------------------| | xai.grok-3-70b | ✅ | ✅ | ✅ | ✅ | | xai.grok-3-mini-8b | ✅ | ✅ | ✅ | ✅ | | xai.grok-4-fast-non-reasoning | ✅ | ✅ | ✅ | ✅ | | Model | Basic | Streaming | Tool Calling | Structured Output | |-------|-------|-----------|--------------|-------------------| | openai.gpt-oss-20b | ✅ | ✅ | ✅ | ✅ | | openai.gpt-oss-120b | ✅ | ✅ | ✅ | ✅ | - pyproject.toml: Updated dependencies to LangChain 1.x - test_tool_calling.py: Fixed import (langchain.tools -> langchain_core.tools) - test_oci_data_science.py: Updated stream chunk count assertion for LangChain 1.x
- Update pytest to ^8.0.0 (required by pytest-httpx) - Update pytest-httpx to >=0.30.0 (compatible with httpx 0.28.1) - Update langgraph to ^1.0.0 (required by langchain 1.x) - Regenerate poetry.lock
- Remove main() functions with print statements - Fix import sorting issues - Remove unused imports - Fix line length violations - Format code with ruff
langchain-core 1.1.0 introduced ModelProfileRegistry which is required by langchain-tests 1.0.0. Update minimum version constraint to ensure CI resolves to a compatible version.
- Update bind_tools signature to match BaseChatModel (AIMessage return, tool_choice parameter) - Add isinstance checks for content type in integration tests - Remove unused type: ignore comments - Add proper type annotations for message lists - Import AIMessage in oci_data_science.py
This commit adds integration tests that verify LangChain 1.x compatibility with OpenAI models (openai.gpt-oss-20b and openai.gpt-oss-120b) available on OCI Generative AI service. Tests cover: - Basic completion with both 20B and 120B models - System message handling - Streaming support - Multi-round conversations - LangChain 1.x specific compatibility (AIMessage structure, metadata) All tests verified passing on rebased branch with latest changes from main.
Rebase Completed SuccessfullyThis PR has been rebased onto Changes During RebaseResolved Conflicts:
Commits Included:
Verification & TestingAdded comprehensive integration tests for OpenAI models to verify the rebased code works correctly: New Test File: Test Coverage:
Test Results: All 7 tests passing Ready for ReviewThe rebased branch is now:
Branch is ready for final review and merge. |
a9ba60d to
42c2358
Compare
New Integration Test Added:
|
- Fix line length in test_openai_models.py - Remove unresolved merge conflict markers in test_oci_data_science.py
|
Re: The use of
Since we're requiring Python >=3.10, using the lowercase The signature accepts any class type (not just BaseModel subclasses) - the function accepts |
1db2433 to
0c30c3e
Compare
Update dependency ranges to support both LangChain 0.3.x and 1.x: - langchain-core: >=0.3.78,<2.0.0 (was >=1.1.0,<2.0.0) - langchain: >=0.3.20,<2.0.0 (was >=1.0.0,<2.0.0) - langchain-openai: >=0.3.35,<2.0.0 (was >=1.0.0,<2.0.0) - langgraph: >=0.2.0,<2.0.0 (was ^1.0.0) - langchain-tests: >=0.3.12,<2.0.0 (was ^1.0.0) Verified compatibility: - All 63 unit tests pass with langchain-core 0.3.80 - All 63 unit tests pass with langchain-core 1.1.0
In LangChain 0.3.x, .text is a method (callable), while in 1.x it's a property. Update the test to handle both cases by checking if .text is callable and calling it if necessary. Verified: - Test passes with LangChain 0.3.80 - Test passes with LangChain 1.1.0
JSON mode requests with OpenAI models on OCI currently return 500 Internal Server Error from the OCI API. Skip these tests for OpenAI models until this can be investigated further (may be model limitation or OCI API issue). Tests affected: - test_structured_output_json_mode - test_response_format_json_object These tests pass successfully with Meta Llama models.
Add type ignore comments to resolve mypy errors where super().bind() returns Runnable[..., BaseMessage] but chat models narrow to AIMessage. These are safe ignores - the runtime types are correct.
8706bf8 to
4185b91
Compare
- Update requires-python to >=3.9 (was >=3.10) - Regenerate poetry.lock to include Python 3.9 compatible versions - Poetry will automatically select: - LangChain 0.3.x for Python 3.9 - LangChain 1.x for Python 3.10+
Summary of ChangesThis PR adds LangChain 1.x support while maintaining full backward compatibility with existing users. Solution: Python-Version-Conditional DependenciesInstead of forcing all users to upgrade, this PR uses Python version markers to provide the appropriate LangChain version:
ImplementationModified dependencies = [
"langchain-core>=0.3.78,<1.0.0; python_version < '3.10'",
"langchain-core>=1.1.0,<2.0.0; python_version >= '3.10'",
"langchain>=0.3.20,<1.0.0; python_version < '3.10'",
"langchain>=1.0.0,<2.0.0; python_version >= '3.10'",
"langchain-openai>=0.3.35,<1.0.0; python_version < '3.10'",
"langchain-openai>=1.1.0,<2.0.0; python_version >= '3.10'",
]Regenerated Tests PerformedLocal Testing (Python 3.14 with LangChain 1.x)
Cross-Version Compatibility Testing
CI Testing Strategy
Backward Compatibility GuaranteesNo Breaking Changes
Upgrade PathUsers can upgrade to LangChain 1.x by:
No code changes required! Technical Challenges AddressedType CompatibilityLangChain versions have different type signatures:
Solution: Added Python 3.9 Syntax Compatibility
Files Modified
Benefits
|
The script now evaluates python_version markers in dependencies and only extracts minimum versions for packages applicable to the current Python version. This ensures: - Python 3.9 CI jobs use LangChain 0.3.x minimums - Python 3.10+ CI jobs use LangChain 1.x minimums This prevents incompatible package combinations like langchain-core 0.3.78 with langchain-openai 1.1.0 (which requires langchain-core >= 1.1.0).
Isn't |
Explains that the 'type' annotation matches LangChain's BaseChatModel API and that runtime validation occurs in convert_to_openai_tool().
|
@YouNeedCryDear Thank you for raising this concern. You're right that EvidenceLangChain Core's official signature: BaseChatModel.bind_tools(
tools: Sequence[typing.Dict[str, Any] | type | Callable | BaseTool]
)LangChain OpenAI's signature: ChatOpenAI.bind_tools(
tools: Sequence[dict[str, Any] | type | Callable | BaseTool]
)Our implementation matches exactly: ChatOCIGenAI.bind_tools(
tools: Sequence[Union[Dict[str, Any], type, Callable, BaseTool]]
)Why LangChain Uses Broad
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should go inside integration test isnt' it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will move it shortly
Addresses PR review feedback - test file should be in libs/oci/tests/integration_tests/chat_models/ not in repo root. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Note: test_openai_model.py was moved to integration tests directory but not modified. It's a quick test script that has linting issues (unsorted imports, print statements). Can address those in a follow-up if needed. |
We probably need to resolve the linting or remove it from the test directory. The PR can not be merged without CI success @fede-kamel |
- Add pytest fixtures and decorators - Replace print statements with assertions - Fix imports and formatting - Handle edge case where max_completion_tokens may cause empty response - All 3 tests pass (test_basic_completion, test_system_message, test_streaming)
|
@YouNeedCryDear You're absolutely right! I've converted test_openai_model.py to proper pytest format. All linting issues are resolved and the 3 tests pass. Thanks for catching that! |
|
@YouNeedCryDear shall we? |
| strategy: | ||
| matrix: | ||
| python-version: | ||
| - "3.9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description indicates that Python 3.10+ required. Why keep this python-version: - "3.9"? @fede-kamel
| parallel_tool_calls: Optional[bool] = None, | ||
| **kwargs: Any, | ||
| ) -> Runnable[LanguageModelInput, BaseMessage]: | ||
| ) -> Runnable[LanguageModelInput, AIMessage]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I ask why use AIMessage instead of BaseMessage? It seems to introduce many type errors? Is it possible to resolve these type errors instead of ignore them? @fede-kamel
libs/oci/pyproject.toml
Outdated
| warn_unreachable = true | ||
| warn_unused_configs = true | ||
| warn_unused_ignores = true | ||
| warn_unused_ignores = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this to false? Can we keep the original settings? We use the same mypy settings as https://github.com/langchain-ai/langchain-google/blob/main/libs/vertexai/pyproject.toml @fede-kamel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine test_openai_models.py and test_openai_model.py into one file? @fede-kamel
- Fix mypy settings: revert warn_unused_ignores to true (match langchain-google standards) - Remove unnecessary type: ignore comments (4 total across oci_generative_ai.py and oci_data_science.py) - Remove duplicate test file test_openai_model.py (consolidated into test_openai_models.py) - Update PR description to clarify Python 3.9 backwards compatibility via conditional dependencies
|
@paxiaatucsdedu Thanks for the thorough review! I've addressed all your feedback: 1. MyPy Settings (pyproject.toml) 2. Type Ignore Comments (oci_generative_ai.py & oci_data_science.py) 3. Duplicate Test Files 4. Python 3.9 Support
This is NOT a breaking change - existing Python 3.9 users will continue to work seamlessly. Verification:
Latest commit: 589614e |
|
@fede-kamel @YouNeedCryDear |
…bility These type ignores are needed for Python 3.9 + LangChain 0.3.x (real type errors) but appear unused in Python 3.10+ + LangChain 1.x. Adding unused-ignore suppresses the warning while keeping warn_unused_ignores=true as requested by reviewer.
I think for now let's ensure we have backwards compat - you can run a small campaign announcing that to consumers. |
paxiaatucsdedu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
|
Nice! |
Summary
This PR upgrades langchain-oci to support LangChain 1.x (specifically tested with 1.1.0) and adds comprehensive integration tests to ensure compatibility.
Key Changes:
Dependency Changes
Python Version Support
LangChain Version Support (via Python markers)
Note: This is NOT a breaking change for existing Python 3.9 users - they will continue to use LangChain 0.3.x automatically.
Test Evidence
Test Summary
Compatibility Testing
LangChain 1.1.0 (Python 3.10+)
LangChain 0.3.x (Python 3.9 Backwards Compatibility)
New Integration Test Files
Models Tested (Real OCI Inference - Chicago Region)
Meta Llama
xAI Grok
OpenAI (OCI-hosted)
Code Changes
pyproject.toml
>=3.9,<4.0Type Safety Improvements
warn_unused_ignoresmypy setting (reverted totrueto match langchain-google standards)type: ignorecomments that were masking non-existent type errorsAIMessageinstead ofBaseMessage)Test Organization
test_openai_model.py, kept comprehensivetest_openai_models.py)Import Updates
langchain.tools→langchain_core.tools(for LangChain 1.x)Test Plan