mjschock's picture
Enhance agent functionality in main_v2.py by adding WikipediaSearchTool and updating DuckDuckGoSearchTool and VisitWebpageTool parameters. Modify agent initialization to accommodate new tools and increase max results and output length. Update requirements.txt to include Wikipedia-API dependency. Refactor imports for better organization across agent modules.
e4c7240 unverified
import importlib
import yaml
from smolagents import CodeAgent
from tools import browse_webpage, extract_dates, find_in_page, web_search
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