Spaces:
Build error
Build error
Enhance design documentation for PlannerAgent entity recognition - Expanded the design document to detail current functionality, limitations, strengths, and proposed enhancements for the PlannerAgent. Included before and after examples of query processing to illustrate improvements in entity extraction and coordination strategies. Updated TODO list to reflect ongoing enhancements.
56ba2a5 | # Comprehensive Implementation Roadmap: Design Alignment & Sequencing | |
| ## Executive Summary | |
| This document analyzes the alignment between our three major enhancement designs and provides an optimal implementation sequence that ensures all components work together cohesively: | |
| 1. **Enhanced PlannerAgent Entity Recognition** - Centralized query understanding | |
| 2. **Agent Improvements: Quality Scoring & Underground Detection** - Enhanced candidate generation (100β20) | |
| 3. **Enhanced JudgeAgent Ranking** - Prompt-driven ranking and evaluation | |
| ## Design Alignment Analysis | |
| ### π― Core Philosophy Alignment | |
| All three designs share the same foundational principles: | |
| #### **Prompt-Driven Architecture** | |
| - **PlannerAgent**: Extracts entities and intent from conversational prompts | |
| - **Agent Improvements**: Uses prompt analysis to generate 100 diverse candidates | |
| - **JudgeAgent**: Ranks based on prompt intent and contextual relevance | |
| #### **Quality-First Approach** | |
| - **PlannerAgent**: Provides quality preferences to agents via entity extraction | |
| - **Agent Improvements**: Implements comprehensive quality scoring (audio, popularity, engagement) | |
| - **JudgeAgent**: Uses multi-dimensional quality assessment for final ranking | |
| #### **Context Awareness** | |
| - **PlannerAgent**: Maintains conversation context and session continuity | |
| - **Agent Improvements**: Uses context for candidate source balancing | |
| - **JudgeAgent**: Applies contextual relevance scoring based on prompt analysis | |
| ### π Data Flow Integration | |
| #### Current Workflow Enhancement | |
| ``` | |
| User Prompt | |
| β | |
| π§ Enhanced PlannerAgent (NEW) | |
| ββ Entity Recognition (artists, moods, activities, preferences) | |
| ββ Intent Analysis (concentration, discovery, energy, etc.) | |
| ββ Context Management (session history, preference evolution) | |
| ββ Enhanced Agent Coordination (entity-aware strategies) | |
| β | |
| Parallel Agent Execution (ENHANCED) | |
| ββ πΈ GenreMoodAgent: 100β20 Quality Filtering | |
| β ββ Enhanced Candidate Generation (40 primary + 30 similar + 20 genre + 10 underground) | |
| β ββ Audio Quality Scoring (energy, danceability, valence) | |
| β ββ Popularity Balancing (mainstream vs underground) | |
| β ββ Entity-Aware Search (using PlannerAgent entities) | |
| ββ π DiscoveryAgent: Multi-hop Similarity & Underground Detection | |
| ββ Enhanced Candidate Generation (40 multi-hop + 30 underground + 20 genre + 10 rising) | |
| ββ Multi-hop Similarity Explorer (2-3 degrees of separation) | |
| ββ Intelligent Underground Detection (<50K listeners) | |
| ββ Entity-Aware Discovery (using PlannerAgent seed artists) | |
| β | |
| βοΈ Enhanced JudgeAgent (NEW) | |
| ββ Prompt-Driven Ranking (intent-weighted scoring) | |
| ββ Contextual Relevance Assessment (activity, mood, temporal fit) | |
| ββ Discovery Appropriateness (exploration vs familiarity balance) | |
| ββ Conversational Explanation Generation (prompt-referencing) | |
| ββ Final Selection (Top 20 from 100 candidates) | |
| ``` | |
| #### Enhanced State Management | |
| ```python | |
| class MusicRecommenderState(BaseModel): | |
| # Input (Enhanced by PlannerAgent) | |
| user_query: str | |
| conversation_context: Optional[Dict] = None # NEW: Session history | |
| # Enhanced Planning Phase (PlannerAgent) | |
| entities: Optional[Dict[str, Any]] = None # NEW: Extracted entities | |
| intent_analysis: Optional[Dict[str, Any]] = None # NEW: Intent understanding | |
| planning_strategy: Optional[Dict[str, Any]] = None # ENHANCED: Entity-aware | |
| # Enhanced Advocate Phase (100 candidates each) | |
| genre_mood_candidates: List[Dict] = [] # NEW: 100 candidates | |
| discovery_candidates: List[Dict] = [] # NEW: 100 candidates | |
| quality_scores: Dict[str, Dict] = {} # NEW: Quality breakdowns | |
| # Enhanced Judge Phase (Prompt-driven ranking) | |
| ranking_analysis: Optional[Dict] = None # NEW: Prompt-based ranking | |
| final_recommendations: List[Dict] = [] # ENHANCED: Top 20 from 200 | |
| # Enhanced Reasoning | |
| reasoning_log: List[str] = [] | |
| entity_reasoning: List[Dict] = [] # NEW: Entity extraction reasoning | |
| quality_reasoning: List[Dict] = [] # NEW: Quality scoring reasoning | |
| ranking_reasoning: List[Dict] = [] # NEW: Ranking decision reasoning | |
| ``` | |
| ### π Component Dependencies | |
| #### **Critical Dependencies** | |
| 1. **PlannerAgent β Agents**: Entity extraction must complete before agent execution | |
| 2. **Agents β JudgeAgent**: 100 candidates must be generated before ranking | |
| 3. **PlannerAgent β JudgeAgent**: Intent analysis needed for prompt-driven ranking | |
| #### **Data Dependencies** | |
| ```python | |
| # PlannerAgent provides to Agents: | |
| { | |
| "entities": { | |
| "artists": {"primary": [], "similar_to": [], "avoid": []}, | |
| "genres": {"primary": [], "fusion": [], "avoid": []}, | |
| "activities": {"mental": [], "physical": []}, | |
| "moods": {"energy": [], "emotion": []} | |
| }, | |
| "intent_analysis": { | |
| "primary_intent": "concentration|discovery|energy|relaxation", | |
| "activity_context": "coding|workout|study|party", | |
| "exploration_openness": 0.0-1.0, | |
| "specificity_level": 0.0-1.0 | |
| } | |
| } | |
| # Agents provide to JudgeAgent: | |
| { | |
| "candidates": [ | |
| { | |
| "track_data": {...}, | |
| "quality_score": 0.85, | |
| "quality_breakdown": { | |
| "audio_quality": 0.8, | |
| "popularity_balance": 0.9, | |
| "engagement": 0.8, | |
| "genre_fit": 0.9 | |
| }, | |
| "candidate_source": "primary_search|similar_artists|genre_exploration|underground_gems", | |
| "discovery_score": 0.7 | |
| } | |
| ] | |
| } | |
| # JudgeAgent uses both for ranking: | |
| { | |
| "prompt_analysis": "from PlannerAgent", | |
| "quality_candidates": "from Agents", | |
| "ranking_strategy": "intent-weighted + contextual + discovery + quality" | |
| } | |
| ``` | |
| ## Implementation Sequence & Rationale | |
| ### ποΈ Phase 1: Foundation - Enhanced PlannerAgent (Weeks 1-3) | |
| **Why First**: All other enhancements depend on centralized entity recognition and intent analysis. | |
| #### Week 1: Core Entity Recognition | |
| ```python | |
| # Implement basic entity extraction | |
| class EnhancedEntityRecognizer: | |
| async def extract_entities(self, query: str) -> Dict[str, Any]: | |
| # LLM-based entity extraction with fallbacks | |
| pass | |
| # Update PlannerAgent | |
| class PlannerAgent(BaseAgent): | |
| async def _analyze_user_query(self, user_query: str) -> Dict[str, Any]: | |
| # ENHANCED: Add entity extraction | |
| entities = await self.entity_recognizer.extract_entities(user_query) | |
| # ENHANCED: Add intent analysis | |
| intent_analysis = await self._analyze_intent(user_query, entities) | |
| # EXISTING: Keep current analysis | |
| task_analysis = await self._existing_analysis(user_query) | |
| return { | |
| "entities": entities, # NEW | |
| "intent_analysis": intent_analysis, # NEW | |
| "task_analysis": task_analysis # EXISTING | |
| } | |
| ``` | |
| #### Week 2: Agent Coordination Enhancement | |
| ```python | |
| async def _plan_agent_coordination(self, user_query: str, analysis: Dict) -> Dict: | |
| # ENHANCED: Use entities for coordination | |
| entities = analysis.get("entities", {}) | |
| intent = analysis.get("intent_analysis", {}) | |
| return { | |
| "genre_mood_agent": { | |
| # EXISTING coordination | |
| "focus_areas": [...], | |
| "energy_level": "...", | |
| # NEW: Entity-aware coordination | |
| "seed_artists": entities.get("artists", {}).get("primary", []), | |
| "target_genres": entities.get("genres", {}).get("primary", []), | |
| "activity_context": entities.get("activities", {}), | |
| "intent_context": intent | |
| }, | |
| "discovery_agent": { | |
| # EXISTING coordination | |
| "novelty_priority": "...", | |
| # NEW: Entity-aware coordination | |
| "similarity_targets": entities.get("artists", {}).get("similar_to", []), | |
| "avoid_artists": entities.get("artists", {}).get("avoid", []), | |
| "exploration_openness": intent.get("exploration_openness", 0.5) | |
| } | |
| } | |
| ``` | |
| #### Week 3: Conversation Context | |
| ```python | |
| class ConversationContextManager: | |
| async def update_session_context(self, session_id: str, query: str, entities: Dict): | |
| # Track conversation history | |
| # Resolve session references ("like the last song") | |
| # Update preference evolution | |
| pass | |
| ``` | |
| **Deliverables**: | |
| - β Enhanced entity extraction (artists, genres, moods, activities) | |
| - β Intent analysis (concentration, discovery, energy levels) | |
| - β Entity-aware agent coordination | |
| - β Basic conversation context management | |
| - β Backward compatibility with existing agents | |
| ### π΅ Phase 2: Agent Enhancements - Quality Scoring & Underground Detection (Weeks 4-7) | |
| **Why Second**: Requires entity information from PlannerAgent to work effectively. | |
| #### Week 4: Enhanced Candidate Generation Framework | |
| ```python | |
| class EnhancedCandidateGenerator: | |
| async def generate_candidate_pool(self, entities: Dict, intent: Dict) -> List[Dict]: | |
| # Use entities for targeted search | |
| seed_artists = entities.get("artists", {}).get("primary", []) | |
| target_genres = entities.get("genres", {}).get("primary", []) | |
| activity_context = entities.get("activities", {}) | |
| # Generate 100 candidates from multiple sources | |
| candidates = [] | |
| candidates.extend(await self._primary_search(seed_artists, target_genres, 40)) | |
| candidates.extend(await self._similar_artists_search(seed_artists, 30)) | |
| candidates.extend(await self._genre_exploration(target_genres, activity_context, 20)) | |
| candidates.extend(await self._underground_detection(target_genres, 10)) | |
| return candidates[:100] | |
| ``` | |
| #### Week 5: Quality Scoring Implementation | |
| ```python | |
| class AudioQualityScorer: | |
| def calculate_audio_quality_score(self, track_features: Dict) -> float: | |
| # Multi-dimensional audio analysis | |
| # Energy optimization, danceability, valence | |
| # Activity-specific scoring | |
| pass | |
| class PopularityBalancer: | |
| def calculate_popularity_score(self, track_data: Dict, intent: Dict) -> float: | |
| # Use intent analysis for popularity preferences | |
| exploration_openness = intent.get("exploration_openness", 0.5) | |
| # Balance mainstream vs underground based on intent | |
| pass | |
| ``` | |
| #### Week 6: Multi-hop Similarity & Underground Detection | |
| ```python | |
| class MultiHopSimilarityExplorer: | |
| async def explore_similarity_network(self, seed_artists: List[str]) -> List[Dict]: | |
| # Use seed artists from PlannerAgent entities | |
| # 2-3 degree exploration | |
| # Underground ratio based on intent analysis | |
| pass | |
| class UndergroundDetector: | |
| async def detect_underground_artists(self, genres: List[str], intent: Dict) -> List[Dict]: | |
| # Use genre entities from PlannerAgent | |
| # Quality thresholds based on intent analysis | |
| pass | |
| ``` | |
| #### Week 7: Integration & 100β20 Filtering | |
| ```python | |
| class EnhancedGenreMoodAgent(GenreMoodAgent): | |
| async def process(self, state: MusicRecommenderState) -> MusicRecommenderState: | |
| # Extract entities and intent from state | |
| entities = state.entities | |
| intent = state.intent_analysis | |
| # Generate 100 candidates using entities | |
| candidates = await self.candidate_generator.generate_candidate_pool(entities, intent) | |
| # Apply quality scoring to all 100 | |
| scored_candidates = [] | |
| for candidate in candidates: | |
| quality_score = await self._calculate_comprehensive_quality(candidate, intent) | |
| candidate["quality_score"] = quality_score | |
| candidate["quality_breakdown"] = self._get_quality_breakdown(candidate) | |
| scored_candidates.append(candidate) | |
| # Filter to top 20 and add to state | |
| top_candidates = sorted(scored_candidates, key=lambda x: x["quality_score"], reverse=True)[:20] | |
| state.genre_mood_candidates = top_candidates | |
| return state | |
| ``` | |
| **Deliverables**: | |
| - β 100-candidate generation from multiple sources | |
| - β Comprehensive quality scoring system | |
| - β Multi-hop similarity exploration | |
| - β Intelligent underground detection | |
| - β 100β20 filtering pipeline | |
| - β Entity-aware search strategies | |
| ### βοΈ Phase 3: Enhanced JudgeAgent - Prompt-Driven Ranking (Weeks 8-10) | |
| **Why Third**: Requires both entity analysis and quality-scored candidates to work effectively. | |
| #### Week 8: Prompt Analysis Engine | |
| ```python | |
| class PromptAnalysisEngine: | |
| def __init__(self): | |
| self.intent_analyzer = IntentAnalyzer() | |
| self.context_extractor = ContextExtractor() | |
| async def analyze_for_ranking(self, entities: Dict, intent: Dict) -> Dict: | |
| return { | |
| "intent_weights": self._calculate_intent_weights(intent), | |
| "contextual_factors": self._extract_contextual_factors(entities), | |
| "discovery_preferences": self._assess_discovery_preferences(intent), | |
| "activity_requirements": self._extract_activity_requirements(entities) | |
| } | |
| ``` | |
| #### Week 9: Prompt-Driven Ranking Implementation | |
| ```python | |
| class EnhancedJudgeAgent(JudgeAgent): | |
| async def process(self, state: MusicRecommenderState) -> MusicRecommenderState: | |
| # Get all candidates (up to 200 from both agents) | |
| all_candidates = state.genre_mood_candidates + state.discovery_candidates | |
| # Use entities and intent for ranking | |
| entities = state.entities | |
| intent = state.intent_analysis | |
| # Apply prompt-driven ranking | |
| ranking_analysis = await self.prompt_analyzer.analyze_for_ranking(entities, intent) | |
| # Score candidates based on prompt context | |
| scored_candidates = [] | |
| for candidate in all_candidates: | |
| prompt_score = await self._calculate_prompt_driven_score( | |
| candidate, entities, intent, ranking_analysis | |
| ) | |
| candidate["prompt_score"] = prompt_score | |
| candidate["ranking_breakdown"] = self._get_ranking_breakdown(candidate) | |
| scored_candidates.append(candidate) | |
| # Select top 20 with diversity | |
| final_recommendations = await self._select_with_diversity( | |
| scored_candidates, entities, intent, num_recommendations=20 | |
| ) | |
| state.final_recommendations = final_recommendations | |
| return state | |
| ``` | |
| #### Week 10: Conversational Explanation Generation | |
| ```python | |
| class ConversationalExplainer: | |
| def generate_prompt_based_explanation(self, track: Dict, entities: Dict, intent: Dict) -> str: | |
| # Reference original prompt | |
| # Explain ranking factors | |
| # Show entity connections | |
| # Provide conversational context | |
| pass | |
| ``` | |
| **Deliverables**: | |
| - β Prompt-driven ranking algorithm | |
| - β Intent-weighted scoring system | |
| - β Contextual relevance assessment | |
| - β Discovery appropriateness balancing | |
| - β Conversational explanation generation | |
| - β Final 20-track selection with diversity | |
| ### π§ Phase 4: Integration & Optimization (Weeks 11-12) | |
| #### Week 11: End-to-End Integration | |
| - Comprehensive testing of full pipeline | |
| - Performance optimization | |
| - Error handling and fallbacks | |
| - State management refinement | |
| #### Week 12: Quality Assurance & Monitoring | |
| - A/B testing against current system | |
| - Performance metrics collection | |
| - User feedback integration | |
| - Documentation and deployment | |
| ## Success Metrics & Validation | |
| ### π― Technical Metrics | |
| #### **Entity Recognition Success** | |
| - **Accuracy**: >90% correct entity extraction | |
| - **Coverage**: >85% of query intents captured | |
| - **Context Resolution**: >95% of session references resolved | |
| #### **Quality Scoring Success** | |
| - **Candidate Quality**: 100 high-quality candidates per agent | |
| - **Scoring Consistency**: <5% variance in quality assessments | |
| - **Source Diversity**: Balanced distribution across 4 sources | |
| #### **Ranking Success** | |
| - **Intent Alignment**: >85% recommendations match prompt intent | |
| - **Contextual Relevance**: >90% appropriate for stated context | |
| - **Discovery Balance**: Optimal exploration based on prompt openness | |
| ### π΅ User Experience Metrics | |
| #### **Overall System Improvements** | |
| - **Recommendation Accuracy**: +40% improvement in user satisfaction | |
| - **Discovery Rate**: +60% more unknown artists discovered | |
| - **Quality Consistency**: 90% of tracks meet high quality standards | |
| - **Conversation Flow**: Natural, contextual dialogue progression | |
| #### **Specific Enhancement Benefits** | |
| - **Entity Recognition**: Users can reference artists, activities, moods naturally | |
| - **Quality Scoring**: Consistent high-quality recommendations across all contexts | |
| - **Prompt-Driven Ranking**: Recommendations that truly match conversational intent | |
| ## Risk Mitigation & Contingencies | |
| ### π¨ Technical Risks | |
| #### **Integration Complexity** | |
| - **Risk**: Components don't integrate smoothly | |
| - **Mitigation**: Phased implementation with backward compatibility | |
| - **Contingency**: Rollback to previous phase if integration fails | |
| #### **Performance Impact** | |
| - **Risk**: 100-candidate generation increases latency | |
| - **Mitigation**: Parallel processing and caching strategies | |
| - **Contingency**: Reduce candidate pool size if performance degrades | |
| #### **LLM Dependency** | |
| - **Risk**: Entity recognition or ranking fails due to LLM issues | |
| - **Mitigation**: Comprehensive fallback mechanisms | |
| - **Contingency**: Graceful degradation to current system behavior | |
| ### π₯ User Experience Risks | |
| #### **Over-Engineering** | |
| - **Risk**: System becomes too complex for simple queries | |
| - **Mitigation**: Maintain simple paths for basic requests | |
| - **Contingency**: Simplification mode for straightforward queries | |
| #### **Context Confusion** | |
| - **Risk**: Session context creates unexpected recommendations | |
| - **Mitigation**: Clear session boundaries and reset options | |
| - **Contingency**: Context-free mode for users who prefer it | |
| ## Conclusion | |
| This comprehensive implementation roadmap ensures that all three enhancement designs work together cohesively to create a sophisticated, prompt-driven music recommendation system. The phased approach allows for: | |
| 1. **Incremental Value Delivery**: Each phase provides immediate benefits | |
| 2. **Risk Management**: Early detection and resolution of integration issues | |
| 3. **Quality Assurance**: Thorough testing at each phase | |
| 4. **User Experience Focus**: Maintaining usability throughout the enhancement process | |
| The final system will provide: | |
| - **10x More Candidate Options**: 100 candidates per agent vs current 10-20 | |
| - **Sophisticated Entity Understanding**: Natural language query processing | |
| - **Context-Aware Recommendations**: Prompt-driven ranking and selection | |
| - **Quality Consistency**: Every recommendation meets high standards | |
| - **Conversational Intelligence**: Natural dialogue about music preferences | |
| This represents a significant evolution of BeatDebate from a basic recommendation system to a sophisticated, conversational music discovery platform that truly understands user intent and context. |