codegen-classroom 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/PKG-INFO +144 -150
  2. codegen_classroom-0.1.1/README.md +231 -0
  3. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/__init__.py +1 -1
  4. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/agent_config.py +31 -1
  5. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/agents.py +39 -1
  6. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/agents_test.py +24 -1
  7. codegen_classroom-0.1.1/codegen_classroom/classroom_integration_test.py +297 -0
  8. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/data_utils.py +99 -0
  9. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/data_utils_test.py +72 -0
  10. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/plotting.py +219 -0
  11. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/reporting.py +290 -142
  12. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/tasks/AGENTS.md +53 -41
  13. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/README.md +131 -0
  14. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/__init__.py +15 -0
  15. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/config.py +370 -0
  16. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/data_loader.py +119 -0
  17. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/housing.ipynb +415 -0
  18. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/leaderboard.tsv +17 -0
  19. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/run_housing.py +1027 -0
  20. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/run_housing_test.py +242 -0
  21. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/solutions/housing_4s_12c_20261103.md +1207 -0
  22. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/solutions/housing_6s_12c_20261104.md +843 -0
  23. codegen_classroom-0.1.1/codegen_classroom/tasks/housing/solutions/housing_6s_12c_v2_20261022.md +1918 -0
  24. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/tasks/template/README.md +18 -20
  25. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/tasks/template/config.py +19 -22
  26. codegen_classroom-0.1.1/codegen_classroom/tasks/template/leaderboard.tsv +5 -0
  27. codegen_classroom-0.1.1/codegen_classroom/tasks/template/run_template.py +620 -0
  28. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/tasks/template/run_template_test.py +49 -10
  29. codegen_classroom-0.1.1/codegen_classroom/tasks/template/solutions/template_6s_12c_20261023.md +1148 -0
  30. codegen_classroom-0.1.1/codegen_classroom/tasks/template/solutions/template_6s_12c_v3_20261027.md +890 -0
  31. codegen_classroom-0.1.1/codegen_classroom/tasks/template/solutions/template_6s_12c_v5_20261104.md +557 -0
  32. codegen_classroom-0.1.1/codegen_classroom/tasks/template/task_example.ipynb +377 -0
  33. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/verify_task.py +5 -1
  34. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/verify_task_test.py +4 -0
  35. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom.egg-info/PKG-INFO +144 -150
  36. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom.egg-info/SOURCES.txt +14 -2
  37. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom.egg-info/requires.txt +2 -0
  38. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/pyproject.toml +28 -4
  39. codegen_classroom-0.1.0/README.md +0 -248
  40. codegen_classroom-0.1.0/codegen_classroom/classroom_integration_test.py +0 -152
  41. codegen_classroom-0.1.0/codegen_classroom/tasks/template/leaderboard.tsv +0 -3
  42. codegen_classroom-0.1.0/codegen_classroom/tasks/template/run_template.py +0 -530
  43. codegen_classroom-0.1.0/codegen_classroom/tasks/template/solutions/template_4s_10c_student_2_gemini_3_5_flash_c8_r2_0p976_20261015.md +0 -904
  44. codegen_classroom-0.1.0/codegen_classroom/tasks/template/solutions/template_5s_12c_student_2_gemini_3_1_pro_preview_c5_r2_0p985_20261015.md +0 -865
  45. codegen_classroom-0.1.0/codegen_classroom/tasks/template/task_example.ipynb +0 -359
  46. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/LICENSE +0 -0
  47. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/code_execution.py +0 -0
  48. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/code_execution_test.py +0 -0
  49. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/metrics.py +0 -0
  50. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/metrics_test.py +0 -0
  51. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/scoring.py +0 -0
  52. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/scoring_test.py +0 -0
  53. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/student_learning.py +0 -0
  54. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/student_learning_test.py +0 -0
  55. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/tasks/__init__.py +0 -0
  56. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/tasks/template/__init__.py +0 -0
  57. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom/tasks/template/data_loader.py +0 -0
  58. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom.egg-info/dependency_links.txt +0 -0
  59. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/codegen_classroom.egg-info/top_level.txt +0 -0
  60. {codegen_classroom-0.1.0 → codegen_classroom-0.1.1}/setup.cfg +0 -0
@@ -1,8 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codegen-classroom
3
- Version: 0.1.0
4
- Summary: A framework for iterative code generation for ML and data analysis tasks using parallel LLM agents in Colab.
3
+ Version: 0.1.1
4
+ Summary: A framework for iterative code generation and recursive self-improvement (RSI) on ML and data analysis tasks using parallel LLM agents, optimized for local and Colab deployments.
5
5
  Author: Google LLC
6
+ Author-email: Jake Garrison <jakegarrison@google.com>
6
7
  License:
7
8
  Apache License
8
9
  Version 2.0, January 2004
@@ -207,10 +208,18 @@ License:
207
208
  limitations under the License.
208
209
 
209
210
  Project-URL: Homepage, https://github.com/google-research/codegen-classroom
210
- Classifier: Programming Language :: Python :: 3
211
+ Project-URL: Repository, https://github.com/google-research/codegen-classroom
212
+ Project-URL: Issues, https://github.com/google-research/codegen-classroom/issues
213
+ Keywords: machine-learning,automated-research,autoresearch,self-improvement,recursive-self-improvement,rsi,code-generation,llm-agents,multi-agent,automl,gemini,gemma
214
+ Classifier: Development Status :: 4 - Beta
215
+ Classifier: Intended Audience :: Developers
216
+ Classifier: Intended Audience :: Science/Research
211
217
  Classifier: License :: OSI Approved :: Apache Software License
212
218
  Classifier: Operating System :: OS Independent
219
+ Classifier: Programming Language :: Python :: 3
213
220
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
221
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
222
+ Classifier: Topic :: Software Development :: Code Generators
214
223
  Requires-Python: >=3.9
215
224
  Description-Content-Type: text/markdown
216
225
  License-File: LICENSE
@@ -230,6 +239,7 @@ Requires-Dist: pyarrow
230
239
  Provides-Extra: notebook
231
240
  Requires-Dist: plotly; extra == "notebook"
232
241
  Requires-Dist: ipython; extra == "notebook"
242
+ Requires-Dist: rich; extra == "notebook"
233
243
  Provides-Extra: torch
234
244
  Requires-Dist: torch; extra == "torch"
235
245
  Requires-Dist: torchvision; extra == "torch"
@@ -243,6 +253,7 @@ Requires-Dist: pytest-mock; extra == "dev"
243
253
  Provides-Extra: all
244
254
  Requires-Dist: plotly; extra == "all"
245
255
  Requires-Dist: ipython; extra == "all"
256
+ Requires-Dist: rich; extra == "all"
246
257
  Requires-Dist: torch; extra == "all"
247
258
  Requires-Dist: torchvision; extra == "all"
248
259
  Requires-Dist: jax; extra == "all"
@@ -253,121 +264,74 @@ Dynamic: license-file
253
264
 
254
265
  # Codegen Classroom 🎓
255
266
 
256
- ### A framework for iterative code generation for ML and data analysis tasks
267
+ ### A framework for iterative code generation for ML and data analysis tasks using parallel LLM agents.
268
+
269
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/google-research/codegen-classroom/blob/main/codegen_classroom/tasks/template/task_example.ipynb)
270
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
271
+ [![Gemini API](https://img.shields.io/badge/Gemini-API-8E75B2.svg)](https://ai.google.dev/gemini-api/docs)
272
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
273
+ [![GitHub Stars](https://img.shields.io/github/stars/google-research/codegen-classroom?style=social)](https://github.com/google-research/codegen-classroom/stargazers)
257
274
 
258
- ### using parallel LLM agents in Colab.
275
+ **Authors:** [Jake Garrison](mailto:jakegarrison@google.com),
276
+ [Zhihan Zhang](mailto:zzhihan@cs.washington.edu),
277
+ [Deon Kouatchou](mailto:deonkouatchou@google.com),
278
+ [Girish Narayanswamy](mailto:girishvn@google.com)
259
279
 
260
- **Authors:** [Jake](mailto:jakegarrison@google.com), [Zhihan](mailto:zzhihan@google.com), [Deon](mailto:deonkouatchou@google.com), [Girish](mailto:girishvn@google.com)
280
+ **Created:** August 2025
261
281
 
262
282
  --------------------------------------------------------------------------------
263
283
 
264
284
  ## Overview
265
285
 
266
286
  Codegen Classroom **automates code generation** for tasks that can be scored
267
- (e.g., regression, classification, signal processing) using **parallel
268
- [Gemini](https://ai.google.dev/gemini-api/docs/models) agents** in Colab. The
269
- library operates as an **autonomous LLM agent loop**; it evaluates the output of
270
- a language model iteratively. It is best suited for tasks where solution quality
271
- can be **scored numerically**. Agents **iteratively write, test, and refine**
272
- solutions in a learning loop where code is **executed and scored** against
273
- quantitative metrics.
287
+ quantitatively (e.g., regression, classification, signal processing) using
288
+ **parallel [Gemini](https://ai.google.dev/gemini-api/docs/models) and
289
+ [Gemma](https://ai.google.dev/gemma) agents**.
274
290
 
275
- Agents **improve based on performance** feedback (scores, errors) and can
276
- **collaborate** with other agents to share insights and escape local optima.
291
+ Instead of single-shot prompting, multiple student agents **iteratively write,
292
+ execute, debug, and refine** Python solutions in a sandboxed **recursive
293
+ self-improvement (RSI)** loop. Agents learn from execution feedback (validation
294
+ scores, runtime errors, diagnostic metrics) and **collaborate via peer
295
+ crossover** to share high-performing ideas and escape local optima.
277
296
 
278
- This framework elevates the human role from **developer to supervisor**. You
279
- define the **task, data, constraints, and scoring** criteria, while agents
280
- perform the **implementation and iterative refinement**.
297
+ Whether you define the data splits and scoring metrics directly or prompt an
298
+ agent to set up the task, the classroom handles implementation and iterative
299
+ optimization.
281
300
 
282
301
  --------------------------------------------------------------------------------
283
302
 
284
- ## Getting Started
285
-
286
- ### Prerequisites
287
-
288
- * Python 3.9 or higher
289
- * Google Colab or Jupyter Notebook environment
290
-
291
- ### Installation and Setup
292
-
293
- We recommend using a virtual environment to avoid dependency conflicts.
294
-
295
- 1. **Create a virtual environment**:
296
-
297
- ```bash
298
- python3 -m venv .venv
299
- ```
300
-
301
- 2. **Activate the virtual environment**:
302
-
303
- * On Linux/macOS:
304
-
305
- ```bash
306
- source .venv/bin/activate
307
- ```
308
- * On Windows:
309
-
310
- ```bash
311
- .venv\Scripts\activate
312
- ```
313
-
314
- 3. **Install dependencies in editable mode**:
315
-
316
- ```bash
317
- # Standard installation (core library - matplotlib included)
318
- pip install -e .
319
-
320
- # For interactive notebooks (Plotly and IPython):
321
- pip install -e ".[notebook]" # or pip install codegen_classroom[notebook]
322
-
323
- # With LightGBM (recommended for tabular tasks):
324
- pip install -e ".[lightgbm]"
325
-
326
- # With PyTorch:
327
- pip install -e ".[torch]"
328
-
329
- # With JAX:
330
- pip install -e ".[jax]"
331
-
332
- # All dependencies (dev tools, torch, jax, lightgbm):
333
- pip install -e ".[all]"
334
- ```
335
-
336
- *Note*: `matplotlib` is a core dependency, while `plotly` and `ipython` live
337
- in the `[notebook]` extra (`pip install codegen_classroom[notebook]`).
338
- `lightgbm` is the approved gradient boosting framework; `xgboost` is not
339
- supported.
303
+ ## Installation
340
304
 
341
- 4. **Configure Environment Variables**: Copy `.env.example` to `.env` and fill
342
- in your `GEMINI_API_KEY`.
305
+ Requires Python 3.9+ and a [`GEMINI_API_KEY`](https://ai.google.dev/gemini-api/docs/api-key):
343
306
 
344
- ```bash
345
- cp .env.example .env
346
- ```
347
-
348
- 5. **Run Tests**: Verify the local installation by running the test suite:
349
-
350
- ```bash
351
- pytest
352
- ```
353
-
354
- 6. **Set up the Colab/Jupyter Kernel** (optional):
355
-
356
- ```bash
357
- pip install ipykernel
358
- python -m ipykernel install --user --name=codegen-classroom --display-name "Python (Codegen Classroom)"
359
- ```
307
+ ```bash
308
+ # 1. Create and activate a virtual environment
309
+ python3 -m venv .venv
310
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
311
+
312
+ # 2. Install from PyPI
313
+ pip install codegen-classroom
314
+ # Or latest from Github: pip install "codegen-classroom @ git+https://github.com/google-research/codegen-classroom.git"
315
+
316
+ # Optional extras:
317
+ pip install "codegen-classroom[lightgbm]" # LightGBM
318
+ pip install "codegen-classroom[notebook]" # Plotly and IPython for notebooks
319
+ pip install "codegen-classroom[torch]" # PyTorch and TorchVision
320
+ pip install "codegen-classroom[jax]" # JAX
321
+ pip install "codegen-classroom[all]" # All optional dependencies and pytest
322
+
323
+ # 3. Configure GEMINI_API_KEY
324
+ export GEMINI_API_KEY="your-api-key" # Or copy .env.example to .env
325
+ ```
360
326
 
361
327
  --------------------------------------------------------------------------------
362
328
 
363
329
  ## Quickstart
364
330
 
365
- The core library provides a modular agent loop that can be imported and
366
- customized for any scorable machine learning or data science task.
331
+ Run an iterative classroom loop on any custom `pandas` dataset:
367
332
 
368
333
  ```python
369
334
  import os
370
- from codegen_classroom import agent_config
371
335
  from codegen_classroom import agents
372
336
  from codegen_classroom import student_learning
373
337
  import pandas as pd
@@ -383,7 +347,7 @@ y_test = pd.DataFrame({"target": [14.0]})
383
347
  # 2. Configure student agents
384
348
  student_configs = student_learning.get_classroom_student_configs(
385
349
  system_instruction="You are an expert ML engineer.",
386
- model_names=["gemini-2.5-flash"],
350
+ model_names=["gemini-3.5-flash"],
387
351
  api_key=os.environ.get("GEMINI_API_KEY"),
388
352
  )
389
353
  classroom = [agents.StudentAgent(cfg) for cfg in student_configs]
@@ -394,7 +358,7 @@ Write a python function `solution(x_train, y_train, x_val)` that trains a regres
394
358
  model on (x_train, y_train) and returns predictions on x_val as a pandas DataFrame with column 'target'.
395
359
  """
396
360
  for cycle in range(3):
397
- results = student_learning.run_parallel_classroom_learning_cycle(
361
+ student_learning.run_parallel_classroom_learning_cycle(
398
362
  current_classroom=classroom,
399
363
  x_train=x_train,
400
364
  y_train=y_train,
@@ -426,68 +390,99 @@ print("Final evaluation completed:", eval_results)
426
390
 
427
391
  --------------------------------------------------------------------------------
428
392
 
429
- ## Library Structure
430
-
431
- The core library is organized into the following modules:
432
-
433
- * [agent_config.py](./codegen_classroom/agent_config.py): Global configuration
434
- defaults for models, generation parameters, and execution timeouts.
435
- * [agents.py](./codegen_classroom/agents.py): Defines the `StudentAgent`,
436
- including **state management** (`best_score`, `best_solution`), **refinement
437
- logic**, and **mutation strategies** (self-reflection, peer crossover).
438
- * [code_execution.py](./codegen_classroom/code_execution.py): Handles
439
- **extraction of Python code** blocks from LLM responses and **executes the
440
- code** in a sandboxed environment, capturing `stdout`, `stderr`, and
441
- results.
442
- * [data_utils.py](./codegen_classroom/data_utils.py): Helpers for **data
443
- loading**, generic file operations via `etils.epath`, **run ID generation**,
444
- and local leaderboard tracking.
445
- * [metrics.py](./codegen_classroom/metrics.py): Contains definitions for
446
- individual **performance metrics** (e.g., MAE, R², Pearson, Worst-Group
447
- Accuracy), including computation and **normalization logic**.
448
- * [plotting.py](./codegen_classroom/plotting.py): Progress and final
449
- evaluation charts using Matplotlib (headless image export) or Plotly
450
- (interactive notebooks).
451
- * [reporting.py](./codegen_classroom/reporting.py): Centralized logging setup,
452
- markdown table rendering with configurable decimal precision,
453
- `ReportSection` structured models, and dual sinks: interactive inline
454
- display and disk export (`report.md`).
455
- * [scoring.py](./codegen_classroom/scoring.py): Implements **solution
456
- validation** (e.g., checking prediction shapes, NaNs) and calculates the
457
- overall **weighted score** based on metrics.
458
- * [student_learning.py](./codegen_classroom/student_learning.py):
459
- **Orchestrates** the entire agent learning process. Contains the main
460
- `run_learning_cycle` function and helpers to **run agents in parallel** and
461
- perform final evaluations across strategies (`first`, `last`, `best`).
462
- * [tasks/](./codegen_classroom/tasks/): Domain-specific benchmark suites and
463
- reference scaffolding. See the
464
- [Task Authoring Guide](./codegen_classroom/tasks/AGENTS.md) and the
465
- [canonical template task](./codegen_classroom/tasks/template/).
466
-
467
- --------------------------------------------------------------------------------
393
+ ## Tasks
468
394
 
469
- ## Benchmark Tasks
395
+ Self-contained benchmark suites live under
396
+ [`codegen_classroom/tasks/<task>/`](./codegen_classroom/tasks/). Each task
397
+ includes a shared configuration (`config.py`), dataset loader
398
+ (`data_loader.py`), headless runner (`run_<task>.py`), unit tests
399
+ (`run_<task>_test.py`), companion notebook (`<task>.ipynb`), `leaderboard.tsv`,
400
+ and archived top solutions (`solutions/`).
470
401
 
471
- Each benchmark task under
472
- [`codegen_classroom/tasks/<task>/`](./codegen_classroom/tasks/) is a
473
- self-contained package providing a shared configuration and prompt module
474
- (`config.py`), a dataset loader (`data_loader.py`), a headless runner
475
- (`run_<task>.py`), unit tests (`run_<task>_test.py`), a companion notebook
476
- (`<task>.ipynb`), a `leaderboard.tsv`, and archived top solutions
477
- (`solutions/`).
402
+ | Task | Summary | Notebook |
403
+ | :--- | :--- | :---: |
404
+ | [`housing`](./codegen_classroom/tasks/housing/) *(California Housing Prices)* | California housing price tabular regression (`N = 20,433`, 12 features) scored on R², MAPE, Pearson, and runtime. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/google-research/codegen-classroom/blob/main/codegen_classroom/tasks/housing/housing.ipynb) |
405
+ | [`template`](./codegen_classroom/tasks/template/) *(Thermal Load Prediction)* | Synthetic multi-regime thermal load regression template (`N = 1,500`, 10 features) scored on R², MAE, and runtime. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/google-research/codegen-classroom/blob/main/codegen_classroom/tasks/template/task_example.ipynb) |
478
406
 
479
407
  ```bash
480
408
  # Run a benchmark task headlessly:
481
409
  python -m codegen_classroom.tasks.template.run_template
482
410
 
483
- # Verify a single task or all tasks before contributing:
411
+ # Verify a single task or all tasks:
484
412
  python -m codegen_classroom.verify_task --task template --strict
485
413
  python -m codegen_classroom.verify_task --all
486
414
  ```
487
415
 
488
- To create a new benchmark task, copy
489
- [`tasks/template/`](./codegen_classroom/tasks/template/) and follow
490
- [`tasks/AGENTS.md`](./codegen_classroom/tasks/AGENTS.md).
416
+ A normal run (without `--mock_students`) ends by running the held-out final
417
+ evaluation, writing `report.md` and saved predictions to the run directory,
418
+ appending a row to the task's `leaderboard.tsv`, and exporting the top runs to
419
+ `solutions/`. `--report_only=<run_dir|latest>` only rebuilds `report.md` for an
420
+ existing run and never re-executes student code.
421
+
422
+ To add a new benchmark task, copy
423
+ [`tasks/template/`](./codegen_classroom/tasks/template/) or prompt a coding
424
+ agent with [`tasks/AGENTS.md`](./codegen_classroom/tasks/AGENTS.md) to scaffold
425
+ one end-to-end.
426
+
427
+ --------------------------------------------------------------------------------
428
+
429
+ ## Classroom Learning Method
430
+
431
+ Each RSI cycle evolves parallel **Student Agents** across four stages:
432
+
433
+ 1. **Generate, Self-Debug, and Execute**: Each student writes a Python
434
+ `solution(x_train, y_train, x_val)` function executed in a timed sandbox,
435
+ automatically repairing runtime or output contract errors before returning
436
+ predictions and diagnostic `feedback` (e.g., CV scores or feature
437
+ importances).
438
+ 2. **Multi-Objective Scoring**: Predictions are evaluated against weighted task
439
+ metrics (e.g., R², MAPE, Macro-F1) and execution time, updating each
440
+ student's `best_score` and `best_solution`.
441
+ 3. **Guided Refinement and Peer Crossover**: Students refine their code using
442
+ domain prompts and self-logged `feedback`. After `max_mutation_count`
443
+ stagnant cycles, a student applies a **Mutation Strategy**:
444
+ * `SELF_BEST_CODE`: Re-anchors on the student's own best solution.
445
+ * `BEST_PEER_CROSSOVER` / `BEST_PEER_REPLACEMENT`: Adopts feature
446
+ engineering and modeling ideas from top-scoring peers.
447
+ * `CONTRASTIVE_PEER_CROSSOVER`: Contrasts top peer solutions against
448
+ weaker attempts to combine winning patterns and avoid failure modes.
449
+ 4. **Final Evaluation and Analysis**: Each student's `first`, `last`, and
450
+ `best` validation solutions are retrained on the full learning split and
451
+ evaluated once on the held-out test set, while `SolutionAnalysisAgent`
452
+ synthesizes results into `report.md` and `leaderboard.tsv`.
453
+
454
+ --------------------------------------------------------------------------------
455
+
456
+ ## Library Structure
457
+
458
+ * [agent_config.py](./codegen_classroom/agent_config.py): Default model
459
+ configurations, generation parameters, pricing, environment resolution, and
460
+ execution timeouts.
461
+ * [agents.py](./codegen_classroom/agents.py): `StudentAgent` and
462
+ `SolutionAnalysisAgent` state management, token/cost tracking, refinement
463
+ prompts, and peer mutation strategies.
464
+ * [code_execution.py](./codegen_classroom/code_execution.py): Python code
465
+ extraction and timed subprocess execution capturing `stdout`, `stderr`, and
466
+ return values.
467
+ * [data_utils.py](./codegen_classroom/data_utils.py): Data loading, file
468
+ operations (`etils.epath`), run ID generation, and `leaderboard.tsv`
469
+ tracking.
470
+ * [metrics.py](./codegen_classroom/metrics.py): Performance metrics (MAE, R²,
471
+ Pearson, Macro-F1, Worst-Group Accuracy) and score normalization.
472
+ * [plotting.py](./codegen_classroom/plotting.py): Progress and final
473
+ evaluation plots via Matplotlib (headless PNG export) or Plotly (notebooks).
474
+ * [reporting.py](./codegen_classroom/reporting.py): Structured logging,
475
+ Markdown table formatting, and report export (`report.md`).
476
+ * [scoring.py](./codegen_classroom/scoring.py): Prediction validation (shape,
477
+ index, NaN checks) and weighted composite scoring.
478
+ * [student_learning.py](./codegen_classroom/student_learning.py): Parallel
479
+ classroom cycle orchestration and final test evaluation across `first`,
480
+ `last`, and `best` strategies.
481
+ * [verify_task.py](./codegen_classroom/verify_task.py): Automated structural,
482
+ notebook, solution report, and prompt hygiene verifier.
483
+ * [tasks/](./codegen_classroom/tasks/): Benchmark task suites,
484
+ [Task Authoring Guide](./codegen_classroom/tasks/AGENTS.md), and
485
+ [canonical template](./codegen_classroom/tasks/template/).
491
486
 
492
487
  --------------------------------------------------------------------------------
493
488
 
@@ -497,5 +492,4 @@ To create a new benchmark task, copy
497
492
 
498
493
  The agents powered by Gemini are experimental and may generate inaccurate,
499
494
  hallucinated, or unoptimized code. Always execute the agent loop inside a
500
- sandboxed environment (like Google Colab) to prevent unexpected side effects
501
- from code execution.
495
+ sandboxed environment to prevent unexpected side effects from code execution.
@@ -0,0 +1,231 @@
1
+ # Codegen Classroom 🎓
2
+
3
+ ### A framework for iterative code generation for ML and data analysis tasks using parallel LLM agents.
4
+
5
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/google-research/codegen-classroom/blob/main/codegen_classroom/tasks/template/task_example.ipynb)
6
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
7
+ [![Gemini API](https://img.shields.io/badge/Gemini-API-8E75B2.svg)](https://ai.google.dev/gemini-api/docs)
8
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
9
+ [![GitHub Stars](https://img.shields.io/github/stars/google-research/codegen-classroom?style=social)](https://github.com/google-research/codegen-classroom/stargazers)
10
+
11
+ **Authors:** [Jake Garrison](mailto:jakegarrison@google.com),
12
+ [Zhihan Zhang](mailto:zzhihan@cs.washington.edu),
13
+ [Deon Kouatchou](mailto:deonkouatchou@google.com),
14
+ [Girish Narayanswamy](mailto:girishvn@google.com)
15
+
16
+ **Created:** August 2025
17
+
18
+ --------------------------------------------------------------------------------
19
+
20
+ ## Overview
21
+
22
+ Codegen Classroom **automates code generation** for tasks that can be scored
23
+ quantitatively (e.g., regression, classification, signal processing) using
24
+ **parallel [Gemini](https://ai.google.dev/gemini-api/docs/models) and
25
+ [Gemma](https://ai.google.dev/gemma) agents**.
26
+
27
+ Instead of single-shot prompting, multiple student agents **iteratively write,
28
+ execute, debug, and refine** Python solutions in a sandboxed **recursive
29
+ self-improvement (RSI)** loop. Agents learn from execution feedback (validation
30
+ scores, runtime errors, diagnostic metrics) and **collaborate via peer
31
+ crossover** to share high-performing ideas and escape local optima.
32
+
33
+ Whether you define the data splits and scoring metrics directly or prompt an
34
+ agent to set up the task, the classroom handles implementation and iterative
35
+ optimization.
36
+
37
+ --------------------------------------------------------------------------------
38
+
39
+ ## Installation
40
+
41
+ Requires Python 3.9+ and a [`GEMINI_API_KEY`](https://ai.google.dev/gemini-api/docs/api-key):
42
+
43
+ ```bash
44
+ # 1. Create and activate a virtual environment
45
+ python3 -m venv .venv
46
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
47
+
48
+ # 2. Install from PyPI
49
+ pip install codegen-classroom
50
+ # Or latest from Github: pip install "codegen-classroom @ git+https://github.com/google-research/codegen-classroom.git"
51
+
52
+ # Optional extras:
53
+ pip install "codegen-classroom[lightgbm]" # LightGBM
54
+ pip install "codegen-classroom[notebook]" # Plotly and IPython for notebooks
55
+ pip install "codegen-classroom[torch]" # PyTorch and TorchVision
56
+ pip install "codegen-classroom[jax]" # JAX
57
+ pip install "codegen-classroom[all]" # All optional dependencies and pytest
58
+
59
+ # 3. Configure GEMINI_API_KEY
60
+ export GEMINI_API_KEY="your-api-key" # Or copy .env.example to .env
61
+ ```
62
+
63
+ --------------------------------------------------------------------------------
64
+
65
+ ## Quickstart
66
+
67
+ Run an iterative classroom loop on any custom `pandas` dataset:
68
+
69
+ ```python
70
+ import os
71
+ from codegen_classroom import agents
72
+ from codegen_classroom import student_learning
73
+ import pandas as pd
74
+
75
+ # 1. Prepare training, validation, and held-out test splits
76
+ x_train = pd.DataFrame({"x1": [1.0, 2.0, 3.0, 4.0], "x2": [10.0, 20.0, 30.0, 40.0]})
77
+ y_train = pd.DataFrame({"target": [2.1, 4.2, 5.9, 8.1]})
78
+ x_val = pd.DataFrame({"x1": [5.0, 6.0], "x2": [50.0, 60.0]})
79
+ y_val = pd.DataFrame({"target": [10.2, 12.1]})
80
+ x_test = pd.DataFrame({"x1": [7.0], "x2": [70.0]})
81
+ y_test = pd.DataFrame({"target": [14.0]})
82
+
83
+ # 2. Configure student agents
84
+ student_configs = student_learning.get_classroom_student_configs(
85
+ system_instruction="You are an expert ML engineer.",
86
+ model_names=["gemini-3.5-flash"],
87
+ api_key=os.environ.get("GEMINI_API_KEY"),
88
+ )
89
+ classroom = [agents.StudentAgent(cfg) for cfg in student_configs]
90
+
91
+ # 3. Run iterative learning cycles
92
+ prompt = """
93
+ Write a python function `solution(x_train, y_train, x_val)` that trains a regression
94
+ model on (x_train, y_train) and returns predictions on x_val as a pandas DataFrame with column 'target'.
95
+ """
96
+ for cycle in range(3):
97
+ student_learning.run_parallel_classroom_learning_cycle(
98
+ current_classroom=classroom,
99
+ x_train=x_train,
100
+ y_train=y_train,
101
+ x_val=x_val,
102
+ y_val=y_val,
103
+ current_cycle=cycle,
104
+ student_initial_prompt=prompt,
105
+ student_function_name="solution",
106
+ metric_weights={"r2": 1.0},
107
+ early_stopping_patience=2,
108
+ student_refine_instruction_options=["Consider feature scaling or Ridge regression."],
109
+ max_mutation_count=2,
110
+ mutation_strategy_options=[agents.MutationStrategy.SELF_BEST_CODE],
111
+ code_execution_max_retries=1,
112
+ )
113
+
114
+ # 4. Final evaluation on held-out test data
115
+ eval_results, _ = student_learning.run_parallel_classroom_final_evaluation(
116
+ students={s.name: s for s in classroom},
117
+ x_learning=x_train,
118
+ y_learning=y_train,
119
+ x_test_final=x_test,
120
+ y_test_final=y_test,
121
+ student_function_name="solution",
122
+ metric_weights={"r2": 1.0},
123
+ )
124
+ print("Final evaluation completed:", eval_results)
125
+ ```
126
+
127
+ --------------------------------------------------------------------------------
128
+
129
+ ## Tasks
130
+
131
+ Self-contained benchmark suites live under
132
+ [`codegen_classroom/tasks/<task>/`](./codegen_classroom/tasks/). Each task
133
+ includes a shared configuration (`config.py`), dataset loader
134
+ (`data_loader.py`), headless runner (`run_<task>.py`), unit tests
135
+ (`run_<task>_test.py`), companion notebook (`<task>.ipynb`), `leaderboard.tsv`,
136
+ and archived top solutions (`solutions/`).
137
+
138
+ | Task | Summary | Notebook |
139
+ | :--- | :--- | :---: |
140
+ | [`housing`](./codegen_classroom/tasks/housing/) *(California Housing Prices)* | California housing price tabular regression (`N = 20,433`, 12 features) scored on R², MAPE, Pearson, and runtime. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/google-research/codegen-classroom/blob/main/codegen_classroom/tasks/housing/housing.ipynb) |
141
+ | [`template`](./codegen_classroom/tasks/template/) *(Thermal Load Prediction)* | Synthetic multi-regime thermal load regression template (`N = 1,500`, 10 features) scored on R², MAE, and runtime. | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/google-research/codegen-classroom/blob/main/codegen_classroom/tasks/template/task_example.ipynb) |
142
+
143
+ ```bash
144
+ # Run a benchmark task headlessly:
145
+ python -m codegen_classroom.tasks.template.run_template
146
+
147
+ # Verify a single task or all tasks:
148
+ python -m codegen_classroom.verify_task --task template --strict
149
+ python -m codegen_classroom.verify_task --all
150
+ ```
151
+
152
+ A normal run (without `--mock_students`) ends by running the held-out final
153
+ evaluation, writing `report.md` and saved predictions to the run directory,
154
+ appending a row to the task's `leaderboard.tsv`, and exporting the top runs to
155
+ `solutions/`. `--report_only=<run_dir|latest>` only rebuilds `report.md` for an
156
+ existing run and never re-executes student code.
157
+
158
+ To add a new benchmark task, copy
159
+ [`tasks/template/`](./codegen_classroom/tasks/template/) or prompt a coding
160
+ agent with [`tasks/AGENTS.md`](./codegen_classroom/tasks/AGENTS.md) to scaffold
161
+ one end-to-end.
162
+
163
+ --------------------------------------------------------------------------------
164
+
165
+ ## Classroom Learning Method
166
+
167
+ Each RSI cycle evolves parallel **Student Agents** across four stages:
168
+
169
+ 1. **Generate, Self-Debug, and Execute**: Each student writes a Python
170
+ `solution(x_train, y_train, x_val)` function executed in a timed sandbox,
171
+ automatically repairing runtime or output contract errors before returning
172
+ predictions and diagnostic `feedback` (e.g., CV scores or feature
173
+ importances).
174
+ 2. **Multi-Objective Scoring**: Predictions are evaluated against weighted task
175
+ metrics (e.g., R², MAPE, Macro-F1) and execution time, updating each
176
+ student's `best_score` and `best_solution`.
177
+ 3. **Guided Refinement and Peer Crossover**: Students refine their code using
178
+ domain prompts and self-logged `feedback`. After `max_mutation_count`
179
+ stagnant cycles, a student applies a **Mutation Strategy**:
180
+ * `SELF_BEST_CODE`: Re-anchors on the student's own best solution.
181
+ * `BEST_PEER_CROSSOVER` / `BEST_PEER_REPLACEMENT`: Adopts feature
182
+ engineering and modeling ideas from top-scoring peers.
183
+ * `CONTRASTIVE_PEER_CROSSOVER`: Contrasts top peer solutions against
184
+ weaker attempts to combine winning patterns and avoid failure modes.
185
+ 4. **Final Evaluation and Analysis**: Each student's `first`, `last`, and
186
+ `best` validation solutions are retrained on the full learning split and
187
+ evaluated once on the held-out test set, while `SolutionAnalysisAgent`
188
+ synthesizes results into `report.md` and `leaderboard.tsv`.
189
+
190
+ --------------------------------------------------------------------------------
191
+
192
+ ## Library Structure
193
+
194
+ * [agent_config.py](./codegen_classroom/agent_config.py): Default model
195
+ configurations, generation parameters, pricing, environment resolution, and
196
+ execution timeouts.
197
+ * [agents.py](./codegen_classroom/agents.py): `StudentAgent` and
198
+ `SolutionAnalysisAgent` state management, token/cost tracking, refinement
199
+ prompts, and peer mutation strategies.
200
+ * [code_execution.py](./codegen_classroom/code_execution.py): Python code
201
+ extraction and timed subprocess execution capturing `stdout`, `stderr`, and
202
+ return values.
203
+ * [data_utils.py](./codegen_classroom/data_utils.py): Data loading, file
204
+ operations (`etils.epath`), run ID generation, and `leaderboard.tsv`
205
+ tracking.
206
+ * [metrics.py](./codegen_classroom/metrics.py): Performance metrics (MAE, R²,
207
+ Pearson, Macro-F1, Worst-Group Accuracy) and score normalization.
208
+ * [plotting.py](./codegen_classroom/plotting.py): Progress and final
209
+ evaluation plots via Matplotlib (headless PNG export) or Plotly (notebooks).
210
+ * [reporting.py](./codegen_classroom/reporting.py): Structured logging,
211
+ Markdown table formatting, and report export (`report.md`).
212
+ * [scoring.py](./codegen_classroom/scoring.py): Prediction validation (shape,
213
+ index, NaN checks) and weighted composite scoring.
214
+ * [student_learning.py](./codegen_classroom/student_learning.py): Parallel
215
+ classroom cycle orchestration and final test evaluation across `first`,
216
+ `last`, and `best` strategies.
217
+ * [verify_task.py](./codegen_classroom/verify_task.py): Automated structural,
218
+ notebook, solution report, and prompt hygiene verifier.
219
+ * [tasks/](./codegen_classroom/tasks/): Benchmark task suites,
220
+ [Task Authoring Guide](./codegen_classroom/tasks/AGENTS.md), and
221
+ [canonical template](./codegen_classroom/tasks/template/).
222
+
223
+ --------------------------------------------------------------------------------
224
+
225
+ ## Disclaimer
226
+
227
+ **This is not an officially supported Google product.**
228
+
229
+ The agents powered by Gemini are experimental and may generate inaccurate,
230
+ hallucinated, or unoptimized code. Always execute the agent loop inside a
231
+ sandboxed environment to prevent unexpected side effects from code execution.
@@ -24,7 +24,7 @@ from codegen_classroom import reporting
24
24
  from codegen_classroom import scoring
25
25
  from codegen_classroom import student_learning
26
26
 
27
- __version__ = "0.1.0"
27
+ __version__ = "0.1.1"
28
28
 
29
29
  __all__ = [
30
30
  "__version__",