You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.2 KiB
2.2 KiB
Agent with Streaming
The Swarms framework provides powerful real-time streaming capabilities for agents, allowing you to see responses being generated token by token as they're produced by the language model. This creates a more engaging and interactive experience, especially useful for long-form content generation, debugging, or when you want to provide immediate feedback to users.
Installation
Install the swarms package using pip:
pip install -U swarms
Basic Setup
- First, set up your environment variables:
WORKSPACE_DIR="agent_workspace"
OPENAI_API_KEY=""
Step by Step
-
Install and put your keys in
.env
-
Turn on streaming in
Agent()
withstreaming_on=True
-
Optional: If you want to pretty print it, you can do
print_on=True
; if not, it will print normally
Code
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=True, # By default, it's False for raw streaming!
)
# This will now stream in real-time with a beautiful UI!
response = agent.run("Tell me a detailed story about humanity colonizing the stars")
print(response)
Connect With Us
If you'd like technical support, join our Discord below and stay updated on our Twitter for new updates!
Platform | Link | Description |
---|---|---|
📚 Documentation | docs.swarms.world | Official documentation and guides |
📝 Blog | Medium | Latest updates and technical articles |
💬 Discord | Join Discord | Live chat and community support |
@kyegomez | Latest news and announcements | |
The Swarm Corporation | Professional network and updates | |
📺 YouTube | Swarms Channel | Tutorials and demos |
🎫 Events | Sign up here | Join our community events |