File size: 1,634 Bytes
7c51b43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95f4932
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from langchain_core.tools import tool
from langchain_community.document_loaders import WikipediaLoader, ArxivLoader
from langchain_community.tools.tavily_search import TavilySearchResults

@tool
def multiply(a: int, b: int) -> int:
    """Multiply two numbers."""
    return a * b

@tool
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

@tool
def subtract(a: int, b: int) -> int:
    """Subtract two numbers."""
    return a - b

@tool
def divide(a: int, b: int) -> float:
    """Divide two numbers."""
    if b == 0:
        raise ValueError("Cannot divide by zero.")
    return a / b

@tool
def modulus(a: int, b: int) -> int:
    """Get modulus of two numbers."""
    return a % b

@tool
def wiki_search(query: str) -> str:
    """Search Wikipedia for a query and return top results."""
    docs = WikipediaLoader(query=query, load_max_docs=2).load()
    return "\n\n".join(doc.page_content for doc in docs)

@tool
def arxiv_search(query: str) -> str:
    """Search Arxiv for a query and return top results."""
    docs = ArxivLoader(query=query, load_max_docs=2).load()
    return "\n\n".join(doc.page_content[:1000] for doc in docs)

@tool
def web_search(query: str) -> str:
    """Search the web using Tavily."""
    docs = TavilySearchResults(max_results=3).invoke(query=query)
    return "\n\n".join(doc.page_content for doc in docs)

# Tools as a dict for manual agent usage
TOOLS = {
    "multiply": multiply,
    "add": add,
    "subtract": subtract,
    "divide": divide,
    "modulus": modulus,
    "wiki_search": wiki_search,
    "arxiv_search": arxiv_search,
    "web_search": web_search,
}