Skip to content

[FEAT] [TEST] [DOCS] Streaming Callback for Majority Voting - #1147

Merged
kyegomez merged 10 commits into
kyegomez:masterfrom
aparekh02:mvstream
Oct 31, 2025
Merged

[FEAT] [TEST] [DOCS] Streaming Callback for Majority Voting#1147
kyegomez merged 10 commits into
kyegomez:masterfrom
aparekh02:mvstream

Conversation

@aparekh02

@aparekh02 aparekh02 commented Oct 18, 2025

Copy link
Copy Markdown
Contributor

📚 Documentation preview 📚: https://swarms--1147.org.readthedocs.build/en/1147/

"""Wrapper for consensus agent streaming callback."""
try:
if chunk is not None and chunk.strip():
streaming_callback(consensus_agent_name, chunk, False)

Check failure

Code scanning / Pyre

Call error Error

Call error [29]: Optional[typing.Callable[[str, str, bool], None]] is not a function.
Comment thread tests/structs/test_majority_voting_streaming.py Fixed
Comment thread tests/structs/test_majority_voting_streaming.py Fixed
Comment thread tests/structs/test_majority_voting_streaming.py Fixed
Added an example demonstrating majority voting with a custom streaming callback function, including agent initialization and usage.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 18, 2025
@aparekh02 aparekh02 changed the title [FEAT] [TEST] Streaming Callback for Majority Voting [FEAT] [TEST] [DOCS] Streaming Callback for Majority Voting Oct 18, 2025
def streaming_callback(agent_name: str, chunk: str, is_final: bool):
# Chunk buffer static per call (reset each session)
if not hasattr(streaming_callback, "_buffer"):
streaming_callback._buffer = ""

Check failure

Code scanning / Pyre

Undefined attribute Error test

Undefined attribute [16]: Callable test_streaming_majority_voting.streaming_callback has no attribute _buffer.
# Chunk buffer static per call (reset each session)
if not hasattr(streaming_callback, "_buffer"):
streaming_callback._buffer = ""
streaming_callback._buffer_size = 0

Check failure

Code scanning / Pyre

Undefined attribute Error test

Undefined attribute [16]: Callable test_streaming_majority_voting.streaming_callback has no attribute _buffer_size.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.


Bug: Undefined Variable Causes Test Failure

The test_streaming_majority_voting function asserts majority_vote is not None, but majority_vote is never defined within its scope. This causes a NameError at runtime, likely a leftover from refactored test logic.

tests/structs/test_majority_voting.py#L201-L203

# Assert majority vote is correct
assert majority_vote is not None

Fix in Cursor Fix in Web


Bug: Consensus Streaming Callback Never Signals Completion

The consensus_streaming_callback in MajorityVoting.run always passes is_final=False to the user's callback. This means the user's callback is never notified when the consensus agent's streaming output is complete, which can prevent final output flushing or cleanup.

swarms/structs/majority_voting.py#L210-L222

if streaming_callback is not None:
def consensus_streaming_callback(chunk: str):
"""Wrapper for consensus agent streaming callback."""
try:
if chunk is not None and chunk.strip():
streaming_callback(consensus_agent_name, chunk, False)
except Exception as callback_error:
if self.verbose:
logger.warning(
f"[STREAMING] Callback failed for {consensus_agent_name}: {str(callback_error)}"
)
else:
consensus_streaming_callback = None

Fix in Cursor Fix in Web


@kyegomez
kyegomez merged commit f5b9544 into kyegomez:master Oct 31, 2025
7 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation structs tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT][Add Streaming Callbacks to MajorityVoting]

3 participants