cleaned up comments

pull/1081/merge^2
Aksh Parekh 4 weeks ago
parent 83fae0070b
commit cd66613dff

@ -1,17 +1,13 @@
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 run_workflow_with_streaming_callback(task, streaming_callback): def streaming_callback(token):
""" buffer.append(token)
Run a sequential workflow with two agents and a streaming callback. if len(buffer) >= 20 or token.endswith("\n"):
print("".join(buffer), end="", flush=True)
Args: buffer.clear()
task (str): The task to process through the workflow.
streaming_callback (callable): Function to handle streaming output.
Returns: def run_workflow_with_streaming_callback(task, streaming_callback):
The final result from the workflow.
"""
agent1 = Agent( agent1 = Agent(
name="Research Agent", name="Research Agent",
@ -55,34 +51,9 @@ def run_workflow_with_streaming_callback(task, streaming_callback):
if __name__ == "__main__": if __name__ == "__main__":
# ## REGULAR STREAMING CALLBACK buffer = []
# 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,
# )
# ## 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( run_workflow_with_streaming_callback(
task="What are the latest advancements in AI?", task="What are the latest advancements in AI?",
streaming_callback=None, streaming_callback=streaming_callback,
) )

@ -386,7 +386,6 @@ class AgentRearrange:
for agent_name in agent_names: for agent_name in agent_names:
agent = self.agents[agent_name] agent = self.agents[agent_name]
# Set agent.streaming_on if no streaming_callback
if self.streaming_callback is not None: if self.streaming_callback is not None:
agent.streaming_on = True agent.streaming_on = True
result = agent.run( result = agent.run(
@ -398,7 +397,6 @@ class AgentRearrange:
result = any_to_str(result) result = any_to_str(result)
# Call streaming callback with the result if provided
if self.streaming_callback: if self.streaming_callback:
self.streaming_callback(result) self.streaming_callback(result)
@ -422,7 +420,6 @@ class AgentRearrange:
agent = self.agents[agent_name] agent = self.agents[agent_name]
# Add sequential awareness information for the agent
awareness_info = ( awareness_info = (
self._get_sequential_awareness( self._get_sequential_awareness(
agent_name, tasks agent_name, tasks
@ -436,7 +433,6 @@ class AgentRearrange:
f"Added sequential awareness for {agent_name}: {awareness_info}" f"Added sequential awareness for {agent_name}: {awareness_info}"
) )
# Set agent.streaming_on if no streaming_callback
if self.streaming_callback is not None: if self.streaming_callback is not None:
agent.streaming_on = True agent.streaming_on = True
current_task = agent.run( current_task = agent.run(
@ -447,7 +443,6 @@ class AgentRearrange:
) )
current_task = any_to_str(current_task) current_task = any_to_str(current_task)
# Call streaming callback with the result if provided
if self.streaming_callback: if self.streaming_callback:
self.streaming_callback(current_task) self.streaming_callback(current_task)

Loading…
Cancel
Save