Software Development Team with Hierarchical Coordination
This example demonstrates how to build a development team where a tech lead coordinates specialized engineers - perfect for complex projects requiring oversight and synthesis.Step 1: Get Your API Key
- Visit https://swarms.world/platform/api-keys
- Sign in or create an account
- Generate a new API key
- Set it as an environment variable:
Copy
export SWARMS_API_KEY="your-api-key-here"
Step 2: Setup
Copy
import requests
import os
API_BASE_URL = "https://api.swarms.world"
API_KEY = os.environ.get("SWARMS_API_KEY", "your_api_key_here")
headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json"
}
Step 3: Define Your Hierarchical Team
Create a development team with a tech lead (leader) coordinating 4 specialist engineers (workers):Copy
def design_auth_system(requirements: str) -> dict:
"""Design an authentication system using a hierarchical development team."""
swarm_config = {
"name": "Software Development Team",
"description": "Hierarchical team with tech lead coordinating specialists",
"swarm_type": "HierarchicalSwarm",
"task": requirements,
"agents": [
{
"agent_name": "Tech Lead",
"description": "Senior engineer coordinating the team",
"system_prompt": "You are a tech lead. Review all work from your team, make architectural decisions, identify gaps, and synthesize everything into a cohesive technical plan. Provide final recommendations.",
"model_name": "gpt-4o",
"max_loops": 1,
"temperature": 0.4
},
{
"agent_name": "Backend Engineer",
"description": "API and authentication specialist",
"system_prompt": "You are a backend engineer specializing in authentication. Design: API endpoints, authentication flow, token management, and session handling. Be specific and technical.",
"model_name": "gpt-4o",
"max_loops": 1,
"temperature": 0.5
},
{
"agent_name": "Database Engineer",
"description": "Database design expert",
"system_prompt": "You are a database engineer. Design: user table schema, indexes, relationships, and data security measures. Consider scalability and performance.",
"model_name": "gpt-4o",
"max_loops": 1,
"temperature": 0.3
},
{
"agent_name": "Security Engineer",
"description": "Application security specialist",
"system_prompt": "You are a security engineer. Identify: security requirements, encryption standards, vulnerability risks, and mitigation strategies. Focus on authentication security.",
"model_name": "gpt-4o",
"max_loops": 1,
"temperature": 0.3
},
{
"agent_name": "QA Engineer",
"description": "Testing strategy expert",
"system_prompt": "You are a QA engineer. Design: test strategy, test cases, edge cases, security tests, and performance tests for the authentication system.",
"model_name": "gpt-4o",
"max_loops": 1,
"temperature": 0.4
}
],
"max_loops": 1
}
response = requests.post(
f"{API_BASE_URL}/v1/swarm/completions",
headers=headers,
json=swarm_config,
timeout=120
)
return response.json()
Step 4: Run the Team
Copy
# Project requirements
requirements = """
Design a user authentication system with these requirements:
- OAuth2 + JWT tokens
- Support email/password and social login
- Two-factor authentication
- Password reset flow
- Session management
- Handle 10,000 concurrent users
"""
# Run the hierarchical team
result = design_auth_system(requirements)
# Display results
for output in result.get("output", []):
print(f"\n{'='*60}")
print(f"{output['role']}")
print('='*60)
# Handle content as string or list
content = output['content']
if isinstance(content, list):
content = ' '.join(str(item) for item in content)
print(str(content)[:400] + "...")
print(f"\nTotal cost: ${result['usage']['billing_info']['total_cost']:.4f}")
print(f"Execution time: {result['execution_time']:.1f}s")
Copy
============================================================
Tech Lead
============================================================
After reviewing all team inputs, here's our unified authentication system design:
**Architecture Decision:** OAuth2 with JWT access tokens (15min) and refresh tokens (7 days)
**Database:** PostgreSQL with proper indexing on email/user_id
**Security:** bcrypt (cost 12), rate limiting, 2FA via TOTP
**API:** RESTful endpoints with /auth prefix
**Testing:** 85% coverage target, load testing for 10k users
[Detailed synthesis of all team inputs...]
============================================================
Backend Engineer
============================================================
API Endpoints:
POST /auth/register - Create new user account
POST /auth/login - Authenticate and issue tokens
POST /auth/refresh - Refresh access token
POST /auth/logout - Invalidate tokens
GET /auth/verify - Verify token validity
POST /auth/2fa/enable - Enable two-factor auth
POST /auth/2fa/verify - Verify 2FA code
...
============================================================
Database Engineer
============================================================
Schema Design:
users table:
- id (UUID, primary key)
- email (VARCHAR(255), unique index)
- password_hash (VARCHAR(255))
- email_verified (BOOLEAN, default false)
- created_at (TIMESTAMP)
- updated_at (TIMESTAMP)
Indexes:
- idx_users_email (unique)
- idx_users_created_at
...
============================================================
Security Engineer
============================================================
Security Requirements:
HIGH PRIORITY:
- Passwords: min 12 chars, require special characters
- bcrypt hashing with cost factor 12
- Rate limiting: 5 failed attempts = 15min lockout
- HTTPS only, no HTTP fallback
- JWT stored in httpOnly cookies
MEDIUM PRIORITY:
- 2FA via TOTP (Google Authenticator)
- Email verification required
...
============================================================
QA Engineer
============================================================
Testing Strategy:
Unit Tests (60% coverage):
- Password validation logic
- Token generation/verification
- Email validation
- 2FA code generation
Integration Tests (25% coverage):
- Full login flow
- Registration + verification
- Password reset flow
...
Total cost: $0.1132
Execution time: 42.5s
The leader agent (Tech Lead) receives outputs from all worker agents and synthesizes them into a cohesive plan. Design your leader’s prompt to emphasize coordination and synthesis.