Skip to content

Adds API for streaming and iterating at the same time #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elijahbenizzy
Copy link
Contributor

@elijahbenizzy elijahbenizzy commented Apr 19, 2025

This allows us to iterate over streaming outputs. E.G. for deep-research mode.

See #360

Changes

  • Adds stream_iterate, astream_iterate
  • Adds tests

How I tested this

  • Unit tests

Notes

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

Important

Adds stream_iterate and astream_iterate methods for synchronous and asynchronous iteration over streaming outputs in Application.

  • New Functionality:
    • Adds stream_iterate and astream_iterate methods to Application in burr/core/application.py for synchronous and asynchronous iteration over streaming outputs.
  • Testing:
    • Adds tests for stream_iterate and astream_iterate in tests/core/test_application.py, covering cases of exhausting and not exhausting intermediate generators.
  • Enums:
    • Updates ExecuteMethod in burr/lifecycle/base.py to include stream_iterate and astream_iterate.

This description was created by Ellipsis for ff9564b. You can customize this summary. It will automatically update as commits are pushed.

Copy link

github-actions bot commented Apr 19, 2025

A preview of ff9564b is uploaded and can be seen here:

https://burr.dagworks.io/pull/532

Changes may take a few minutes to propagate. Since this is a preview of production, content with draft: true will not be rendered. The source is here: https://github.com/DAGWorks-Inc/burr/tree/gh-pages/pull/532/

This allows us to iterate over streaming outputs. E.G. for deep-research
mode.

See #360
@elijahbenizzy
Copy link
Contributor Author

RC version: pip install burr==0.40.0rc1

Docs:

@elijahbenizzy elijahbenizzy marked this pull request as ready for review April 27, 2025 17:12
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Changes requested ❌

Reviewed everything up to ff9564b in 3 minutes and 39 seconds. Click for details.
  • Reviewed 232 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 14 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. tests/core/test_application.py:1888
  • Draft comment:
    Redundant assertion: the length of post_stream_item_calls is checked twice for equality with 20. Consider removing one instance.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
2. tests/core/test_application.py:2044
  • Draft comment:
    Also duplicated assertion for post_stream_item_calls length (20) appears in test_iterate. Consider consolidating the duplicate check.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
3. tests/core/test_application.py:3560
  • Draft comment:
    Test for _remap_dunder_parameters is clear; ensure that for actions that expect mangling the implementation of __context is kept consistent. No immediate change needed, but maintain documentation on expected dunder mapping behavior.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
4. tests/core/test_application.py:3330
  • Draft comment:
    Tests of lifecycle hook execution and context passing are thorough. Consider adding inline comments in recursive action tests to clarify expected behavior.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
5. tests/core/test_application.py:3560
  • Draft comment:
    Tests for _remap_dunder_parameters using mangled names (e.g. ActionWithContextTracer) are very thorough. Consider adding a brief comment to clarify expected behavior for future readers.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
6. tests/core/test_application.py:3320
  • Draft comment:
    In test_application_does_not_allow_dunderscore_inputs, the error message is matched with 'double underscore'. Confirm that the regex precisely captures the intended error and consider clarifying the rationale in a comment.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
7. tests/core/test_application.py:3385
  • Draft comment:
    The recursive action test uses a comment 'Fork bomb!'. Although intentional, consider clarifying the base case and expected total count (63) in more detail for maintainability.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
8. tests/core/test_application.py:3646
  • Draft comment:
    In test__process_control_flow_params, sorting of the halt_after list is used to assert expected action names. Ensure that ordering is intentional; if order doesn’t matter, consider adding a clarifying comment.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
9. burr/lifecycle/base.py:15
  • Draft comment:
    Abstract hook classes are defined clearly. Consider adding docstrings or inline comments on the expected type of 'future_kwargs' to improve clarity for future maintainers.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
10. tests/core/test_application.py:3605
  • Draft comment:
    Overall, this test file is very comprehensive. Consider splitting the tests into smaller modules (e.g. sync vs async, remap functions, persister errors) to improve maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
11. tests/core/test_application.py:460
  • Draft comment:
    Typo: Remove the stray 'ß' in the comment that explains how the reducer deletes items.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
12. tests/core/test_application.py:1576
  • Draft comment:
    Typo: 'quicly' should be corrected to 'quickly' in the comment describing the test that uses inputs to speed up the stream.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
13. tests/core/test_application.py:954
  • Draft comment:
    Typo: Correct 'floating poit comparison problems' to 'floating point comparison problems'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
14. tests/core/test_application.py:2368
  • Draft comment:
    Typo: Replace 'steram' with 'stream' in the relevant comments.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_fKF73bXFd6WSw46f

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

assert len(stream_event_tracker.pre_start_stream_calls) == 2
assert len(stream_event_tracker.post_end_stream_calls) == 2
assert len(stream_event_tracker.post_stream_item_calls) == 20
assert len(stream_event_tracker.post_stream_item_calls) == 20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate assertion for stream_event_tracker.post_stream_item_calls appears twice (asserting length == 20). Consider removing the redundant check to avoid duplication.

Suggested change
assert len(stream_event_tracker.post_stream_item_calls) == 20

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Note that there are control-flow complexities involved here -- we need to ensure that the iterator
is properly pushed along and the prior streaming results containers are all finished before going to the next one.

:param halt_after: Action names/tags to halt before
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation typo: In the docstrings for both stream_iterate and astream_iterate, the descriptions of the parameters halt_after and halt_before are either swapped or incomplete (_description_). Please update them to clearly differentiate: halt_after should indicate which actions/tags cause the stream to halt after the action completes, and halt_before should indicate the actions/tags that, if encountered, halt the iteration before the action runs.

Suggested change
:param halt_after: Action names/tags to halt before
:param halt_after: Action names/tags to halt after the action completes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor

@skrawcz skrawcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix up docs and test nits.

@@ -1604,7 +1604,7 @@ async def astream_result(
which will be empty. Thus ``halt_after`` takes precedence -- if it is met, the streaming result container will contain the result of the
halt_after condition.

The :py:class:`AsyncStreamingResultContainer <burr.core.action.AsyncStreamingResultContainer>` is meant as a convenience -- specifically this allows for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the type annotation is async? is this supposed to be changed?

Comment on lines +1868 to +1871
:param halt_before: _description_, defaults to None
:param inputs: _description_, defaults to None
:return: _description_
:yield: _description_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

assert len(stream_event_tracker.pre_start_stream_calls) == 2
assert len(stream_event_tracker.post_end_stream_calls) == 2
assert len(stream_event_tracker.post_stream_item_calls) == 20
assert len(stream_event_tracker.post_stream_item_calls) == 20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate

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