File size: 1,303 Bytes
ce0ec3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Web agent for finding and extracting song lyrics from online sources.
"""

from smolagents import CodeAgent, VisitWebpageTool
from loguru import logger

from config import AGENT_CONFIG, load_prompt_templates
from tools.search_tools import ThrottledDuckDuckGoSearchTool


def create_web_agent(model):
    """
    Create an agent specialized in web browsing and lyrics extraction.
    
    Args:
        model: The LLM model to use with this agent
        
    Returns:
        A configured CodeAgent for web searches
    """
    # Get configuration values
    config = AGENT_CONFIG['web_agent']
    prompt_templates = load_prompt_templates()
    
    # Create the throttled search tool
    throttled_search_tool = ThrottledDuckDuckGoSearchTool(
        min_delay=3.0, 
        max_delay=7.0
    )
    
    # Create and return the agent
    agent = CodeAgent(
        model=model,
        tools=[throttled_search_tool, VisitWebpageTool()],
        name="lyrics_search_agent",
        description=config['description'],
        additional_authorized_imports=["numpy", "bs4"],
        max_steps=config['max_steps'],
        verbosity_level=config['verbosity_level'],
        prompt_templates=prompt_templates
    )
    
    logger.info("Web agent (lyrics search) created successfully")
    return agent