The Ultimate Technical Guide to the Swarms CLI: A Step-by-Step Developer’s Guide
The definitive technical guide for using the Swarms Command Line Interface (CLI). The Swarms CLI enables developers, engineers, and business professionals to seamlessly manage and run Swarms of agents from the command line.
Welcome to the definitive technical guide for using the Swarms Command Line Interface (CLI). The Swarms CLI enables developers, engineers, and business professionals to seamlessly manage and run Swarms of agents from the command line. This guide will walk you through the complete process of installing, configuring, and using the Swarms CLI to orchestrate intelligent agents for your needs.
By following this guide, you will not only understand how to install and use the Swarms CLI but also learn about real-world use cases, including how the CLI is used to automate tasks across various industries, from finance to marketing, operations, and beyond.
Explore the official Swarms GitHub repository, dive into the comprehensive documentation at Swarms Docs, and explore the vast marketplace of agents on swarms.ai to kickstart your journey with Swarms!
1. Installing the Swarms CLI
Before we delve into Swarms CLI commands, let’s get it installed and running on your machine.
1.1. Installation Using pip
For most users, the simplest way to install the Swarms CLI is through pip:
pip3 install -U swarms
This command installs the latest version of the Swarms CLI package, ensuring that you have the newest features and fixes.
1.2. Installation Using Poetry
Alternatively, if you are using Poetry as your Python package manager, you can add the Swarms package like this:
poetry add swarms
Once installed, you can run the Swarms CLI directly using:
poetry run swarms help
This command shows all the available options and commands, as we will explore in-depth below.
2. Understanding Swarms CLI Commands
With the Swarms CLI installed, the next step is to explore its key functionalities. Here are the most essential commands:
2.1. onboarding: Setup Your Environment
The onboarding command guides you through setting up your environment and configuring the agents for your Swarms.
swarms onboarding
This is the first step when you begin working with the Swarms platform. It helps to:
2.2. help: Learn Available Commands
Running help displays the various commands you can use:
swarms help
This command will output a helpful list like the one shown below, including detailed descriptions of each command.
Swarms CLI - Help
Commands:
onboarding : Starts the onboarding process
help : Shows this help message
get-api-key : Retrieves your API key from the platform
check-login : Checks if you're logged in and starts the cache
read-docs : Redirects you to swarms cloud documentation
run-agents : Run your Agents from your agents.yaml
2.3. get-api-key: Access API Integration
One of the key functionalities of the Swarms platform is integrating your agents with the Swarms API. To retrieve your unique API key for communication, use this command:
swarms get-api-key
Your API key is essential to enable agent workflows and access various services through the Swarms platform.
2.4. check-login: Verify Authentication
Use the check-login command to verify if you're logged in and ensure that your credentials are cached:
swarms check-login
This ensures seamless operation, allowing agents to execute tasks securely on the Swarms platform without needing to log in repeatedly.
2.5. read-docs: Explore Official Documentation
Easily access the official documentation with this command:
swarms read-docs
You’ll be redirected to the Swarms documentation site, Swarms Docs, where you'll find in-depth explanations, advanced use-cases, and more.
领英推荐
2.6. run-agents: Orchestrate Agents
Perhaps the most important command in the CLI is run-agents, which allows you to execute your agents as defined in your agents.yaml configuration file.
swarms run-agents --yaml-file agents.yaml
If you want to specify a custom configuration file, just pass in the YAML file using the --yaml-file flag.
3. Working with the agents.yaml Configuration File
The agents.yaml file is at the heart of your Swarms setup. This file allows you to define the structure and behavior of each agent you want to run. Below is an example YAML configuration for two agents.
3.1. Example agents.yaml Configuration:
agents:
- agent_name: "Financial-Advisor-Agent"
model:
model_name: "gpt-4o-mini"
temperature: 0.3
max_tokens: 2500
system_prompt: |
You are a highly knowledgeable financial advisor with expertise in tax strategies, investment management, and retirement planning.
Provide concise and actionable advice based on the user's financial goals and situation.
max_loops: 1
autosave: true
dashboard: false
verbose: true
dynamic_temperature_enabled: true
saved_state_path: "financial_advisor_state.json"
user_name: "finance_user"
retry_attempts: 2
context_length: 200000
return_step_meta: false
output_type: "str"
task: "I am 35 years old with a moderate risk tolerance. How should I diversify my portfolio for retirement in 20 years?"
- agent_name: "Stock-Market-Analysis-Agent"
model:
model_name: "gpt-4o-mini"
temperature: 0.25
max_tokens: 1800
system_prompt: |
You are an expert stock market analyst with a deep understanding of technical analysis, market trends, and long-term investment strategies.
Provide well-reasoned investment advice, taking current market conditions into account.
max_loops: 2
autosave: true
dashboard: false
verbose: true
dynamic_temperature_enabled: false
saved_state_path: "stock_market_analysis_state.json"
user_name: "market_analyst"
retry_attempts: 3
context_length: 150000
return_step_meta: true
output_type: "json"
task: "Analyze the current market trends for tech stocks and suggest the best long-term investment options."
- agent_name: "Marketing-Strategy-Agent"
model:
model_name: "gpt-4o-mini"
temperature: 0.4
max_tokens: 2200
system_prompt: |
You are a marketing strategist with expertise in digital campaigns, customer engagement, and branding.
Provide a comprehensive marketing strategy to increase brand awareness and drive customer acquisition for an e-commerce business.
max_loops: 1
autosave: true
dashboard: false
verbose: true
dynamic_temperature_enabled: true
saved_state_path: "marketing_strategy_state.json"
user_name: "marketing_user"
retry_attempts: 2
context_length: 200000
return_step_meta: false
output_type: "str"
task: "Create a 6-month digital marketing strategy for a new eco-friendly e-commerce brand targeting millennial consumers."
- agent_name: "Operations-Optimizer-Agent"
model:
model_name: "gpt-4o-mini"
temperature: 0.2
max_tokens: 2000
system_prompt: |
You are an operations expert with extensive experience in optimizing workflows, reducing costs, and improving efficiency in supply chains.
Provide actionable recommendations to streamline business operations.
max_loops: 1
autosave: true
dashboard: false
verbose: true
dynamic_temperature_enabled: true
saved_state_path: "operations_optimizer_state.json"
user_name: "operations_user"
retry_attempts: 1
context_length: 200000
return_step_meta: false
output_type: "str"
task: "Identify ways to improve the efficiency of a small manufacturing company’s supply chain to reduce costs by 15% within one year."
3.2. Explanation of Key Fields
3.3. Running Agents Using agents.yaml
After configuring the agents, you can execute them directly from the CLI:
swarms run-agents --yaml-file agents_config.yaml
This command will run the specified agents, allowing them to perform their tasks and return results according to your configuration.
4. Use Cases for the Swarms CLI
Now that you have a solid understanding of the basic commands and the agents.yaml configuration, let's explore how the Swarms CLI can be applied in real-world scenarios.
4.1. Financial Data Analysis
For financial firms or hedge funds, agents like the "Financial-Analysis-Agent" can be set up to automate complex financial analyses. You could have agents analyze market trends, recommend portfolio adjustments, or perform tax optimizations.
Example Task: Automating long-term investment analysis using historical stock data.
swarms run-agents --yaml-file finance_analysis.yaml
4.2. Marketing Automation
Marketing departments can utilize Swarms agents to optimize campaigns, generate compelling ad copy, or provide detailed marketing insights. You can create a Marketing-Agent to process customer feedback, perform sentiment analysis, and suggest marketing strategies.
Example Task: Running multiple agents to analyze customer sentiment from recent surveys.
swarms run-agents --yaml-file marketing_agents.yaml
4.3. Operations and Task Management
Companies can create agents for automating internal task management. For example, you might have a set of agents responsible for managing deadlines, employee tasks, and progress tracking.
Example Task: Automating a task management system using Swarms agents.
swarms run-agents --yaml-file operations_agents.yaml
5. Advanced Usage: Customizing and Scaling Agents
The Swarms CLI is flexible and scalable. As your needs grow, you can start running agents across multiple machines, scale workloads dynamically, and even run multiple swarms in parallel.
5.1. Running Agents in Parallel
To run multiple agents concurrently, you can utilize different YAML configurations for each agent or group of agents. This allows for extensive scaling, especially when dealing with large datasets or complex workflows.
swarms run-agents --yaml-file agents_batch_1.yaml & swarms run-agents --yaml-file agents_batch_2.yaml &
5.2. Integration with Other Tools
The Swarms CLI integrates with many tools and platforms via APIs. You can connect Swarms with external platforms such as AWS, Azure, or your custom cloud setup for enterprise-level automation.
6. Conclusion and Next Steps
The Swarms CLI is a powerful tool for automating agent workflows in various industries, including finance, marketing, and operations. By following this guide, you should now have a thorough understanding of how to install and use the CLI, configure agents, and apply it to real-world use cases.
To further explore Swarms, be sure to check out the official Swarms GitHub repository, where you can contribute to the framework or build your own custom agents. Dive deeper into the documentation at Swarms Docs, and browse the extensive agent marketplace at swarms.ai.
With the Swarms CLI, the future of automation is within reach.