File size: 882 Bytes
8b0695f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
from smolagents import tool
from tools.simple_text_browser import _BROWSER

@tool
def simple_search(query: str) -> str:
    """
    Perform a DuckDuckGo web search and return the top snippets.

    Args:
        query: The search query to perform.
    """
    return _BROWSER.search(query)

@tool
def archive_search(url: str, date: str) -> str:
    """
    Given a URL and a date (YYYYMMDD), returns the archived snapshot text via Wayback.

    Args:
        url: The original URL to look up.
        date: The desired snapshot date as YYYYMMDD.
    """
    api = f"https://archive.org/wayback/available?url={url}&timestamp={date}"
    data = requests.get(api, timeout=10).json()
    snap = data.get("archived_snapshots", {}).get("closest", {}).get("url")
    if not snap:
        return f"No archive found for {url} at {date}."
    return _BROWSER.visit_page(snap)