feat: add arun_stream and run_stream to HierarchicalSwarm - #1611
Merged
kyegomez merged 2 commits intoMay 28, 2026
Conversation
Bridge the existing callback-based streaming in run() to async/sync generators so HierarchicalSwarm can be consumed the same way as AgentRearrange and SequentialWorkflow. arun_stream(with_events=True) emits agent_start / token / agent_end structured events. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Steve-Dusty
force-pushed
the
feat/hierarchical-streaming
branch
from
May 13, 2026 21:41
b1021d1 to
eb8e7ff
Compare
Rewrite arun_stream to stream every phase of the hierarchical swarm: - Director plan tokens stream as produced - Workers stream with parallel interleaving via asyncio.Queue - Aggregator (feedback director / judge) streams its synthesis - with_events=True emits swarm_start, director_start/token/end, worker_start/token/end, aggregator_start/token/end, swarm_end - Every event tagged with role and loop index - Fix call_single_agent to enable streaming_on when callback provided Add 5 pytest tests covering plain streaming, event types, parallel interleaving, aggregator feedback, and token metadata. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
arun_stream(task, img, with_events)async generator toHierarchicalSwarmrun_stream(task, img, with_events)sync generator wrapperstreaming_callbackplumbing inrun()to generator-based streaming viaasyncio.Queuewith_events=Trueemits structuredagent_start/token/agent_enddicts (same format asAgentRearrangeandSequentialWorkflow)(agent_name, token)tuplesHow it works
arun_streamruns the existingself.run(streaming_callback=...)in a background thread. The callback pushes(agent_name, chunk, is_final)items to anasyncio.Queueviacall_soon_threadsafe. The async generator yields from the queue, accumulating chunks per agent to include the full output inagent_endevents.Parallel worker execution interleaves naturally since multiple threads push to the same queue concurrently.
Test plan
python3 -c "from swarms import HierarchicalSwarm; import inspect; print(inspect.signature(HierarchicalSwarm.arun_stream))"🤖 Generated with Claude Code
📚 Documentation preview 📚: https://swarms--1611.org.readthedocs.build/en/1611/