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 at the schema level, but required in practice — see Running YAML Configurations) - Swarm configuration

Agent Configuration

Single Agent Example

swarm_architecture is required here — run-agents always runs through a SwarmRouter, so a YAML file with only an agents section will fail. See Running YAML Configurations below.

Multiple Agents Example

Swarm Architecture Configuration

You can define how agents work together using the swarm_architecture section:
Any extra key in swarm_architecture is passed to SwarmRouter as a keyword argument. Use this for router parameters such as rearrange_flow (required for AgentRearrange), output_type, or fallback_swarms:

Agent Configuration Parameters

The autosave, user_name, and context_length defaults above come from the YAML loader and differ from the Agent class defaults. The loader also accepts return_step_meta, artifacts_on, artifacts_file_extension, and artifacts_output_path, but Agent no longer has those parameters, so they have no effect. Any other key, such as temperature or max_tokens, is passed to Agent as a keyword argument; keys Agent does not recognize are silently ignored.

Model Configuration

Model parameters are flat, top-level fields on each agent entry — there is no nested model: block. A model: block is not rejected (extra fields are allowed), but it is silently ignored and has no effect on the agent:

Swarm Architecture Parameters

The loader also accepts flow, return_json, and rules, but SwarmRouter has no such parameters and ignores them. To set an AgentRearrange flow, use rearrange_flow.

Running YAML Configurations

To execute agents from a YAML file:
With a custom file path:
run-agents hardcodes return_type="run_swarm", so it always builds and runs a SwarmRouter. A YAML file that defines agents but omits swarm_architecture, or a swarm_architecture without a task, will fail — there is currently no standalone-agent mode for this command.

Environment Variables

The Swarms CLI uses environment variables for API keys and configuration.

Required Environment Variables

At least one provider key is required. swarms setup-check looks for one of these four, but any provider LiteLLM supports works for running agents (for example GROQ_API_KEY, XAI_API_KEY, or OPENROUTER_API_KEY):

Optional Environment Variables

See Telemetry for what tracing captures.

Using .env Files

Create a .env file in your project root:
The Swarms CLI automatically loads the nearest .env file, searching upward from the current directory. swarms init writes one for you.

Environment Variable Priority

Variables already set in your environment, whether exported in the shell or set system-wide, take precedence. The .env file only fills in variables that are not already set.

Workspace Directory

The WORKSPACE_DIR environment variable determines where agents store their outputs:
Default behavior:
  • If not set, importing Swarms sets it to ./agent_workspace and creates the directory
  • Agent state files are saved under agents/<agent-name>-<id>/
  • Logs are written to logs/
Directory structure example:
Not everything lives in the workspace: conversation files saved without an explicit path go to ./conversations/ in the current directory, and ~/.swarms/ only caches MCP OAuth tokens.

Markdown Agent Configuration

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

Markdown Format

The markdown loader reads only name, description, model_name (or model), temperature, max_loops, mcp_url, and streaming_on from the frontmatter. Other keys are ignored, and the body becomes the system prompt.

Loading Markdown Agents

Load a single agent:
In Swarms 15.0.3, passing a directory to --markdown-path fails with Unsupported file type. Load one file at a time.
--concurrent defaults to true and there is no --no-concurrent flag to disable it, so this flag is currently always on regardless of whether it’s passed.

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

  • Put collaboration rules in system prompts; the rules key is ignored
  • 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