mjschock's picture
Refactor agent structure by modularizing agent implementations into separate directories for web, data analysis, and media agents. Remove legacy code from agents.py, prompts.py, and tools.py, enhancing maintainability. Update main_v2.py to reflect new import paths and agent initialization. Add new tools for enhanced functionality, including web searching and data extraction. Update requirements.txt to include necessary dependencies for new tools.
837e221 unverified
raw
history blame
1.03 kB
import importlib
import yaml
from smolagents import CodeAgent
from tools import web_search, browse_webpage, find_in_page, extract_dates
def create_web_agent(model):
"""
Create a specialized agent for web browsing tasks.
Args:
model: The model to use for the agent
Returns:
Configured CodeAgent for web browsing
"""
# Load default prompts
prompt_templates = yaml.safe_load(
importlib.resources.files("smolagents.prompts")
.joinpath("code_agent.yaml")
.read_text()
)
web_agent = CodeAgent(
tools=[web_search, browse_webpage, find_in_page, extract_dates],
model=model,
name="web_agent",
description="Specialized agent for web browsing and searching. Use this agent to find information online, browse websites, and extract information from web pages.",
add_base_tools=True,
additional_authorized_imports=["requests", "bs4", "re", "json"],
prompt_templates=prompt_templates,
)
return web_agent