File size: 2,072 Bytes
775ea0b
 
 
 
 
7cc9db2
775ea0b
0e9bb01
 
 
7cc9db2
c3b461c
775ea0b
 
7cc9db2
45b377e
775ea0b
 
 
 
7cc9db2
775ea0b
 
 
 
0e9bb01
 
775ea0b
 
 
 
7539685
f252842
775ea0b
7cc9db2
7539685
c3b461c
7539685
775ea0b
 
c3b461c
45b377e
 
c3b461c
0e9bb01
775ea0b
 
 
45b377e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Web agent for finding and extracting song lyrics from online sources.
"""

from loguru import logger
from smolagents import CodeAgent, VisitWebpageTool, FinalAnswerTool

from config import load_prompt_templates
from tools.analysis_tools import AnalyzeLyricsTool
from tools.formatting_tools import FormatAnalysisResultsTool
from tools.search_tools import BraveSearchTool
from tools.image_generation_tools import GenerateImageTool


def create_single_agent(model, analysis_tool_model_id=None):
    """ 
    Create an agent specialized in web browsing and lyrics extraction.
    
    Args:
        model: The LLM model to use with this agent
        model_id: The model ID string to use for lyrics analysis (optional)
        
    Returns:
        A configured CodeAgent for web searches
    """
    prompt_templates = load_prompt_templates()

    # Define agent parameters directly in the code instead of using config
    # Example usage within the agent
    agent = CodeAgent(
        tools=[
            BraveSearchTool(),
            # ThrottledDuckDuckGoSearchTool(min_delay=7.0, max_delay=15.0),
            VisitWebpageTool(),
            AnalyzeLyricsTool(model_id=analysis_tool_model_id),
            FormatAnalysisResultsTool(),
            GenerateImageTool(),
            FinalAnswerTool(),
        ],
        model=model,
        additional_authorized_imports=['numpy', 'bs4', 'rich', 'json'],
        max_steps=25,
        verbosity_level=2,
        description="Specialized agent for finding and extracting song lyrics specified by the user using search and analysis tools. Performs lyrics search and after getting the lyrics full text from the web, it performs the analysis using given tools. Generates visual representation of the song based on the analysis results. Provides detailed commentary with beautiful and human-readable format using rich library formatting. Format analysis results in rich colorful output.",
        prompt_templates=prompt_templates
    )
    
    logger.info("Web agent (lyrics search) created successfully")
    return agent