""" Analysis agent for interpreting song lyrics and providing deeper context. This agent is responsible for analyzing song lyrics and formatting the analysis in a user-friendly way, showing lyrics with comments underneath them. """ from smolagents import CodeAgent, VisitWebpageTool from loguru import logger from config import load_prompt_templates from tools.search_tools import ThrottledDuckDuckGoSearchTool from tools.analysis_tools import AnalyzeLyricsTool from tools.formatting_tools import FormatAnalysisResultsTool def create_analysis_agent(model): """ Create an agent specialized in analyzing and interpreting song lyrics. Args: model: The LLM model to use with this agent Returns: A configured CodeAgent for lyrics analysis """ # Load prompt templates prompt_templates = load_prompt_templates() # Create the throttled search tool with hardcoded values throttled_search_tool = ThrottledDuckDuckGoSearchTool( min_delay=3.0, max_delay=7.0 ) # Create and return the agent with specialized lyrics analysis instructions # Customize the prompts to use our specialized lyrics_analysis_agent prompt custom_prompt_templates = prompt_templates.copy() # Set our special prompt as the system prompt for better instruction if 'lyrics_analysis_agent' in custom_prompt_templates: custom_prompt_templates['system_prompt'] = custom_prompt_templates['lyrics_analysis_agent'] agent = CodeAgent( model=model, tools=[throttled_search_tool, VisitWebpageTool(), AnalyzeLyricsTool(), FormatAnalysisResultsTool()], name="lyrics_analysis_agent", description="Specialized agent for analyzing song lyrics and providing detailed commentary", additional_authorized_imports=["numpy", "bs4", "json", "re"], max_steps=5, # Hardcoded from config verbosity_level=2, # Hardcoded from config prompt_templates=prompt_templates ) logger.info("Analysis agent created successfully") return agent