Skip to main content

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:
  1. agents - List of agent configurations
  2. swarm_architecture (optional) - Swarm configuration

Agent Configuration

Single Agent Example

Multiple Agents Example

Swarm Architecture Configuration

You can define how agents work together using the swarm_architecture section:

Agent Configuration Parameters

Model Configuration

Within each agent, you can specify model parameters:

Swarm Architecture Parameters

Running YAML Configurations

To execute agents from a YAML file:
With a custom file path:

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:
The Swarms CLI automatically loads .env files from the current directory.

Environment Variable Priority

The CLI checks for API keys in this order:
  1. Environment variables set in the current shell
  2. Variables from .env file in current directory
  3. System-wide environment variables

Workspace Directory

The WORKSPACE_DIR environment variable determines where agents store their outputs:
Default behavior:
  • 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
Directory structure example:

Markdown Agent Configuration

You can also define agents using Markdown files with YAML frontmatter.

Markdown Format

Loading Markdown Agents

Load a single agent:
Load all agents from a directory:
With concurrent processing:

Configuration Best Practices

1. API Key Management

  • Never commit API keys to version control
  • Use .env files (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:
This checks:
  • ✓ 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”
Issue: “YAML file not found”
Issue: “WORKSPACE_DIR not set”
Issue: “Invalid YAML format”

Next Steps

CLI Overview

Return to CLI overview and quick start

Commands Reference

Explore all available CLI commands

Resources