Skip to content

[IMPROVEMENT] Implement full streaming support in autonomous loop structure (max_loops='auto') #1297

@kyegomez

Description

@kyegomez

Summary

Fix and complete streaming support in the autonomous loop structure (max_loops="auto"). Currently, streaming works partially during planning and execution phases but does not work in the final summary phase, breaking the end-to-end streaming experience.

The autonomous loop structure in agent.py supports three phases:

  1. Planning Phase ✅ - Streaming works
  2. Execution Phase ✅ - Streaming works
  3. Summary Phase ❌ - Streaming does NOT work

When users enable streaming (streaming_on=True or stream=True) with max_loops="auto", they expect continuous token streaming throughout the entire autonomous loop. However, the final summary generation happens without streaming, causing an inconsistent user experience.

Current Behavior

from swarms import Agent

# User enables streaming with autonomous loop
agent = Agent(
    agent_name="TaskAgent",
    system_prompt="You are a helpful assistant",
    model_name="gpt-4",
    max_loops="auto",  # Autonomous loop enabled
    streaming_on=True,  # User expects streaming throughout
    verbose=True
)

def on_token(token):
    print(token, end="", flush=True)

# Run with streaming callback
result = agent.run(
    task="Create a comprehensive marketing plan",
    streaming_callback=on_token
)

# Result:
# ✅ Planning phase streams tokens
# ✅ Execution phase streams tokens
# ❌ Summary phase does NOT stream (silent until complete)

This improvement is essential for production-grade autonomous agents where real-time feedback and responsiveness are critical requirements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions