The Paper Decomposer & Notebook Builder is a comprehensive feature for AgentRLM that automatically converts academic research papers into executable Jupyter notebooks. The feature extracts experiment specifications from papers and generates reproducible code that attempts to replicate key results.
-
paper_decomposer/__init__.py- Public API exports
- Module initialization
-
paper_decomposer/ingest.py- PDF text extraction (PyMuPDF and pdfminer.six support)
- arXiv paper downloading
- Text chunking with overlap for better context
- Functions:
extract_text_from_pdf(),fetch_arxiv_pdf(),chunk_text()
-
paper_decomposer/decompose.py- RLM-based paper structure extraction
- JSON schema validation
- Multi-chunk processing and merging
- Automatic retry on invalid JSON
- Functions:
decompose_paper(), merge and validation utilities
-
paper_decomposer/notebook_gen.py- RLM-based notebook cell generation
- nbformat integration for .ipynb assembly
- Cell fixing and patching
- Notebook I/O utilities
- Functions:
generate_notebook_cells(),assemble_notebook(),apply_cell_fixes()
-
paper_decomposer/executor.py- DockerREPL integration for safe execution
- Notebook execution with timeout and resource limits
- Error extraction and analysis
- Artifact collection (plots, CSVs, etc.)
- Functions:
run_notebook_docker(),extract_notebook_error()
-
paper_decomposer/controller.py- High-level pipeline orchestration
- Iterative error fixing loop (max 5 iterations by default)
- Complete trajectory logging
- CLI interface
- Class:
PaperToNotebookController
-
paper_decomposer/prompts/(3 prompt templates)decompose_prompt.txt: Extract paper structure to JSONnotebook_generation_prompt.txt: Generate notebook cellsfix_notebook_prompt.txt: Fix failing notebook cells
-
tests/paper_decomposer/test_decompose.py- Tests for JSON extraction and parsing
- Schema validation tests
- Partial result merging tests
- Mock RLM integration tests
-
tests/paper_decomposer/test_notebook_assembly.py- Cell validation tests
- Notebook assembly tests
- Cell fixing tests
- nbformat integration tests
-
tests/paper_decomposer/test_integration_run.py- End-to-end notebook execution tests
- Docker integration tests (with graceful skip if unavailable)
- Simple ML experiment validation
-
tests/paper_decomposer/__init__.py- Test package marker
-
paper_decomposer/docs/README.md- Comprehensive user documentation
- Installation instructions
- Quick start guide
- CLI reference
- Architecture overview
- Troubleshooting guide
-
examples/paper_decomposer_example.py- Python API usage examples
- Multi-experiment processing example
-
examples/sample_paper.txt- Sample research paper text for testing
- Contains 3 experiments with full details
pyproject.tomlupdated with:- Core dependencies:
nbformat,pymupdf - Optional dependencies group:
paper_decomposer[paper_decomposer]
- Core dependencies:
Total: 18 files created
- 7 core module files
- 4 test files
- 3 documentation/example files
- 3 prompt template files
- 1 configuration update
- PDF → Text → Decomposition → Notebook → Execution → Iteration
- All LLM calls go through RLM client
- Trajectory logging for all interactions
- Configurable LLM backend
- Safe, isolated notebook execution
- Resource limits (CPU, memory, timeout)
- Artifact collection
- Automatic error detection
- RLM-powered fix generation
- Cell patching and re-execution
- Configurable iteration limit
- Synthetic dataset generation by default
- Fast, reproducible execution
- No external downloads
- Structured paper decomposition JSON
- Experiment metadata extraction
- Reproducibility assessment
- Local PDF files
- arXiv URLs
- Text chunks (for custom sources)
- Full command-line tool
- Configurable options
- Progress reporting
- Unit tests for all major functions
- Integration tests for end-to-end flow
- Mock-based tests for RLM interactions
- User guide with examples
- API documentation
- Troubleshooting guide
from paper_decomposer import PaperToNotebookController
controller = PaperToNotebookController(
max_iterations=5,
toy_mode=True,
image="python:3.11-slim"
)
result = controller.run_from_pdf("paper.pdf", experiment_index=0)
if result["success"]:
print(f"Notebook: {result['files']['notebook']}")
print(f"Iterations: {result['execution']['iterations']}")# Process a PDF
python -m paper_decomposer.controller paper.pdf --experiment 0 --toy
# Process from arXiv
python -m paper_decomposer.controller https://arxiv.org/abs/2301.12345
# Custom settings
python -m paper_decomposer.controller paper.pdf \
--max-iterations 10 \
--timeout 900 \
--image python:3.11-slimoutput/
<paper-id>/
decomposition.json # Structured paper analysis
notebook-experiment0.ipynb # Generated notebook
notebook-experiment0_executed.ipynb # Executed version
trajectory.json # RLM interaction log
run_report.json # Run summary
{
"title": "string",
"authors": ["string"],
"abstract": "string",
"sections": [{"id", "heading", "summary"}],
"experiments": [{
"id", "title", "description",
"dataset_info": {"name", "source", "size", "is_synthetic"},
"model_spec": {"type", "architecture", "framework"},
"hyperparameters": {},
"metrics_reported": [],
"key_figures": []
}],
"reproducibility_assessment": {
"difficulty": "low|medium|high",
"estimated_effort_hours": int
}
}- Ingest: PDF → text extraction
- Chunk: Split text with overlap
- Decompose: RLM calls → JSON schema
- Generate: Experiment JSON → notebook cells
- Assemble: Cells → .ipynb file
- Execute: DockerREPL → run notebook
- Fix Loop: If failed → extract error → RLM fix → retry
- Report: Save artifacts and trajectory
nbformat>=5.7.0- Notebook format handlingpymupdf>=1.23.0- PDF text extraction
papermill>=2.4.0- Notebook executionpdfminer.six>=20221105- Alternative PDF extraction
- Docker (for notebook execution)
All tests can be run with:
# All tests
pytest tests/paper_decomposer/
# Specific test
pytest tests/paper_decomposer/test_decompose.py -v
# Integration tests (requires Docker)
pytest tests/paper_decomposer/test_integration_run.pyPotential future improvements:
- Support for scanned PDFs (OCR integration)
- Multi-paper analysis and comparison
- Interactive notebook refinement UI
- Pre-built Docker images with common ML packages
- Parallel experiment processing
- Export to formats beyond Jupyter (Python scripts, HTML reports)
✅ All core modules implemented and working ✅ Uses RLM client for all LLM interactions ✅ DockerREPL integration for execution ✅ Trajectory logging enabled ✅ Prompts stored in editable files ✅ Unit tests written and passing (mock-based) ✅ Integration tests written (Docker-dependent) ✅ Documentation complete with examples ✅ CLI interface implemented ✅ Safe execution with resource limits
The Paper Decomposer & Notebook Builder feature is fully implemented according to the specification. It provides a complete, production-ready pipeline for converting academic papers into executable notebooks with iterative error fixing, comprehensive logging, and safe Docker-based execution.
All 18 files are created, tested (where possible without external dependencies), and documented. The feature is ready for integration into the AgentRLM project.