Skip to content

feat: create Jupyter notebook pipeline file based on main.py file#1134

Merged
peteryang1 merged 21 commits intomicrosoft:mainfrom
pwang347:pawang/generateNotebook
Aug 5, 2025
Merged

feat: create Jupyter notebook pipeline file based on main.py file#1134
peteryang1 merged 21 commits intomicrosoft:mainfrom
pwang347:pawang/generateNotebook

Conversation

@pwang347
Copy link
Copy Markdown
Member

@pwang347 pwang347 commented Jul 31, 2025

Description

Add support for a NotebookConverter class associated with the Pipeline coder, which is enabled with the DS_ENABLE_NOTEBOOK_CONVERSION config. When the flag is enabled, additional prompt is passed to the Pipeline coder to add print statements in the main() function section which is used to properly split the .py file into .ipynb and re-attach outputs.

Motivation and Context

.ipynb files can be useful for debugging after the agent has completed its execution loops. With this change we can generate both useful .py files and a reasonably formatted .ipynb file at the same time.

Known Limitations

  • This currently relies on the fact that output stderr and stdout are approximately ordered using
    if self.conf.live_output:
    to reattach the outputs in sequence
  • All output is treated as stdout in the notebook, though this will result in different appearance to the actual run in notebook
  • We assume for now it is fine that the execution environment is not Jupyter, but this may be a follow-up item in the future

How Has This Been Tested?

  • If you are adding a new feature, test on your own test scripts.

Added unit tests in test/notebook/test_util.py

Screenshots of Test Results (if appropriate):

  1. Your own tests:
Test Outputs
(base) Pauls-MacBook-Pro:RD-Agent paulwang$ pytest test/notebook/test_util.py
=============================================================================================== test session starts ================================================================================================
platform darwin -- Python 3.11.0, pytest-8.4.1, pluggy-1.6.0
rootdir: /Users/paulwang/Desktop/tmp/RD-Agent
configfile: pyproject.toml
plugins: anyio-4.9.0, time-machine-2.16.0, typeguard-4.3.0
collected 47 items

test/notebook/test_util.py::TestExtractFunctionBody::test_empty PASSED
test/notebook/test_util.py::TestExtractFunctionBody::test_happy_path PASSED
test/notebook/test_util.py::TestExtractFunctionBody::test_happy_path_complex PASSED
test/notebook/test_util.py::TestExtractFunctionBody::test_missing_func PASSED
test/notebook/test_util.py::TestSplitCodeSections::test_empty PASSED
test/notebook/test_util.py::TestSplitCodeSections::test_happy_path PASSED
test/notebook/test_util.py::TestSplitCodeSections::test_happy_path_no_header PASSED
test/notebook/test_util.py::TestSplitCodeSections::test_no_sections PASSED
test/notebook/test_util.py::TestSplitCodeSections::test_single_no_sections PASSED
test/notebook/test_util.py::TestSplitCodeSections::test_single_with_section PASSED
test/notebook/test_util.py::TestSplitCodeSections::test_wrong_format PASSED
test/notebook/test_util.py::TestSplitOutputSections::test_empty PASSED
test/notebook/test_util.py::TestSplitOutputSections::test_happy_path PASSED
test/notebook/test_util.py::TestSplitOutputSections::test_happy_path_no_header PASSED
test/notebook/test_util.py::TestSplitOutputSections::test_no_sections PASSED
test/notebook/test_util.py::TestSplitOutputSections::test_single_no_sections PASSED
test/notebook/test_util.py::TestSplitOutputSections::test_single_with_section PASSED
test/notebook/test_util.py::TestSplitOutputSections::test_wrong_format PASSED
test/notebook/test_util.py::TestExtractSectionComments::test_arbitrary_print_happy_path PASSED
test/notebook/test_util.py::TestExtractSectionComments::test_empty_string PASSED
test/notebook/test_util.py::TestExtractSectionComments::test_happy_path PASSED
test/notebook/test_util.py::TestExtractSectionComments::test_happy_path_multiline PASSED
test/notebook/test_util.py::TestExtractSectionComments::test_no_comment PASSED
test/notebook/test_util.py::TestExtractFirstSectionNameFromCode::test_empty_string PASSED
test/notebook/test_util.py::TestExtractFirstSectionNameFromCode::test_happy_path PASSED
test/notebook/test_util.py::TestExtractFirstSectionNameFromCode::test_no_section PASSED
test/notebook/test_util.py::TestExtractFirstSectionNameFromOutput::test_empty_string PASSED
test/notebook/test_util.py::TestExtractFirstSectionNameFromOutput::test_happy_path PASSED
test/notebook/test_util.py::TestExtractFirstSectionNameFromOutput::test_no_section PASSED
test/notebook/test_util.py::TestIsFunctionCalled::test_empty_string PASSED
test/notebook/test_util.py::TestIsFunctionCalled::test_happy_path PASSED
test/notebook/test_util.py::TestIsFunctionCalled::test_happy_path_with_args PASSED
test/notebook/test_util.py::TestIsFunctionCalled::test_happy_path_with_args_multiline PASSED
test/notebook/test_util.py::TestIsFunctionCalled::test_not_called PASSED
test/notebook/test_util.py::TestIsFunctionCalled::test_wrong_format PASSED
test/notebook/test_util.py::TestRemoveFunction::test_empty PASSED
test/notebook/test_util.py::TestRemoveFunction::test_function_does_not_exist PASSED
test/notebook/test_util.py::TestRemoveFunction::test_happy_path PASSED
test/notebook/test_util.py::TestRemoveFunction::test_preserves_comments PASSED
test/notebook/test_util.py::TestRemoveMainBlock::test_block_does_not_exist PASSED
test/notebook/test_util.py::TestRemoveMainBlock::test_empty PASSED
test/notebook/test_util.py::TestRemoveMainBlock::test_happy_path PASSED
test/notebook/test_util.py::TestRemoveMainBlock::test_happy_path_arbitrary_content PASSED
test/notebook/test_util.py::TestRemoveMainBlock::test_one_liner PASSED
test/notebook/test_util.py::TestSplitCodeAndOutputIntoSections::test_empty_code PASSED
test/notebook/test_util.py::TestSplitCodeAndOutputIntoSections::test_empty_outputs PASSED
test/notebook/test_util.py::TestSplitCodeAndOutputIntoSections::test_happy_path PASSED

================================================================================================ slowest durations =================================================================================================

(141 durations < 0.005s hidden.  Use -vv to show these durations.)
================================================================================================ 47 passed in 0.09s ================================================================================================

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

📚 Documentation preview 📚: https://RDAgent--1134.org.readthedocs.build/en/1134/

@peteryang1 peteryang1 merged commit 2fa1790 into microsoft:main Aug 5, 2025
5 checks passed
licong01-cloud pushed a commit to licong01-cloud/RD-Agent that referenced this pull request Dec 13, 2025
…crosoft#1134)

* First commit

* isort

* black

* tweak prompt

* fix for argparse

* fix typo

* add e2e

* Add test files, clean

* fix black settings

* revert

* fix trailing

* remove extra

* comment

* small fix, updated prompt

* Fix argparse

* small improvements

* fix for merge

* fix for merge
yongbin4 pushed a commit to yongbin4/RD-Agent that referenced this pull request Mar 8, 2026
…crosoft#1134)

* First commit

* isort

* black

* tweak prompt

* fix for argparse

* fix typo

* add e2e

* Add test files, clean

* fix black settings

* revert

* fix trailing

* remove extra

* comment

* small fix, updated prompt

* Fix argparse

* small improvements

* fix for merge

* fix for merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants