Beatsmith AI is an AI-powered music discovery assistant built with Cloudflare's Agent platform, powered by agents. You can discover new songs, find similar artists, and explore music through natural conversation with AI.
- Music discovery and recommendations
- Search Spotify tracks and artists
- Find similar songs using Last.fm data
- Discover related artists
- Get detailed track information
- Dark/Light theme support
- Real-time streaming responses
- State management and chat history
- Modern, responsive UI
- Cloudflare account
- OpenAI API key
- Spotify API credentials (Client ID and Client Secret)
- Last.fm API key
- Install dependencies:
npm install- Set up your environment:
Create a .dev.vars file:
OPENAI_API_KEY=your_openai_api_key
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
LASTFM_API_KEY=your_lastfm_api_keyTo get your API keys:
- OpenAI API Key: Sign up at OpenAI
- Spotify Credentials: Create an app at Spotify Developer Dashboard
- Last.fm API Key: Get an API key at Last.fm API
Note: The Spotify login system has been deprecated in the default implementation. However, if you want to enable user-specific features (such as accessing user's top tracks, playlists, or creating playlists), you will need to:
- Set up your own Spotify app in the Spotify Developer Dashboard
- Configure the redirect URI in your Spotify app settings to match your deployment URL (e.g.,
https://your-domain.workers.dev/callback) - Add yourself and any other users to the User Management section of your Spotify app
- Update the callback URL in
tools.tsto match your deployment - Users must be explicitly added to your Spotify app's user list before they can authenticate
Without setting up your own Spotify app with user management, only public Spotify features (search, track info, related artists) will be available.
- Run locally:
npm start- Deploy:
npm run deploy├── src/
│ ├── app.tsx # Chat UI implementation
│ ├── server.ts # Chat agent logic
│ ├── tools.ts # Tool definitions
│ ├── utils.ts # Helper functions
│ └── styles.css # UI styling
Beatsmith AI comes with the following music-related tools:
- Search Spotify Tracks - Search for songs and artists on Spotify
- Find Similar Songs - Discover tracks similar to a given song using Last.fm data
- Get Related Artists - Find artists similar to a given artist
- Get Track Information - Retrieve detailed metadata for any Spotify track
- Search Spotify Artist - Look up artist information by name or ID
Add new tools in tools.ts using the tool builder:
// Example of a tool that requires confirmation
const searchDatabase = tool({
description: "Search the database for user records",
inputSchema: z.object({
query: z.string(),
limit: z.number().optional()
})
// No execute function = requires confirmation
});
// Example of an auto-executing tool
const getCurrentTime = tool({
description: "Get current server time",
inputSchema: z.object({}),
execute: async () => new Date().toISOString()
});To handle tool confirmations, add execution functions to the executions object:
export const executions = {
searchDatabase: async ({
query,
limit
}: {
query: string;
limit?: number;
}) => {
// Implementation for when the tool is confirmed
const results = await db.search(query, limit);
return results;
}
// Add more execution handlers for other tools that require confirmation
};Tools can be configured in two ways:
- With an
executefunction for automatic execution - Without an
executefunction, requiring confirmation and using theexecutionsobject to handle the confirmed action. NOTE: The keys inexecutionsshould matchtoolsRequiringConfirmationinapp.tsx.
The starting server.ts implementation uses the ai-sdk and the OpenAI provider, but you can use any AI model provider by:
- Installing an alternative AI provider for the
ai-sdk, such as theworkers-ai-provideroranthropicprovider: - Replacing the AI SDK with the OpenAI SDK
- Using the Cloudflare Workers AI + AI Gateway binding API directly
For example, to use the workers-ai-provider, install the package:
npm install workers-ai-providerAdd an ai binding to wrangler.jsonc:
Replace the @ai-sdk/openai import and usage with the workers-ai-provider:
// server.ts
// Change the imports
- import { openai } from "@ai-sdk/openai";
+ import { createWorkersAI } from 'workers-ai-provider';
// Create a Workers AI instance
+ const workersai = createWorkersAI({ binding: env.AI });
// Use it when calling the streamText method (or other methods)
// from the ai-sdk
- const model = openai("gpt-4o-2024-11-20");
+ const model = workersai("@cf/deepseek-ai/deepseek-r1-distill-qwen-32b")Commit your changes and then run the agents-starter as per the rest of this README.
The chat interface is built with React and can be customized in app.tsx:
- Modify the theme colors in
styles.css - Add new UI components in the chat container
- Customize message rendering and tool confirmation dialogs
- Add new controls to the header
Try asking Beatsmith AI:
- "Find songs similar to Cruel Summer"
- "Find artists similar to The Weeknd"
- "Search for Taylor Swift on Spotify"
- "Get track information for [song name]"
- "What songs are similar to [track name]?"
You can extend Beatsmith AI by:
- Adding new music-related tools in
tools.ts - Customizing the UI for specific interactions in
app.tsx - Extending the agent's capabilities in
server.ts - Integrating additional music APIs (e.g., Apple Music, YouTube Music)
MIT