Hi AI and tech friends, my name is Danar Mustafa. I write about product management focusing on AI, tech, business and strategy management. You can visit my Linkedin here. I am based in Sweden and founder of aiceostrategy.com – the leading AI maturity Model Matrix . Author of AI Agents: When AI Becomes part of your team.
Table of Contents
- Overview of what we’ll build
- Prerequisites & setup
- Step 1: Start your agent flow
- Step 2: Add a Guardrail node for input validation
- Step 3: Interpret user intent (If / Else logic)
- Step 4: Playlist generation logic (for each branch)
- Step 5: Merge back and output
- Step 6: (Optional) Asking follow-up or customizing
- Node summary & wiring
- Step 7: Prompt & instruction design in Agent node
- Step 8: Testing & iteration
- Step 9: Publishing & embedding
Below is a step-by-step guide (very explicit, so your customers can follow) to build a “Personalized DJ Agent” in Agent Builder (based on the video “Master ChatGPT Agent Builder Before It’s Too Late” The DJ agent will generate playlists (or recommend songs) for three modes: work, gym, and sleep. You can package this as a sellable guide.
I’ll break it into phases: setup, designing logic, implementing nodes, testing & refining, and publishing / embedding.
If you want, I can also format it nicely (with screenshots, checklists, etc.) for your product.
Overview of what we’ll build
- A ChatGPT-agent via Agent Builder that listens for user input like “create a work playlist”, “playlist for gym”, “sleep music please”, etc.
- It will route the user’s request to a playlist-generation logic, possibly using a music API (Spotify, Apple Music, etc.) via a connector (MCP) or via a custom function.
- It will return a list of song titles (or a playlist link) to the user.
- It will include safety/guardrails to avoid invalid inputs.
- We’ll provide room for customization (e.g. user’s preferred genres) via state.
Prerequisites & setup
Before starting in Agent Builder, ensure:
- OpenAI access & agent builder access
You must have access to Agent Builder in the OpenAI platform.- Access OpenAI Community
- Music API / Connector / MCP integration
To generate real playlists, you’ll need access to a music service API (e.g. Spotify Web API, Apple Music API, or a 3rd-party playlist service).- If Agent Builder supports an MCP connector for the music service, use that.
- If not, you may need a custom MCP server or wrap the music API into an MCP-compatible endpoint.
- (Optional but recommended) Vector store or knowledge base
If you intend the agent to “remember” the user’s preferences (genres, artists) or existing playlists, you might integrate a vector store or database and use RAG. But for a first version, you may skip that. - Decide on structure of outputs
Decide whether you return a JSON (with song titles, artist, links) or a plain text list, or both. - Decide on state variables
You may want to keep, per user:- preferred genres
- mood (if user specifies)
- length of playlist (number of songs)
Step 1: Start your agent flow
- Log in to the OpenAI platform → go to Agent Builder.
- Create a new workflow / flow (blank)
- You’ll see a Start node by default. That is your entry point.
- Configure inputs:
- Use
input_as_textas the user’s natural language input. - Optionally, define additional state variables (like
user_genres,playlist_length).
- Use
Step 2: Add a Guardrail node for input validation
Add a Guardrail node connected to the Start node. This ensures the user input is safe and conforms to expected patterns.
Configure the Guardrail:
- Moderation: Enable to block disallowed content
- Jailbreak: Enable to prevent prompt injection
- Hallucination check: (If you later use vector store)
- You’ll have a pass path (valid input) and a failure path.
Connect the failure path to an End node with a friendly message like “Sorry, I couldn’t understand your request. Try asking for a playlist for work, gym or sleep.”
Step 3: Interpret user intent (If / Else logic)
After the Guardrail’s pass path, insert an If / Else logic node. Use that to branch based on the user’s request:
- Condition 1: Input (or parsed variable) contains keyword “work”
- Condition 2: contains “gym”
- Condition 3: contains “sleep”
- Otherwise: fallback to “which mode do you want (work / gym / sleep)?”
You can use simple CEL expressions or keyword matching. For example:
input_as_text contains “work”input_as_text contains “gym”input_as_text contains “sleep”
Each branch will connect to a different logic path for generating the playlist.
Step 4: Playlist generation logic (for each branch)
For each of the three branches (work, gym, sleep), you’ll attach a sub-flow to produce a playlist. Here’s how:
Option A: Use a music API connector via MCP
- Add an MCP / Tools node connected in that branch.
- Configure that MCP to call the music API endpoint (for example, “get playlist recommendations”) with parameters:
mode(“work” / “gym” / “sleep”)preferred_genres(if stored)playlist_length
- The API returns a JSON with songs (title, artist, URI).
- Optionally, add a Transform node to convert the JSON into a human-readable text list (or HTML) to send back to the user.
Option B: Use an LLM-only fallback
If you can’t call an API (or in a simpler version), you can ask the model to produce a playlist:
- Insert an Agent node (i.e., call GPT)
- In the prompt instructions, specify:
“You are a DJ. When user says ‘work playlist’, produce a list of e.g. 10 songs (title — artist) suited for work (focus, mellow), drawing on popular public songs.”
Similarly for gym (energetic) and sleep (ambient, calm).
- You can combine this with a vector store or curated song database if you wish to restrict to songs you license.
- After the Agent, optionally a Transform node to format output.
Step 5: Merge back and output
After each branch (work / gym / sleep), converge them to a common path that leads to an End node that returns the result.
Ensure the output format is consistent. You may want JSON with a key songs or a neatly formatted text list. Use End node to return it.
Step 6: (Optional) Asking follow-up or customizing
You may want to let the user personalize:
- If user says “I like rock”, ask “Which mode (work/gym/sleep) do you want?”
- Or automatically store
user_genresin a State node.
You can insert these before the If / Else node: e.g.:
- After guardrails, check if
user_genresis null. If yes, prompt: “What genres do you like?” - Use User Approval or User Prompt node to capture that, store in
user_genres.
Then proceed to the If / Else.
Node summary & wiring
Here is a simplified wiring of nodes:
Start → Guardrail → (pass) → [maybe genre prompt / user input capture] → If/Else (3 branches)
├→ Work branch → (MCP or Agent) → Transform → →
├→ Gym branch → (MCP or Agent) → Transform → →
└→ Sleep branch → (MCP or Agent) → Transform → →
→ Merge → End node
guardrail (fail) → End node (error message)
You can insert Note nodes in the canvas to label each part for clarity (documentation for user).
Step 7: Prompt & instruction design in Agent node
In the Agent node(s) you use for playlist generation, carefully craft the prompt so the model reliably returns songs. Suggestions:
- “You are a music DJ that only suggests songs that are well-known (no obscure songs). Give exactly 8–12 song suggestions, with title — artist line by line.”
- “For ‘gym’, prefer energetic / high BPM songs.”
- “For ‘sleep’, suggest ambient, calm tracks.”
- Optionally: “Don’t repeat songs. If user provided a genre preference, use it.”
You can include a system/human instruction part of the agent’s prompt configuration.
Step 8: Testing & iteration
- Use Preview in Agent Builder (or “test mode”) to simulate chats.
- Try commands:
- “Create a work playlist”
- “Playlist for gym”
- “I want sleep music”
- “Give me a rock gym playlist”
- Check output formatting, edge cases (unknown mode, ambiguous input).
- If the model misinterprets, refine prompts, add more guardrails, add fallback messages.
- Optionally: export the agent’s logic as code (TypeScript / Python) from Agent Builder to further fine-tune.
Step 9: Publishing & embedding
- Once satisfied, Publish the agent in Agent Builder (so it’s live)
- You can then embed the agent via ChatKit into a website/app, or expose as a widget. (The Agent Builder documentation shows how to integrate with your UI)
- Optionally, add analytics or logging (e.g. store how many playlists generated, which mode most used).
Let me know how it works for you. Any questions , please write a comment.
Special thanks to Vaibhav Sisinty for inspiration.
Discover more from The Tech Society
Subscribe to get the latest posts sent to your email.