|
|
|
@ -1,17 +1,11 @@
|
|
|
|
from typing import Callable
|
|
|
|
|
|
|
|
from swarms.structs.agent import Agent
|
|
|
|
from swarms.structs.agent import Agent
|
|
|
|
from swarms.structs.sequential_workflow import SequentialWorkflow
|
|
|
|
from swarms.structs.sequential_workflow import SequentialWorkflow
|
|
|
|
|
|
|
|
|
|
|
|
def create_streaming_callback() -> Callable[[str, str, bool], None]:
|
|
|
|
def streaming_callback(agent_name: str, chunk: str, is_final: bool):
|
|
|
|
"""
|
|
|
|
if chunk:
|
|
|
|
Create a streaming callback that prints each chunk as it arrives, with no duplication or timestamps.
|
|
|
|
print(chunk, end="", flush=True)
|
|
|
|
"""
|
|
|
|
if is_final:
|
|
|
|
def streaming_callback(agent_name: str, chunk: str, is_final: bool):
|
|
|
|
print()
|
|
|
|
if chunk:
|
|
|
|
|
|
|
|
print(chunk, end="", flush=True)
|
|
|
|
|
|
|
|
if is_final:
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
return streaming_callback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_agents():
|
|
|
|
def create_agents():
|
|
|
|
"""Create specialized agents for the workflow."""
|
|
|
|
"""Create specialized agents for the workflow."""
|
|
|
|
@ -37,9 +31,6 @@ def create_agents():
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|
print("🎯 SEQUENTIAL WORKFLOW STREAMING DEMO")
|
|
|
|
|
|
|
|
print("=" * 50)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
agents = create_agents()
|
|
|
|
agents = create_agents()
|
|
|
|
workflow = SequentialWorkflow(
|
|
|
|
workflow = SequentialWorkflow(
|
|
|
|
id="research_analysis_workflow",
|
|
|
|
id="research_analysis_workflow",
|
|
|
|
@ -53,19 +44,7 @@ if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
task = "What are the latest advancements in AI?"
|
|
|
|
task = "What are the latest advancements in AI?"
|
|
|
|
|
|
|
|
|
|
|
|
print(f"Task: {task.strip()}")
|
|
|
|
workflow.run(
|
|
|
|
|
|
|
|
|
|
|
|
streaming_callback = create_streaming_callback()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("\n🎬 EXECUTING WITH STREAMING CALLBACKS...")
|
|
|
|
|
|
|
|
print("Watch real-time agent outputs below:\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = workflow.run(
|
|
|
|
|
|
|
|
task=task,
|
|
|
|
task=task,
|
|
|
|
streaming_callback=streaming_callback,
|
|
|
|
streaming_callback=streaming_callback,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
print("\n🎉 EXECUTION COMPLETED!")
|
|
|
|
|
|
|
|
print("\n📊 FINAL RESULT:")
|
|
|
|
|
|
|
|
print("-" * 50)
|
|
|
|
|
|
|
|
print(result)
|
|
|
|
|