[FEAT] [TEST] [DOCS] Streaming Callback for Majority Voting - #1147
Conversation
Added streaming callback support to the majority voting agent.
| """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
Added an example demonstrating majority voting with a custom streaming callback function, including agent initialization and usage.
| 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
| # 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
There was a problem hiding this comment.
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
swarms/tests/structs/test_majority_voting.py
Lines 201 to 203 in e839dc5
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
swarms/swarms/structs/majority_voting.py
Lines 210 to 222 in e839dc5
📚 Documentation preview 📚: https://swarms--1147.org.readthedocs.build/en/1147/