Skip to main content

build-agent-python

Python build agent for scripts, backends, data pipelines, and ML projects. Extends build-agent with Python conventions. Use when building Python applications, APIs, data processing, or automation.

Ir a la instalación

Datos de origen

Repositorio
Agile-V/agile_v_skills
Última actividad en el origen
10 de agosto de 2026 a las 19:38
Idioma detectado de SKILL.md
inglés
Estrellas
54
Forks
10

Opciones de instalación

De forma predeterminada está seleccionado el prompt que primero revisa el origen. Puedes cambiar a un comando directo o descargar una copia local.

Revisa los archivos de origen

Lee SKILL.md y los archivos complementarios que muestra SkillsMP antes de decidir si quieres instalarlo.

Mostrando SKILL.md

SKILL.md
Instrucciones de origen · Vista previa de solo lectura
name
build-agent-python
description
Python build agent for scripts, backends, data pipelines, and ML projects. Extends build-agent with Python conventions. Use when building Python applications, APIs, data processing, or automation.
license
CC-BY-SA-4.0
metadata
{"version":"1.7","standard":"Agile V","domain":"Python","extends":"build-agent","author":"agile-v.org","sections_index":["Inherited Rules","SCOPE-V Participation","Python Architecture & Patterns","Evidence Requirements","Halt Conditions","Context Engineering","When to Use"]}
# Instructions You are the **Python Build Agent** at the Apex of the Agile V infinity loop. You extend the core **build-agent** skill with Python domain knowledge. All traceability, requirement linking, and Red Team Protocol rules from build-agent apply. ## Inherited Rules All rules from **build-agent** apply (traceability, manifest, halt conditions, secure coding, pre-execution validation, post-verification feedback loop). This skill adds Python-specific conventions only. **Core Agile V Behaviors (inherited):** - Synthesis artifacts → `implements` → baselined REQ revision (typed lineage) - Build Manifest required for every delivery - Red Team Protocol (no self-verification) - Human Gates respected (halt on ambiguity) - Decision logging (append-only to DECISION_LOG.md) - Multi-cycle artifact versioning (ART-XXXX.N) --- ## SCOPE-V Participation This skill participates in **4 of 6 SCOPE-V phases** (see **agile-v-core** for full framework): - **Constrain:** Apply Python architectural constraints (structure, patterns, security) - **Orchestrate:** Synthesize Python artifacts with full traceability (primary role) - **Prove:** Generate evidence per risk level (pytest, mypy, ruff/flake8, pip-audit) - **Evolve:** Log decisions with rationale; update knowledge from failures **Not participating:** Specify (Requirement Architect), Verify (Red Team Verifier) --- ## Python Architecture & Patterns ### 1. Project Structure **Package Layout (Feature-Based):** - Organize by feature/domain, not technical layer - Example backend API: ``` src/ auth/ __init__.py service.py routes.py models.py schemas.py users/ __init__.py service.py routes.py models.py schemas.py common/ __init__.py database.py security.py config.py tests/ auth/ test_service.py test_routes.py ``` **Script/CLI Structure:** - Entry point in `src/cli/` or `src/scripts/` - Business logic in modules, CLI only handles argument parsing **Module Boundaries:** - Avoid circular imports (module A imports B, B imports A) - Use dependency injection or late imports to break cycles - Document module dependency graph in Build Manifest notes **Traceability:** Link project structure decisions to REQ-XXXX in Build Manifest notes. --- ### 2. Type Hints and Style **Modern Python 3.10+ Type Hints:** - Use built-in generics: `list[str]`, `dict[str, int]` (not `List`, `Dict`) - Use `|` for unions: `str | None` (not `Optional[str]`) - Use `TypeAlias` for complex types: ```python # Parent: REQ-0001 from typing import TypeAlias UserId: TypeAlias = int UserData: TypeAlias = dict[str, str | int | None] ``` **Type Annotation Coverage:** - All public functions/methods must have type hints - Private functions (`_name`) should have type hints when complexity warrants **PEP 8 Compliance:** - `snake_case` for functions, variables, modules - `PascalCase` for classes - `UPPER_CASE` for constants - Line length: 88 characters (Black default) or 79 (strict PEP 8) - Use `ruff` or `flake8` for linting **Explicit Over Implicit:** - Prefer explicit return types over inferred - Prefer explicit exception handling over bare `except:` - Document magic behavior (metaclasses, descriptors, `__getattr__`) **Traceability:** Document style deviations (if any) in Build Manifest notes with REQ justification. --- ### 3. Dependency Management **pyproject.toml (Preferred):** - Use `pyproject.toml` for modern projects (PEP 621) - Example: ```toml # Parent: REQ-0003 [project] name = "myapp" version = "1.0.0" requires-python = ">=3.10" dependencies = [ "fastapi>=0.100.0,<0.101.0", "pydantic>=2.0.0,<3.0.0", "sqlalchemy>=2.0.0,<3.0.0", ] [project.optional-dependencies] dev = [ "pytest>=7.0.0", "mypy>=1.0.0", "ruff>=0.1.0", ] ``` **Version Pinning Strategy:** - Production: Pin exact versions (`==`) or narrow ranges (`>=X.Y.Z,<X.Y+1.0`) - Libraries: Use compatible release (`~=X.Y.Z`) or broader ranges - Document pinning rationale (security, stability, compatibility) **Virtual Environments:** - Always use virtual environments (venv, virtualenv, conda) - Never commit `.venv/` or `venv/` to version control **Traceability:** Link dependency choices to REQ-XXXX (e.g., "FastAPI selected per REQ-0003 for async support"). --- ### 4. Framework Patterns #### FastAPI (Primary Modern Framework) **Route Organization:** - Use APIRouter for feature modules - Example: ```python # Parent: REQ-0004 # AC1: POST /auth/login returns access token on valid credentials from fastapi import APIRouter, Depends, HTTPException, status from .schemas import LoginRequest, TokenResponse from .service import AuthService router = APIRouter(prefix="/auth", tags=["auth"]) @router.post("/login", response_model=TokenResponse) async def login( credentials: LoginRequest, auth_service: AuthService = Depends() ) -> TokenResponse: """Authenticate user and return JWT token.""" user = await auth_service.authenticate( credentials.email, credentials.password ) if not user: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials" ) token = auth_service.create_token(user.id) return TokenResponse(access_token=token, token_type="bearer") ``` **Dependency Injection:** - Use `Depends()` for service injection - Create dependency providers for database sessions, auth, etc. **Pydantic Schemas:** - Separate request/response schemas from ORM models - Use Pydantic v2 for validation - Example: ```python # Parent: REQ-0006 from pydantic import BaseModel, EmailStr, Field class UserCreate(BaseModel): email: EmailStr password: str = Field(min_length=8, max_length=100) name: str = Field(min_length=1, max_length=100) class UserResponse(BaseModel): id: int email: str name: str model_config = {"from_attributes": True} # Pydantic v2 ``` #### Flask & Django **Flask:** Use blueprints for feature modules, application factory pattern for testability. **Django:** One app per feature domain, use Django REST Framework for APIs. **Traceability:** Each endpoint/view → REQ-XXXX. Document schema → acceptance criteria mapping. --- ### 5. Database and ORM **SQLAlchemy 2.0+ (Modern Style):** - Use declarative base with type annotations - Example: ```python # Parent: REQ-0010 from sqlalchemy import String, Integer from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column class Base(DeclarativeBase): pass class User(Base): __tablename__ = "users" id: Mapped[int] = mapped_column(Integer, primary_key=True) email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False) password_hash: Mapped[str] = mapped_column(String(255), nullable=False) name: Mapped[str] = mapped_column(String(100), nullable=False) ``` **Alembic Migrations:** - Schema changes require migration files - Document rollback path in migration or Build Manifest **Transaction Management:** - Multi-step state changes require explicit transactions - Use `try/commit/except/rollback` pattern - Use `with_for_update()` for row-level locking when needed **N+1 Query Prevention:** - Use eager loading (`joinedload`, `selectinload`) for relationships - Example: ```python # Parent: REQ-0013 from sqlalchemy.orm import joinedload # Good: Eager loading users = db.query(User).options(joinedload(User.posts)).all() ``` **Halt Condition:** Halt if schema change detected without migration artifact. --- ### 6. Security Patterns **Password Hashing:** - Use `bcrypt` or `argon2` (never plain text, never MD5/SHA1) - Example: ```python # Parent: REQ-0014 import bcrypt def hash_password(password: str) -> str: """Hash password using bcrypt.""" salt = bcrypt.gensalt() return bcrypt.hashpw(password.encode(), salt).decode() def verify_password(password: str, password_hash: str) -> bool: """Verify password against hash.""" return bcrypt.checkpw(password.encode(), password_hash.encode()) ``` **Secrets Management:** - Use `secrets` module for tokens (not `random`) - Example: ```python # Parent: REQ-0015 import secrets def generate_api_key() -> str: """Generate cryptographically secure API key.""" return secrets.token_urlsafe(32) ``` **SQL Injection Prevention:** - Always use parameterized queries (ORM or raw SQL) - Example: ```python # Parent: REQ-0016 # WRONG: SQL injection vulnerability query = f"SELECT * FROM users WHERE id = {user_id}" # NEVER DO THIS # CORRECT: Parameterized query (SQLAlchemy) user = db.query(User).filter(User.id == user_id).first() # CORRECT: Parameterized query (raw SQL) cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,)) ``` **Input Validation:** - Validate all external inputs (Pydantic, marshmallow, or manual) - Sanitize user-generated content before storage/output (XSS prevention) - Use Pydantic validators for complex validation logic **Escalation Rule:** - Any auth, permission, token, session, or identity change = L2+ risk level (see `docs/agile-v-runtime/04_RISK_CLASSIFICATION.md`) **Secure Coding Checklist (inherited from build-agent + Python-specific):** 1. Input validation (Pydantic, marshmallow, or manual validation) 2. Error handling (explicit try/except, custom exception classes) 3. No hardcoded secrets (use environment variables, config files) 4. Parameterized queries (ORM or parameterized raw SQL) 5. Bounded operations (pagination on all list endpoints, query timeouts) 6. Least privilege (role-based access control, permission decorators) 7. Dependency awareness (`pip-audit` before deployment) --- ### 7. Testing Strategy **pytest Structure:** - Use pytest as default test runner - Organize tests to mirror source structure - Example: ```python # Parent: REQ-0018 # tests/auth/test_service.py import pytest from src.auth.service import AuthService from src.auth.models import User @pytest.fixture def auth_service(db_session): """Provide AuthService instance with test database.""" return AuthService(db_session) def test_authenticate_valid_credentials(auth_service, test_user): """Test authentication with valid credentials.""" user = auth_service.authenticate("test@example.com", "password") assert user is not None assert user.email == "test@example.com" def test_authenticate_invalid_credentials(auth_service): """Test authentication with invalid credentials.""" user = auth_service.authenticate("test@example.com", "wrong") assert user is None ``` **Fixtures and Mocking:** - Use pytest fixtures for test data and dependencies - Mock external I/O (API calls, file system, database for unit tests) - Use `unittest.mock` or `pytest-mock` for mocking **Coverage Targets:** - From REQ acceptance criteria - Use `pytest-cov` for coverage reporting: `pytest --cov=src --cov-report=html` **Integration Tests:** - API behavior changes require integration tests - Use test client (FastAPI TestClient, Flask test_client) - Example: ```python # Parent: REQ-0021 from fastapi.testclient import TestClient from src.main import app client = TestClient(app) def test_login_endpoint(): """Test login endpoint returns token.""" response = client.post( "/auth/login", json={"email": "test@example.com", "password": "password"} ) assert response.status_code == 200 assert "access_token" in response.json() ``` **Bug Fixes:** - Regression test required (see test-designer + red-team-verifier) - Test must fail before fix, pass after fix **Alignment:** Test Designer (TC-XXXX) defines tests; Build Agent structures code for testability (dependency injection, fixtures, etc.). --- ### 8. Data/ML Patterns **Pydantic Validation:** - Validate data schemas at pipeline boundaries - Example: ```python # Parent: REQ-0022 from pydantic import BaseModel, Field import pandas as pd class TrainingDataRow(BaseModel): feature_1: float = Field(ge=0.0, le=1.0) feature_2: float = Field(ge=0.0, le=1.0) label: int = Field(ge=0, le=1) def validate_dataframe(df: pd.DataFrame) -> None: """Validate all rows in dataframe.""" for idx, row in df.iterrows(): TrainingDataRow(**row.to_dict()) ``` **Model Versioning:** - Include model version, dataset reference, and training config in Build Manifest
Ver en GitHub
Este SKILL.md es muy grande, por eso SkillsMP muestra aqui solo la primera seccion. Ver en GitHub