Refactor agent streaming behavior and update formatter panel title color

pull/933/head
harshalmore31 3 days ago
parent 20c3d8a19c
commit 50a69950f2

@ -3,10 +3,10 @@ from swarms import Agent
# Enable real-time streaming
agent = Agent(
agent_name="StoryAgent",
model_name="gpt-4o-mini",
streaming_on=True, # 🔥 This enables real streaming!
max_loops=1,
print_on=False, # By Default its False, raw streaming !!
model_name="gpt-4o-mini", # 🔥 This enables real streaming!
max_loops=4,
streaming_on=True,
print_on=True,
output_type="all",
)
@ -14,4 +14,4 @@ agent = Agent(
response = agent.run(
"Tell me a detailed story about Humanity colonizing the stars"
)
print(response)
# print(response)

@ -2518,13 +2518,8 @@ class Agent:
) and not isinstance(streaming_response, str):
# Check print_on parameter for different streaming behaviors
if self.print_on is False:
# Show raw streaming text without formatting panels
# Silent streaming - no printing, just collect chunks
chunks = []
print(
f"\n{self.agent_name}: ",
end="",
flush=True,
)
for chunk in streaming_response:
if (
hasattr(chunk, "choices")
@ -2533,11 +2528,7 @@ class Agent:
content = chunk.choices[
0
].delta.content
print(
content, end="", flush=True
) # Print raw streaming text
chunks.append(content)
print() # New line after streaming completes
complete_response = "".join(chunks)
else:
# Collect chunks for conversation saving
@ -2802,8 +2793,8 @@ class Agent:
return
if self.print_on is False:
# Show raw text without formatting panels
print(f"\n{self.agent_name}: {response}\n")
# Silent mode - no printing at all
return
else:
# Use formatted panels (default behavior when print_on=True)
formatter.print_panel(

@ -181,7 +181,7 @@ class Formatter:
def create_streaming_panel(text_obj, is_complete=False):
"""Create panel with proper text wrapping using Rich's built-in capabilities"""
panel_title = f"[bold cyan]{title}[/bold cyan]"
panel_title = f"[white]{title}[/white]"
if is_complete:
panel_title += " [bold green]✅[/bold green]"

Loading…
Cancel
Save