tonko22's picture
Simplify all a bit
775ea0b
"""
Web agent for finding and extracting song lyrics from online sources.
"""
from smolagents import CodeAgent, VisitWebpageTool
from loguru import logger
from config import 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
"""
# Load prompt templates
prompt_templates = load_prompt_templates()
# Create the throttled search tool
throttled_search_tool = ThrottledDuckDuckGoSearchTool(
min_delay=5.0,
max_delay=10.0
)
# Create and return the agent with specialized lyrics search instructions
# Customize the prompts to use our specialized lyrics_search_agent prompt
custom_prompt_templates = prompt_templates.copy()
# Set our special prompt as the system prompt for better instruction
if 'lyrics_search_agent' in custom_prompt_templates:
custom_prompt_templates['system_prompt'] = custom_prompt_templates['lyrics_search_agent']
agent = CodeAgent(
model=model,
tools=[throttled_search_tool, VisitWebpageTool()],
name="lyrics_search_agent",
description="Specialized agent for finding and extracting complete song lyrics",
additional_authorized_imports=["numpy", "bs4", "json", "re"],
max_steps=10, # Hardcoded from config
verbosity_level=2, # Hardcoded from config
prompt_templates=prompt_templates
)
logger.info("Web agent (lyrics search) created successfully")
return agent