A beginner-friendly AI agent system that combines Spotify music control with intelligent web search to create your ultimate music companion! This project demonstrates advanced AI concepts like multi-agent systems, tool integration, and Model Context Protocol (MCP) using Google's Agent Development Kit (ADK).
Imagine having a smart music friend who can:
- πΆ Control your Spotify: Search songs, create playlists, manage playback
- π Research music topics: Find artist biographies, album stories, music history
- π€ Work as a team: Multiple AI agents collaborate to give you the best experience
Instead of one "do-everything" AI, this project uses three specialized agents that work together - just like a real team where each member has expertise in different areas!
Think of this like a music store with specialists:
-
π΅ MusicFriendManager (The Receptionist):
- Talks to customers (you)
- Decides which specialist can help
- Coordinates everything
-
π§ SpotifySpecialist (The DJ):
- Expert at all Spotify operations
- Can search songs, make playlists, control playback
- Uses Spotify's official tools
-
π MusicInfoSpecialist (The Music Historian):
- Expert at finding music information online
- Researches artists, albums, music history
- Uses Google Search to find detailed info
Agents are AI programs that can:
- Think and make decisions
- Use tools (like searching the web or controlling apps)
- Communicate with other agents
- Complete tasks autonomously
Tools give agents superpowers! Examples:
- Spotify MCP Tool: Lets agents control Spotify
- Google Search Tool: Lets agents search the internet
- AgentTool: Lets one agent use another agent as a tool
MCP is like a universal translator that lets AI agents talk to external services:
- It's a standard way for AI to connect to apps like Spotify
- Handles authentication and communication
- Makes it easy to add new capabilities to agents
Instead of one giant AI trying to do everything:
- Divide and Conquer: Each agent specializes in specific tasks
- Collaboration: Agents work together and share information
- Scalability: Easy to add new specialists for new capabilities
- Maintainability: Easier to update or fix individual components
Before we begin, make sure you have:
- Python 3.8+ installed
- Basic terminal/command prompt knowledge
- A Spotify account (free or premium)
- A Google AI API key (we'll get this together)
The Spotify MCP is a separate service that handles all Spotify operations.
- Clone and set up the Spotify MCP:
# Navigate to your desktop or preferred directory
cd Desktop
# Clone the Spotify MCP repository
git clone https://github.com/varunneal/spotify-mcp.git
# Create a virtual environment (isolated Python environment)
python -m venv .venv
# Activate the virtual environment
# On Windows:
.venv\Scripts\activate
# On Mac/Linux:
source .venv/bin/activate
# Install the Spotify MCP
pip install -e .-
Create a Spotify App (to get API credentials):
- Go to Spotify Developer Dashboard
- Click "Create App"
- Fill in:
- App Name: "My Music Agent"
- App Description: "AI agent for music control"
- Redirect URI:
http://127.0.0.1:8080/callback
- Save your Client ID and Client Secret
-
Configure the Spotify MCP:
# Create environment file for secrets
echo "SPOTIFY_CLIENT_ID=your_client_id_here" > .env
echo "SPOTIFY_CLIENT_SECRET=your_client_secret_here" >> .env- Test the Spotify MCP:
# This should start the server without errors
python -m uv run spotify-mcp- Create your project directory:
cd Desktop
mkdir spotify-agent-demo
cd spotify-agent-demo- Create virtual environment for the main project:
python -m venv .venv
# Activate it
# Windows:
.venv\Scripts\activate
# Mac/Linux:
source .venv/bin/activate- Install Google ADK:
pip install google-adk-
Get your Google AI API key:
- Go to Google AI Studio
- Create a new API key
- Save it securely
-
Create the agent structure:
mkdir spotify-playlist-agent
cd spotify-playlist-agent- Create environment file:
echo "GOOGLE_GENAI_API_KEY=your_google_api_key_here" > .env- Copy the agent code:
- Create
agent.pywith the code from this repository - Make sure to update the paths in the code to match your setup
- Create
Let's break down the main agent.py file:
spotify_tools = MCPToolset(
connection_params=StdioConnectionParams(
server_params=StdioServerParameters(
command=r"path_to_your_spotify_mcp_python.exe",
args=["-m", "uv", "run", "spotify-mcp"],
working_dir=r"path_to_your_spotify_mcp_directory",
)
)
)What this does: Connects our agent to the Spotify MCP server we set up earlier.
spotify_specialist = LlmAgent(
name="SpotifySpecialist",
model="gemini-2.5-flash-lite",
instruction="You are a Spotify specialist...",
tools=[spotify_tools]
)What this does: Creates an AI agent that specializes in Spotify operations.
music_info_specialist = LlmAgent(
name="MusicInfoSpecialist",
model="gemini-2.5-flash-lite",
instruction="You are a music information specialist...",
tools=[google_search]
)What this does: Creates an AI agent that specializes in researching music information.
music_friend_manager = LlmAgent(
name="MusicFriendManager",
model="gemini-2.5-flash",
instruction="You are a friendly music assistant manager...",
tools=[
AgentTool(agent=spotify_specialist),
AgentTool(agent=music_info_specialist)
]
)What this does: Creates the main agent that coordinates between specialists.
- Start the agent:
# Make sure you're in the spotify-agent-demo directory
# and your virtual environment is activated
adk web-
Open your browser and go to
http://localhost:8000 -
Start chatting with your music agent!
You: "Play some jazz music" Agent: Uses SpotifySpecialist to search for jazz and start playback
You: "Tell me about Miles Davis" Agent: Uses MusicInfoSpecialist to search Google and provide detailed biography
You: "Play Kind of Blue by Miles Davis and tell me about the album" Agent: Uses SpotifySpecialist to play the album, then MusicInfoSpecialist to research its history
-
"Connection closed" error:
- Check that the Spotify MCP path is correct
- Make sure the Spotify MCP virtual environment is set up properly
-
"Invalid redirect URI":
- Add
http://127.0.0.1:8080/callbackto your Spotify app settings
- Add
-
"Google Search not working":
- Verify your Google AI API key is correct
- Check your internet connection
If you run into issues:
- Check the error messages carefully
- Verify all paths and API keys
- Make sure both virtual environments are properly activated
- Consult the ADK Documentation
By building this project, you'll learn:
- Multi-agent system design
- Tool integration patterns
- MCP protocol usage
- API authentication and configuration
- Virtual environment management
- Modern AI agent development practices
Once you have this working, try:
- Adding new specialists (e.g., a lyrics finder agent)
- Customizing agent personalities
- Adding more complex workflows
- Integrating with other music services
