Skip to content

alxTools/spotify-agent

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Spotify Agent

An AI-powered Spotify control agent that provides intelligent music queue management and natural language interaction with your Spotify account.

TypeScript OpenAI Agents MCP

Features

πŸ’¬ Natural Language Control

🎧 You: start auto queue please
πŸ€– Agent: Auto-queue started! Adding 4 songs every 10 minutes.

🎧 You: queue something by radiohead
πŸ€– Agent: I'll search for Radiohead and add it to your queue...

🎧 You: what's playing?
πŸ€– Agent: Currently playing "Everything In Its Right Place" by Radiohead

🎡 Auto-Queue

  • Pool Management: Fetches 50 songs from your library, uses 20, refreshes every 30 minutes
  • Anti-Repetition: Remembers your last 12 tracks to avoid musical dΓ©jΓ  vu
  • Seamless Experience: Adds 4 songs every 10 minutes for continuous playback

πŸ› οΈ System Commands

  • /help - Show available commands
  • /auto-queue - Start intelligent queue monitoring
  • /stop-queue - Stop auto-queue
  • /pool-stats - View song pool statistics
  • /history-songs - Show recent track history
  • /refresh-pool - Force refresh song pool

πŸ—£οΈ Natural Language Commands β€” All system commands can also be triggered using natural language:

Quick Start

Prerequisites

  • Node.js 18+
  • Spotify Premium account
  • Spotify Developer application
  • OpenAI API key
  • Spotify MCP Server (repo)

Installation

  1. Clone the required repositories
mkdir spotify-ai && cd spotify-ai
git clone https://github.com/hannasage/spotify-mcp-server.git
git clone https://github.com/hannasage/spotify-agent.git
  1. Setup the Spotify MCP Server

You'll also need to configure an app on the spotify developer dashboard to configure the Spotify MCP server.

cd spotify-mcp-server
cp spotify-config.example.json spotify-config.json
# Edit the contents with the required params
  1. Setup the Spotify Agent
cd ../spotify-agent
npm install
cp .env.example .env
  1. Configure environment variables
# Add to .env file
OPENAI_API_KEY=your_openai_api_key_here
SPOTIFY_MCP_PATH=../spotify-mcp-server/dist/index.js
  1. Run the agent
npm run build
npm start

First Experience

🎡 SPOTIFY AGENT
βœ… Multi-agent system ready! Spotify Assistant + Queue Manager + Command Router available.

🎧 You: start auto queue
🎯 Auto-queue monitor started! Will add 4 songs every 10 minutes.
🎡 ANA-LOG AUTO: Added 4 songs to queue
   β€’ "Paranoid Android" by Radiohead
   β€’ "Karma Police" by Radiohead  
   β€’ "Creep" by Radiohead
   β€’ "No Surprises" by Radiohead

Architecture

Enhanced Multi-Agent System

  • Spotify Assistant: Primary agent handling user interaction and music control with integrated tracing
  • Queue Manager: Specialized agent for intelligent music curation and queue management
  • Command Router: Routes natural language to appropriate tools and agents with performance monitoring
  • MCP Tool Call Interceptor: Real-time monitoring of all Spotify API interactions
  • Tool Call Tracer: Comprehensive agent execution tracking and performance analysis

Key Components

  • Song Pool Manager: Intelligent song selection from your library
  • Queue Monitor: Autonomous queue management with anti-repetition
  • History Tracker: Persistent track history to avoid repetition
  • Tool Registry: Modular system for extending functionality
  • Performance Evaluation: Real-time trace collection and system analysis
  • Tool Call Interceptor: Detailed MCP tool call monitoring and metrics

Technology Stack

  • OpenAI Agents SDK: Multi-agent orchestration
  • Model Context Protocol (MCP): AI-to-API communication
  • TypeScript: Type-safe development
  • Spotify Web API: Music control and library access
  • Evaluation System: Comprehensive performance tracking and analysis

Evaluation System

Performance Monitoring

The Spotify Agent includes a comprehensive evaluation system for tracking performance, accuracy, and user experience metrics:

# Run evaluations on collected trace data
npm run eval

# Example evaluation output:
πŸ“Š SPOTIFY AGENT EVALUATION REPORT
Session: session_2025_07_19_152437
Grade: A (Score: 92.3/100)

🎯 Performance Metrics:
β€’ Average Response Time: 1.2s
β€’ Tool Call Success Rate: 98.5%
β€’ Agent Execution Time: 850ms

🎡 Accuracy Metrics:
β€’ Command Routing: 94.2%
β€’ Playback Success: 96.8%
β€’ Query Relevance: 89.3%

πŸ‘€ User Experience:
β€’ Session Duration: 180s
β€’ Interactions: 12
β€’ Conversation Flow: 8.5/10

Trace Collection

Real-time monitoring captures detailed execution traces:

  • MCP Tool Calls: Spotify API interactions with timing and success rates
  • Agent Executions: Multi-agent coordination and decision-making
  • User Interactions: Input classification and response quality
  • System Health: Error rates, connection stability, and performance

Evaluation Dimensions

  • Routing: Input classification accuracy and agent selection
  • Tool Calls: MCP server interaction performance and reliability
  • Agents: Individual agent execution metrics and success rates
  • Interactions: User experience quality and conversation flow

Development

Project Structure

src/
β”œβ”€β”€ agents.ts          # Multi-agent configuration
β”œβ”€β”€ queueMonitor.ts    # Auto-queue management
β”œβ”€β”€ songPool.ts        # Intelligent song selection
β”œβ”€β”€ tools/             # Modular tool system
β”‚   β”œβ”€β”€ autoQueueTools.ts
β”‚   β”œβ”€β”€ poolTools.ts
β”‚   β”œβ”€β”€ historyTools.ts
β”‚   └── systemTools.ts
β”œβ”€β”€ evaluations/       # Performance evaluation system
β”‚   β”œβ”€β”€ evaluator.ts   # Comprehensive metrics analysis
β”‚   β”œβ”€β”€ schema.ts      # Evaluation data structures
β”‚   β”œβ”€β”€ cli.ts         # Evaluation CLI interface
β”‚   └── index.ts       # Evaluation system exports
β”œβ”€β”€ lib/               # Enhanced system libraries
β”‚   β”œβ”€β”€ toolCallTracer.ts      # Agent tool call tracing
β”‚   └── mcpToolCallInterceptor.ts  # MCP tool call monitoring
β”œβ”€β”€ ui.ts              # Rich CLI interface
└── types.ts           # TypeScript definitions

Available Scripts

npm run build          # Build TypeScript
npm run dev            # Development mode with auth
npm run debug          # Debug mode with verbose logging
npm start              # Production mode
npm run clean          # Clean build artifacts
npm run eval           # Run evaluation system on trace data

Development Features

  • Enhanced Debugging: Comprehensive trace collection with MCP tool call interception
  • Performance Monitoring: Real-time metrics on agent execution and tool call success rates
  • Evaluation Framework: Automated analysis of system performance with graded reports
  • Error Tracking: Detailed error capture and recovery analysis

Adding New Tools

  1. Create a new tool class extending BaseTool
  2. Register it in src/tools/registry.ts
  3. Add appropriate agent instructions
  4. Tool calls will be automatically traced and included in evaluation reports

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Areas for Contribution

  • Enhanced recommendation algorithms
  • Additional music service integrations
  • Web interface development
  • Mobile app development
  • Playlist generation features
  • Advanced evaluation metrics and analysis
  • Machine learning-based performance optimization
  • Custom trace collection and visualization tools

License

ISC License - see LICENSE file for details.

Acknowledgments


Made with ❀️ and modern AI development practices

About

An OpenAI-based agent for controlling Spotify.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • TypeScript 86.7%
  • JavaScript 13.3%