Skip to main content
Learn how to create and run your first autonomous agent using the Swarms framework. An Agent is the fundamental building block of a swarm—an autonomous entity powered by an LLM + Tools + Memory.

Quick Start

Here’s the simplest way to create and run an agent:

Understanding the Code

Let’s break down each component:

1. Import the Agent Class

The Agent class is the core building block for creating autonomous agents in Swarms.

2. Initialize the Agent

Key Parameters:
  • model_name: The LLM to power your agent. Swarms supports OpenAI, Anthropic, Groq, Ollama, and more.
  • max_loops: Controls iteration behavior:
    • "auto": Agent decides when to stop based on task completion
    • Integer (e.g., 1, 5): Fixed number of iterations
  • interactive: When True, provides real-time feedback during execution

3. Run the Agent

The run() method executes the agent with your task and returns the response.

Example Output

When you run this agent, you’ll see output similar to:

Customizing Your Agent

Here’s a more customized example with additional configuration:

Additional Configuration Options

  • agent_name: A unique identifier for your agent
  • agent_description: Describes the agent’s purpose and capabilities
  • system_prompt: Instructions that define the agent’s behavior and personality
  • verbose: When True, shows detailed execution logs
  • output_type: Controls the format of the response ("str", "json", "dict", etc.)

Working with Different Models

Swarms supports multiple LLM providers:

Environment Setup

Make sure you have the required API keys set in your environment:
Or create a .env file:

Next Steps

Now that you’ve created your first agent, explore these advanced topics:

Common Patterns

Task-Specific Agent

Autonomous Agent with Auto Loops

Tips and Best Practices

  1. Start Simple: Begin with basic configurations and add complexity as needed
  2. Use Descriptive Names: Clear agent names and descriptions improve debugging
  3. Set Appropriate Loop Limits: Use max_loops=1 for simple tasks, higher values or "auto" for complex ones
  4. Monitor Costs: Be mindful of API costs when using max_loops="auto"
  5. Test Incrementally: Test your agent with simple tasks before moving to complex ones

Troubleshooting

Agent Not Responding

API Key Errors

Learn More