Basic Agent Creation
The simplest way to create an agent is to instantiate theAgent class with minimal configuration:
Agent Initialization Patterns
Pattern 1: Simple Agent
For quick prototyping and simple tasks:Pattern 2: Named Agent with Description
For better organization and clarity:Pattern 3: Agent with System Prompt
For specialized behavior and domain expertise:Pattern 4: Interactive Agent
For conversational interfaces:Pattern 5: Autonomous Agent
For complex, multi-step reasoning:Pattern 6: Agent with Fallback Models
For reliability and cost optimization:fallback_models is set, its first entry is the primary model and model_name is not used.
Pattern 7: Agent from Marketplace Prompt
Load prompts from the Swarms Marketplace:Pattern 8: Continue an Existing Conversation
Pass earlier turns asmessages. On the constructor they seed the conversation and are sent with every run. On run() they apply to that call and are added to the conversation.
Pattern 9: Several Answers to One Task
run(task, n=3) runs the task three times and returns a list with one output per run. Every run gets the same img, imgs, messages and streaming_callback. The runs share the agent’s conversation, so later runs see the earlier answers. Use output_type="final" so each entry holds only that run’s answer. With max_loops="auto", n is ignored and you get one output.
Best Practices
1. Always Name Your Agents
2. Use Descriptive System Prompts
3. Set Appropriate Max Loops
4. Enable Verbose Mode During Development
5. Use Autosave for Important Work
6. Set Environment Variables
Common Patterns
temperature defaults to None, which sends no temperature and uses the provider’s default. Set it only when you want to steer randomness, and leave it unset for models that reject a temperature value.Research Agent
Writing Agent
Code Generation Agent
Next Steps
Agent Configuration
Learn about all configuration parameters
Agent Memory
Configure memory and conversation history
Agent Tools
Add tools to extend agent capabilities
Structured Outputs
Get structured responses from agents
Token Usage
See what each run cost in tokens
Reference
For the complete API reference, see the Agent class documentation. Location in source:swarms/structs/agent.py:130 (class Agent); the constructor (__init__) starts at line 306.