CLI Configuration
This guide covers how to configure agents and swarms using YAML configuration files and environment variables.YAML Configuration
The Swarms CLI supports loading agent configurations from YAML files, allowing you to define complex agent setups and swarm architectures declaratively.Basic YAML Structure
A Swarms YAML configuration file has two main sections:agents- List of agent configurationsswarm_architecture(optional) - Swarm configuration
Agent Configuration
Single Agent Example
Multiple Agents Example
Swarm Architecture Configuration
You can define how agents work together using theswarm_architecture section:
Agent Configuration Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
agent_name | string | Yes | - | Unique name for the agent |
system_prompt | string | Yes | - | System prompt defining agent behavior |
model_name | string | No | ”gpt-4” | LLM model to use |
max_loops | integer | No | 1 | Maximum number of execution loops |
autosave | boolean | No | true | Enable automatic state saving |
dashboard | boolean | No | false | Enable agent dashboard |
verbose | boolean | No | false | Enable verbose logging |
dynamic_temperature_enabled | boolean | No | false | Enable dynamic temperature adjustment |
saved_state_path | string | No | null | Path to save agent state |
user_name | string | No | ”default_user” | Username associated with agent |
retry_attempts | integer | No | 3 | Number of retry attempts on failure |
context_length | integer | No | 100000 | Maximum context length |
return_step_meta | boolean | No | false | Return metadata for each step |
output_type | string | No | ”str” | Output format (“str” or “json”) |
task | string | No | null | Task for the agent to execute |
auto_generate_prompt | boolean | No | false | Auto-generate system prompts |
artifacts_on | boolean | No | false | Enable artifact generation |
artifacts_file_extension | string | No | ”.md” | File extension for artifacts |
artifacts_output_path | string | No | "" | Output path for artifacts |
Model Configuration
Within each agent, you can specify model parameters:Swarm Architecture Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the swarm |
description | string | Yes | Description of swarm purpose |
swarm_type | string | Yes | Type of swarm (e.g., “SequentialWorkflow”) |
max_loops | integer | No | Maximum loops for swarm execution |
task | string | No | Overall task for the swarm |
flow | object | No | Flow configuration for agent routing |
autosave | boolean | No | Enable swarm state autosave |
return_json | boolean | No | Return results in JSON format |
rules | string | No | Rules governing swarm behavior |
Running YAML Configurations
To execute agents from a YAML file:Environment Variables
The Swarms CLI uses environment variables for API keys and configuration.Required Environment Variables
At least one API key is required:Optional Environment Variables
Using .env Files
Create a.env file in your project root:
.env files from the current directory.
Environment Variable Priority
The CLI checks for API keys in this order:- Environment variables set in the current shell
- Variables from
.envfile in current directory - System-wide environment variables
Workspace Directory
TheWORKSPACE_DIR environment variable determines where agents store their outputs:
- If not set, some swarm operations will create a default workspace
- Agents will autosave state files to this directory
- Artifacts and outputs are stored here
Markdown Agent Configuration
You can also define agents using Markdown files with YAML frontmatter.Markdown Format
Loading Markdown Agents
Load a single agent:Configuration Best Practices
1. API Key Management
- Never commit API keys to version control
- Use
.envfiles (add to.gitignore) - Rotate keys regularly
- Use different keys for development and production
2. Agent Configuration
- Start with low temperature (0.1-0.3) for consistent outputs
- Use appropriate context lengths based on your use case
- Enable autosave for long-running agents
- Set retry attempts for production reliability
3. Swarm Configuration
- Define clear rules for agent collaboration
- Use descriptive names for agents and swarms
- Test with max_loops=1 before increasing
- Enable verbose mode during development
4. File Organization
Validation
Check Your Configuration
Verify your environment setup:- ✓ Python version (3.10+)
- ✓ Swarms installation
- ✓ API keys
- ✓ Dependencies
- ✓ .env file
- ✓ WORKSPACE_DIR
Test Agent Configuration
Test a YAML configuration:Example Configurations
Minimal Agent Config
Production Agent Config
Multi-Agent Swarm
Troubleshooting
Common Issues
Issue: “No API keys found”Next Steps
CLI Overview
Return to CLI overview and quick start
Commands Reference
Explore all available CLI commands