From cd66613dff49bb7209efc2ce00a9d83cc3387aa7 Mon Sep 17 00:00:00 2001 From: Aksh Parekh Date: Sun, 14 Sep 2025 00:49:36 -0700 Subject: [PATCH] cleaned up comments --- .../test_sequentialworkflow_streaming.py | 45 ++++--------------- swarms/structs/agent_rearrange.py | 5 --- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/examples/multi_agent/test_sequentialworkflow_streaming.py b/examples/multi_agent/test_sequentialworkflow_streaming.py index 310c9cc8..95fcf55d 100644 --- a/examples/multi_agent/test_sequentialworkflow_streaming.py +++ b/examples/multi_agent/test_sequentialworkflow_streaming.py @@ -1,17 +1,13 @@ from swarms.structs.agent import Agent from swarms.structs.sequential_workflow import SequentialWorkflow -def run_workflow_with_streaming_callback(task, streaming_callback): - """ - Run a sequential workflow with two agents and a streaming callback. - - Args: - task (str): The task to process through the workflow. - streaming_callback (callable): Function to handle streaming output. +def streaming_callback(token): + buffer.append(token) + if len(buffer) >= 20 or token.endswith("\n"): + print("".join(buffer), end="", flush=True) + buffer.clear() - Returns: - The final result from the workflow. - """ +def run_workflow_with_streaming_callback(task, streaming_callback): agent1 = Agent( name="Research Agent", @@ -55,34 +51,9 @@ def run_workflow_with_streaming_callback(task, streaming_callback): if __name__ == "__main__": -# ## REGULAR STREAMING CALLBACK -# def streaming_callback(token): -# print(token, end="", flush=True) - -# run_workflow_with_streaming_callback( -# task="What are the latest advancements in AI?", -# streaming_callback=streaming_callback, -# ) - + buffer = [] -# ## CUSTOM BUFFERING STREAMING_CALLBACK BASED ON DEV PREFERED -# buffer = [] -# def streaming_callback(token): -# buffer.append(token) -# # Print in bigger chunks (e.g., every 20 tokens or on final flush) -# if len(buffer) >= 20 or token.endswith("\n"): -# print("".join(buffer), end="", flush=True) -# buffer.clear() -# # Optionally, you could add a flush at the end of the run if needed - -# run_workflow_with_streaming_callback( -# task="What are the latest advancements in AI?", -# streaming_callback=streaming_callback, -# ) - - -## NO ADDED STREAMING_CALLBACK run_workflow_with_streaming_callback( task="What are the latest advancements in AI?", - streaming_callback=None, + streaming_callback=streaming_callback, ) \ No newline at end of file diff --git a/swarms/structs/agent_rearrange.py b/swarms/structs/agent_rearrange.py index 6480cb14..e691ef18 100644 --- a/swarms/structs/agent_rearrange.py +++ b/swarms/structs/agent_rearrange.py @@ -386,7 +386,6 @@ class AgentRearrange: for agent_name in agent_names: agent = self.agents[agent_name] - # Set agent.streaming_on if no streaming_callback if self.streaming_callback is not None: agent.streaming_on = True result = agent.run( @@ -398,7 +397,6 @@ class AgentRearrange: result = any_to_str(result) - # Call streaming callback with the result if provided if self.streaming_callback: self.streaming_callback(result) @@ -422,7 +420,6 @@ class AgentRearrange: agent = self.agents[agent_name] - # Add sequential awareness information for the agent awareness_info = ( self._get_sequential_awareness( agent_name, tasks @@ -436,7 +433,6 @@ class AgentRearrange: f"Added sequential awareness for {agent_name}: {awareness_info}" ) - # Set agent.streaming_on if no streaming_callback if self.streaming_callback is not None: agent.streaming_on = True current_task = agent.run( @@ -447,7 +443,6 @@ class AgentRearrange: ) current_task = any_to_str(current_task) - # Call streaming callback with the result if provided if self.streaming_callback: self.streaming_callback(current_task)