apps/learning-api/AGENTS.md
AGENTS.md
AGENTS.md
Project Overview
LearningAPI V2 is a Python monorepo that generates educational content (flashcards, quizzes, summaries) from documents using AI. It consists of:
- api/: FastAPI web service providing REST endpoints
- workers/: Background processing with Celery (learning_agents for AI tasks, parser for document parsing)
- shared/: Common schemas and utilities used by all services
Essential Commands
# Development
poe dev # Start API + workers (no parser/OCR)
poe dev-docker # Start all services with slim CPU parser/OCR (requires TRITON_URL)
poe dev-docker-parser-gpu # Start legacy local GPU/VLLM parser stack
poe install # Install dependencies for all services
# Code Quality
poe lint # Run Ruff linter
poe format # Format code with Ruff
poe typecheck # Run Pyright type checking
poe ci # Run full CI pipeline (lint + typecheck)
# Testing
poe test # Run all tests
poe test-unit # Run unit tests only
poe test-integration # Run integration tests only
# Testing with automatic service management
poe test-with-services # Run all tests (starts test Docker services)
# Other
poe update-types # Generate TypeScript types from OpenAPI (requires poe dev running)
poe set-secrets # Pull secrets from Infisical
Architecture
- API Service (api/): FastAPI application handling HTTP requests
- Endpoints:
/ingest_document,/generate_flashcards,/generate_quiz,/generate_summary - Authentication via
X-API-Keyheader - Delegates heavy processing to Celery workers
- Endpoints:
- Worker Services (workers/):
- learning_agents/: AI-powered content generation using LangChain/LangGraph
- Separate agents for flashcards, quizzes, summaries, and document ingestion
- Uses Google Vertex AI and OpenAI models
- parser/: Document parsing with Docling (optional, GPU-capable)
- learning_agents/: AI-powered content generation using LangChain/LangGraph
- Shared Package (shared/): Common Pydantic schemas and utilities
- All services depend on this package for type safety
- Contains schemas for Chunks, Languages, Subjects, and API contracts
- IMPORTANT: Since this is a monorepo with separate apps, shared code between API and Workers MUST be placed in the shared package. The API cannot import from workers and vice versa.
Development Workflow
- Each service is an independent UV project with its own
pyproject.toml - Docker Compose with watch mode enables hot-reloading
- Services communicate via Celery/Redis task queue
- Strong typing enforced with Pyright and Pydantic
Key Technologies
- Python 3.12+ (3.10+ for parser due to Docling requirements)
- UV for package management
- Poe the Poet for task running
- FastAPI for REST API
- Celery + Redis for task queue
- Docker Compose for local development
- Ruff for linting/formatting
- Pyright for type checking
Test Structure
The project follows a distributed testing approach:
- Unit Tests: Located within each service directory
api/tests/- API endpoint unit tests with mocked dependencies (13 tests)workers/learning_agents/tests/- Worker task unit tests (currently empty)workers/parser/tests/- Parser unit tests (currently empty)
- Integration Tests: Located at the root level (
tests_integration/)test_integration.py- All integration tests including connectivity checks and complete workflows (10 tests)- Tests use pytest markers:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow
- Test Configuration:
.env- Environment variables (uses same as development)pytest.ini- Pytest configuration with markers and paths- Test user:
test@email.com/password(from supabase seed)
- Running Tests:
- Option 1: Manual setup
- Start Supabase and edge functions:
cd ~/work/studyflash_v2/apps/supabase && pnpm run dev- This runs
npx supabase start(predev hook) and serves edge functions - If test user doesn't exist, run:
pnpm run seedto create test@email.com
- This runs
- Start learning-api services:
poe dev - Run tests:
poe test
- Start Supabase and edge functions:
- Option 2: Automatic setup (recommended)
- Use
poe test-with-services- automatically stops existing Docker services and starts test-specific ones - The test script handles all service management
- IMPORTANT: Core-api Supabase must still be running separately at http://localhost:54321
- Without Supabase, only smoke tests will pass (6/7), integration tests will fail
- Use
- Option 1: Manual setup
- Test Commands:
poe test- Run all testspoe test-unit- Run unit tests onlypoe test-integration- Run integration tests onlypoe test-with-services- Run all tests with automatic service management
Code Quality Workflow
When making code changes, always follow this workflow to ensure code quality:
- After Each Edit: Run linting and type checking for the project you modified
poe lint # Check for linting issues poe typecheck # Verify type safety - Fix Any Issues: Address all linting and type checking errors before proceeding
- Final Step: Once all edits are complete and all checks pass, format the code
poe format # Auto-format all code with Ruff
Important: Always run these checks in this order. Format last to ensure consistent code style after all manual fixes.
Important Instructions
- Package Management: Always use
uv addinstead ofuv pip installwhen adding dependencies in UV projects - File Management: Never create files unless absolutely necessary. Always prefer editing existing files
- Documentation: Don't create documentation files (*.md) or README files unless explicitly requested
- Validation: Validate JSON/dict payloads with Pydantic models by default (except when an external library already validates/parses them)
- Type Safety: Avoid
getattrfor production code. Prefer typed models, explicit attributes, or typed fallbacks. Usegetattronly when interfacing with truly dynamic/unknown objects and document why.