理念
旨在为所有代码贡献遵循这些核心原则:入门
快速修复:提交错误修复
对于简单的错误修复,您可以立即开始:克隆和设置
Create a branch
Make your changes
Add tests
Run tests
Submit a pull request
Fixes #123).Full development setup
For ongoing development or larger contributions:Development environment
Repository structure
Development workflow
Contribution guidelines
Development environment
Set up a development environment for the package(s) you’re working on.- LangChain
- LangGraph
Core abstractions
Core abstractions
langchain-core:Main package
Main package
langchain:Partner packages
Partner packages
Community packages
Community packages
Repository structure
- LangChain
- LangGraph
Core packages
Core packages
langchain(located inlibs/langchain/): Main package with chains, agents, and retrieval logiclangchain-core(located inlibs/core/): Base interfaces and core abstractions
Partner packages
Partner packages
libs/partners/, these are independently versioned packages for specific integrations. For example:langchain-openai: OpenAI integrationslangchain-anthropic: Anthropic integrationslangchain-google-genai: Google Generative AI integrations
Supporting packages
Supporting packages
langchain-text-splitters: Text splitting utilitieslangchain-standard-tests: Standard test suites for integrationslangchain-cli: Command line interfacelangchain-community: Community maintained integrations (located in a separate repo)
Development workflow
Testing requirements
Unit tests
tests/unit_tests/Requirements:- No network calls allowed
- Test all code paths including edge cases
- Use mocks for external dependencies
Integration tests
tests/integration_tests/Requirements:- Test real integrations with external services
- Use environment variables for API keys
- Skip gracefully if credentials unavailable
Test quality checklist
- Tests fail when your code is broken
- Edge cases and error conditions are tested
- Proper use of fixtures and mocks
Code quality standards
Quality requirements:- Type hints
- Documentation
- Code style
Manual formatting and linting
Format code
Run linting checks
Verify changes
Contribution guidelines
Backwards compatibility
Maintain compatibility:Stable interfaces
Stable interfaces
- Function signatures and parameter names
- Class interfaces and method names
- Return value structure and types
- Import paths for public APIs
Safe changes
Safe changes
- Adding new optional parameters
- Adding new methods to classes
- Improving performance without changing behavior
- Adding new modules or functions
Before making changes
Before making changes
- Would this break existing user code?
- Check if your target is public
-
If needed, is it exported in
__init__.py? - Are there existing usage patterns in tests?
Bugfixes
For bugfix contributions:Reproduce the issue
Write failing tests
Implement the fix
Verify the fix
Document the change
New features
We aim to keep the bar high for new features. We generally don’t accept new core abstractions, changes to infra, changes to dependencies, or new agents/chains from outside contributors without an existing issue that demonstrates an acute need for them. In general, feature contribution requirements include:Design discussion
- The problem you’re solving
- Proposed API design
- Expected usage patterns
Implementation
- Follow existing code patterns
- Include comprehensive tests and documentation
- Consider security implications
Integration considerations
- How does this interact with existing features?
- Are there performance implications?
- Does this introduce new dependencies?
Security guidelines
Security checklist:Input validation
Input validation
- Validate and sanitize all user inputs
- Properly escape data in templates and queries
- Never use
eval(),exec(), orpickleon user data, as this can lead to arbitrary code execution vulnerabilities
Error handling
Error handling
- Use specific exception types
- Don’t expose sensitive information in error messages
- Implement proper resource cleanup
Dependencies
Dependencies
- Avoid adding hard dependencies
- Keep optional dependencies minimal
- Review third-party packages for security issues
测试与验证
本地运行测试
在提交 PR 之前,请确保完成以下步骤。请注意,LangChain 与 LangGraph 的要求略有差异。- LangChain
- LangGraph
Unit tests
Integration tests
Formatting
Type checking
PR submission
测试编写指南
为了编写有效的测试,需要遵循一些良好的实践:- Use natural language to describe the test in docstrings
- Use descriptive variable names
- Be exhaustive with assertions
- Unit tests
- Integration tests
- Mock usage