-
-
Notifications
You must be signed in to change notification settings - Fork 717
Add streaming support for autonomous loop summary generation and test⦠#1300
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
ZackBradshaw
wants to merge
1
commit into
kyegomez:master
Choose a base branch
from
ZackBradshaw:Steaming-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Test script to verify autonomous loop streaming support. | ||
|
|
||
| This script tests that streaming works correctly in all three phases: | ||
| 1. Planning Phase - should stream | ||
| 2. Execution Phase - should stream | ||
| 3. Summary Phase - should NOW stream (this was the fix) | ||
| """ | ||
|
|
||
| import sys | ||
| from swarms import Agent | ||
|
|
||
|
|
||
| def test_autonomous_loop_streaming(): | ||
| """Test autonomous loop with streaming enabled.""" | ||
|
|
||
| print("\n" + "="*80) | ||
| print("TESTING AUTONOMOUS LOOP WITH STREAMING SUPPORT") | ||
| print("="*80 + "\n") | ||
|
|
||
| # Create a streaming callback to collect tokens | ||
| collected_tokens = { | ||
| "planning_phase": [], | ||
| "execution_phase": [], | ||
| "summary_phase": [], | ||
| } | ||
|
|
||
| current_phase = "planning_phase" | ||
|
|
||
| def streaming_callback(token): | ||
| """Callback to receive streaming tokens.""" | ||
| # Print token for real-time feedback | ||
| if isinstance(token, dict): | ||
| # Handle token info dict from call_llm | ||
| if "token" in token: | ||
| print(token["token"], end="", flush=True) | ||
| collected_tokens[current_phase].append(token["token"]) | ||
| else: | ||
| # Handle plain string token | ||
| print(str(token), end="", flush=True) | ||
| collected_tokens[current_phase].append(str(token)) | ||
|
|
||
| try: | ||
| # Initialize agent with streaming enabled and max_loops="auto" | ||
| agent = Agent( | ||
| agent_name="StreamingTestAgent", | ||
| system_prompt="""You are a helpful assistant that provides clear, comprehensive responses. | ||
| When asked to plan, provide structured step-by-step plans. | ||
| When asked to execute, provide detailed execution results. | ||
| When asked to summarize, provide comprehensive summaries.""", | ||
| model_name="gpt-4o-mini", | ||
| max_loops="auto", | ||
| streaming_on=True, | ||
| verbose=False, # Reduce noise | ||
| print_on=False, | ||
| ) | ||
|
|
||
| # Test task that will trigger autonomous loop | ||
| task = """Please help me with the following: | ||
| 1. Create a plan for organizing a small tech conference | ||
| 2. Outline the key steps needed | ||
| 3. List important considerations | ||
|
|
||
| Then provide a comprehensive summary of everything discussed.""" | ||
|
|
||
| print(f"π Task: {task}\n") | ||
| print("-" * 80) | ||
| print("π¬ EXECUTING WITH AUTONOMOUS LOOP STREAMING...\n") | ||
|
|
||
| # Run agent with streaming callback | ||
| result = agent.run( | ||
| task=task, | ||
| streaming_callback=streaming_callback, | ||
| ) | ||
|
|
||
| print("\n" + "-" * 80) | ||
| print("\nβ EXECUTION COMPLETED!\n") | ||
|
|
||
| # Verify results | ||
| print("π STREAMING VERIFICATION REPORT:") | ||
| print("-" * 80) | ||
|
|
||
| phases_with_tokens = [] | ||
| phases_without_tokens = [] | ||
|
|
||
| for phase, tokens in collected_tokens.items(): | ||
| token_count = len(tokens) | ||
| if token_count > 0: | ||
| phases_with_tokens.append((phase, token_count)) | ||
| status = "β " | ||
| else: | ||
| phases_without_tokens.append(phase) | ||
| status = "β" | ||
|
|
||
| print(f"{status} {phase}: {token_count} tokens streamed") | ||
|
|
||
| print("\n" + "="*80) | ||
| if "summary_phase" in [p for p, _ in phases_with_tokens]: | ||
| print("β SUCCESS: Summary phase is NOW streaming!") | ||
| print(" The autonomous loop streaming fix is working correctly.") | ||
| else: | ||
| print("β ISSUE: Summary phase is still not streaming.") | ||
| print(" The fix may need additional investigation.") | ||
|
|
||
| print("="*80 + "\n") | ||
|
|
||
| # Show final result | ||
| print("π FINAL AGENT OUTPUT:") | ||
| print("-" * 80) | ||
| print(result) | ||
| print("-" * 80 + "\n") | ||
|
|
||
| return len(phases_without_tokens) == 0 | ||
|
|
||
| except Exception as e: | ||
| print(f"\nβ ERROR during test: {str(e)}") | ||
| import traceback | ||
| traceback.print_exc() | ||
| return False | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| success = test_autonomous_loop_streaming() | ||
| sys.exit(0 if success else 1) |
Oops, something went wrong.
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.
Check failure
Code scanning / Pyre
Undefined attribute Error