This document provides guidelines for AI agents working on the banyan-extract codebase.
No Emojis: No emojis anywhere in the codebase. If you find one, remove it.
File Naming: Use descriptive names (e.g., chat_service.py, mcp_tool_manager.py), not generic ones (utils.py, helpers.py). Exception: top-level entry points like atlas/main.py.
File Size: Prefer 400 lines or fewer.
Documentation: PRs must update relevant docs in /docs (architecture, features, API, config, troubleshooting).
Changelog: Add a 1-2 line entry to CHANGELOG.md for every PR. Format: ### PR #<number> - YYYY-MM-DD.
Date Stamps: Include YYYY-MM-DD dates in doc filenames or section headers to track staleness.
STRICT RULES FOR ALL AGENTS:
- Agents may READ .env files but NEVER MODIFY or DELETE them
- This applies to all agents without exception
- Any testing that requires .env configuration should use temporary files or ask for user permission
Strict Guidelines:
- NEVER modify or delete .env files - read only: Agents may read .env files but never modify or delete them
- No Special Characters: Never use unicode, special symbols, emojis, or non-standard characters in code or output
- Simplicity First: Prefer simpler implementations over complex logic
- Minimal Dependency Checking: Avoid excessive dependency checking unless explicitly required
- Focused Testing: Write comprehensive but focused tests targeting key functionality
- Proportional Testing: Avoid excessive tests for small features (e.g., 100+ tests for a couple lines of code)
- Relative Paths Only: Never use absolute paths for sample files in tests
- Code Quality: Prioritize clean, maintainable, and well-documented code
- Scope Adherence: Implement only the exact feature requested, no extra functionality
Strict Guidelines:
- NEVER modify or delete .env files - read only: Agents may read .env files but never modify or delete them
- No Special Characters: Ensure no unicode, special symbols, emojis, or non-standard characters in code
- Simplicity Review: Favor simpler solutions and flag overly complex implementations
- Test Quality: Verify tests are comprehensive but not excessive for the feature size
- Path Validation: Ensure no absolute paths are used in test files
- Scope Validation: Confirm implementation matches exact requirements, no scope creep
Strict Guidelines:
- NEVER modify or delete .env files - read only: Agents may read .env files but never modify or delete them
- No Special Characters: Avoid unicode, special symbols, emojis in planning documents
- Simplicity First: Plan for the simplest viable implementation first - always prefer simpler solutions over complex architectures
- Avoid Overly Complex Architectures: Only propose complex solutions when absolutely necessary and provide clear justification
- Proportional Testing: Plan test coverage that matches feature complexity - avoid excessive testing for simple features
- Relative Paths Only: Never use absolute paths for sample files in test plans - always use relative paths from project root
- Minimal Dependencies: Avoid adding unnecessary dependencies in plans
- Clear Scope: Define exact feature boundaries to prevent scope creep
- Justify Complexity: Any complex solution must include clear justification explaining why simpler approaches won't work
Test Planning Guidelines:
- Simple Features (1-2 functions): 3-5 focused tests covering main functionality and edge cases
- Medium Features (3-5 functions): 5-10 tests covering main paths, edge cases, and error handling
- Complex Features (6+ functions): 10-20 tests covering comprehensive scenarios, but avoid excessive testing
- Avoid: Planning 100+ tests for simple features or testing every minor implementation detail
Path Usage Guidelines:
- Test Data Location: All test data should be referenced using relative paths from project root
- Test Data Organization: Plan for test data to be organized in
tests/data/directory structure - No Absolute Paths: Never use absolute paths like
/home/user/project/tests/data/- always usetests/data/ - Cross-Platform Compatibility: Ensure paths work on all platforms (Windows, Linux, macOS)
Implementation Complexity Guidelines:
- Simple Implementation: Single function/method, straightforward logic, minimal dependencies
- Medium Implementation: Multiple related functions, some conditional logic, moderate dependencies
- Complex Implementation: Multiple components, complex workflows, significant dependencies - requires detailed justification
Alignment with Other Agents:
- Planning agent guidelines should align with Feature-Implementer agent's simplicity focus
- Planning agent guidelines should align with Code-Review agent's proportional testing approach
- All agents should enforce relative path usage consistently
test-report-runner: Run frequently after code changes to verify tests pass.
final-checklist-reviewer: Run once at the end of a PR to validate requirements, standards, and quality gates.
Run all tests:
python3 -m pytest tests/Run a single test file:
python3 -m pytest tests/path/to/test_file.pyRun a specific test:
python3 -m pytest tests/path/to/test_file.py::test_nameRun tests with coverage:
python3 -m pytest --cov=src/banyan_extract tests/Run tests with verbose output:
python3 -m pytest -v tests/Run ruff linter (if available):
python3 -m ruff check src/Run ruff formatter (if available):
python3 -m ruff format src/Run flake8 (if available):
python3 -m flake8 src/Build the package:
python3 -m pip install .Build with optional dependencies:
python3 -m pip install .[marker]
python3 -m pip install .[nemotronparse]Install in development mode:
python3 -m pip install -e .-
Group imports in the following order:
- Standard library imports
- Third-party library imports
- Local application imports
-
Use absolute imports for local modules:
from banyan_extract.processor import Processor
-
Avoid wildcard imports (except in
__init__.py):# Good from module import specific_function # Avoid from module import *
- Line length: Maximum 120 characters
- Indentation: 4 spaces (no tabs)
- Spacing:
- Two blank lines around top-level functions and classes
- One blank line around method definitions
- No spaces inside parentheses, brackets, or braces
- Quotes: Use double quotes for strings unless single quotes are needed
- Docstrings: Use Google-style docstrings for public functions and classes
- Use type hints for all function parameters and return values
- Use PEP 604 union syntax (X | Y) instead of Union[X, Y]
- Use Optional[X] for nullable types instead of Union[X, None]
- Use Annotated for complex types with metadata
-
Variables and functions: snake_case
def process_document(self, filepath): file_pages = []
-
Classes: PascalCase
class NemoparseProcessor:
-
Constants: UPPER_SNAKE_CASE
MAX_RETRIES = 3
-
Private members: Leading underscore
def _encode_image(self, image):
-
Boolean variables: Prefix with
is_,has_, orcan_is_valid = True has_error = False
- Use specific exceptions instead of generic Exception
- Provide meaningful error messages
- Use try-except blocks for operations that might fail
- Clean up resources in finally blocks when needed
try:
base64_encoded_data = base64.b64encode(image)
base64_string = base64_encoded_data.decode("utf-8")
return base64_string
except Exception as e:
print(f"An error occurred trying to encode the document: {e}")
return None-
Use Google-style docstrings for public functions and classes:
def sort_elements_by_position(self, bbox_data, width, height): """ Sort document elements based on their spatial position. Args: bbox_data: List of element dictionaries from API response width: Page width in pixels height: Page height in pixels Returns: List of sorted element dictionaries """
-
Document complex logic with inline comments:
# Convert normalized coordinates to absolute pixels # Use top-left corner (ymin, xmin) instead of center for better reading order y_top = bbox['ymin'] * height x_left = bbox['xmin'] * width
- Write unit tests for all new functionality
- Follow the test structure outlined in Test-plan.md
- Use pytest as the test runner
- Mock external dependencies in unit tests
- Test both success and failure cases
banyan-extract/
├── src/
│ └── banyan_extract/
│ ├── __init__.py
│ ├── cli.py
│ ├── converter/
│ ├── output/
│ └── processor/
├── tests/
├── examples/
└── docs/
All processors should inherit from the base Processor class:
from .processor import Processor
class NemoparseProcessor(Processor):
def __init__(self, endpoint_url="", model_name="nvidia/nemoretriever-parse"):
super().__init__()
# Initialize processor-specific attributesEach processor should have a corresponding output class:
class NemoparseOutput:
def __init__(self):
self.pages = []
def add_output(self, page_data):
self.pages.append(page_data)
def save_output(self, output_dir, basename):
# Save output filesNew features should be exposed through the CLI when appropriate:
parser.add_argument("--sort_by_position", action="store_true", default=True,
help="Sort elements by spatial position for logical reading order")The project uses environment variables for configuration:
NEMOPARSE_ENDPOINT=your_endpoint_url
NEMOPARSE_MODEL=your_model_name
- python-pptx
- pandas
- pdf2image
- python-dotenv
- marker-pdf (for marker backend)
- surya-ocr (for marker backend)
- openai (for nemotronparse backend)
- Keep functions small and focused on a single responsibility
- Use descriptive names for variables and functions
- Handle edge cases gracefully
- Write tests first when possible (TDD)
- Follow the existing code patterns in the codebase
- Document assumptions and limitations
- Keep the code DRY (Don't Repeat Yourself)
- Write maintainable code that others can understand
- Use feature branches for new development
- Write meaningful commit messages
- Keep commits small and focused
- Update documentation when making changes
- Run tests before committing
The project uses GitHub Actions for CI/CD. Make sure:
- All tests pass before pushing
- Code follows the style guidelines
- Documentation is updated
- New features have corresponding tests