Welcome! We're excited you're interested in contributing to Legion. This document outlines the process for contributing and helps you get started.
-
Fork the Repository
- Click the "Fork" button in the top right of the GitHub repository
- Clone your fork locally:
git clone https://github.com/YOUR-USERNAME/Legion.git
- Add upstream remote:
git remote add upstream https://github.com/LLMP-io/Legion.git
-
Set Up Development Environment Three options here.
-
Option 1: Using
Makefile
Optioned and automated- Requires you have
make
andpoetry
installed ENV
management options are currentlyvenv
orconda
POETRY
can be set totrue
orfalse
to use it, orpip
2a. Install Make
2b. Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
2c. Set up the environment
make setup ENV=venv POETRY=false # or make setup ENV=conda POETRY=true # or make # Just use the defaults
This will:
- Create and activate a virtual environment (with specified
ENV
) - Install all dependencies (with
pip
orpoetry
) - Set up pre-commit hooks
You can also:
make lint POETRY=<true|false> or make test POETRY=<true|false>
- Requires you have
-
Option 2: Using
setup.py
Default and standardvenv
/pip
setup# Run the setup script python3 scripts/setup_env.py # Activate the virtual environment # On macOS/Linux: source venv/bin/activate # On Windows: # venv\Scripts\activate
This will:
- Create and activate a virtual environment
- Install all dependencies
- Set up pre-commit hooks
-
Option 3: 🐳 Whale you can just use
Docker
If you have Docker installed and the docker engine running, from the project root you can just run:docker compose up --build
This will spin up a cointainer, build the project to it, and run the tests. Want to keep it running and get a shell on it to run other commands?
docker compose up -d # detached docker compose exec legion bash
-
-
Configure Git Email To maintain privacy while contributing, you can use a GitHub-provided no-reply email address:
# Replace 'username' with your GitHub username # Get your GitHub user ID from: https://api.github.com/users/username git config user.email "[email protected]"
-
Create a Branch
git checkout -b feature/your-feature-name # or git checkout -b fix/your-bug-fix
We follow PEP 8 guidelines for Python code style. Key points:
- Use 4 spaces for indentation
- Maximum line length of 79 characters for code, 72 for docstrings
- Use meaningful variable names
- Add docstrings to all functions, classes, and modules
- Use comprehensive type hints
We use mypy for static type checking. Key requirements:
- All functions must have complete type hints
- All class attributes must be typed
- Use
Optional[T]
instead ofT | None
- Use
Sequence[T]
for read-only lists - Use
Mapping[K, V]
for read-only dicts - Avoid
Any
unless absolutely necessary - Run type checks before submitting PRs
-
Set up pre-commit hooks:
# Install pre-commit pip install pre-commit # Install the git hooks pre-commit install
-
The pre-commit hooks will automatically run:
- Non-integration tests
- Style checking with ruff
- Security checks with bandit and safety
You can also run these checks manually:
-
Run tests:
# Run all tests except integration tests
pytest -v -m "not integration"
# Run only integration tests
pytest -v -m integration
# Run all tests
pytest -v
- Run type checking (optional, but recommended):
# Run mypy type checker
python scripts/typecheck.py
# Check specific modules
python scripts/typecheck.py legion/agents legion/blocks
- Run code style checks:
# Run ruff linter
python scripts/lint.py
- Run security checks:
# Run security scans
python scripts/security.py
# Check specific modules
python scripts/security.py legion/agents legion/blocks
- Update documentation if needed
- Add tests for new features
-
Create Pull Request
- Push your changes to your fork
- Create a PR against the
main
branch - Fill out the PR template
- Link any related issues
-
PR Guidelines
- Keep changes focused and atomic
- Provide clear description of changes
- Include any necessary documentation updates
- Add screenshots for UI changes
- Reference any related issues
-
Review Process
- Maintainers will review your PR
- Address any requested changes
- Once approved, maintainers will merge your PR
-
Direct to Upstream (Recommended)
- Each contributor maintains their fork
- Create PRs directly to upstream
- Sync fork:
git fetch upstream git rebase upstream/main
-
Fork Collaboration
- Add collaborators to your fork's settings
- Both can push branches
- Create single PR to upstream
- Maintain clear ownership of the PR
-
Cross-fork PRs
- For non-collaborator contributions
- Create PR between forks
- Owner submits final PR upstream
Note: Contributions are tracked through PRs, not individual commits due to squash merging. All contributors are credited in the PR history.
- Check existing issues to avoid duplicates
- Use issue templates when available
- Provide clear reproduction steps for bugs
- For feature requests, explain the use case
Look for issues labeled good-first-issue
if you're new to the project. These are typically:
- Documentation improvements
- Small bug fixes
- Test additions
- Simple feature implementations
- Join our Discord server for real-time discussion
- Use the #help channel for technical questions
- Tag maintainers in GitHub issues if you need clarification
- #announcements: Project updates and news
- #general: Introduce yourself and ask questions
- #help: Get help with technical issues
- #development: Discuss ongoing development
- #pull-requests: PR discussions and reviews
- #give-your-input: Share and discuss feature ideas
- #general-ai-discussion: Talk all things AI 🤖
We value all contributions, big and small! Contributors will be:
- Added to our Contributors list
- Recognized in release notes for significant contributions
- Badges applied to your profile within the Legion Discord Server
- Given credit in documentation when appropriate
Thank you for contributing to Legion! 🚀