Repository navigation
Expand file tree
/
Copy pathtools.py
More file actions
51 lines (37 loc) · 1.37 KB
/
Copy pathtools.py
File metadata and controls
51 lines (37 loc) · 1.37 KB
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
from langchain.tools import tool
from helpers import _search, _fetch, _search_and_fetch
@tool
def search(query: str, max_results: int = 5) -> list[dict]:
"""Search the web and return a list of results with title, url, and snippet.
Args:
query: The search query string
max_results: Maximum number of results to return (default: 5)
Returns:
List of dicts with 'title', 'url', and 'snippet' fields
"""
results = _search(query, max_results)
return [r.model_dump() for r in results]
@tool
def fetch(url: str) -> dict:
"""Fetch a webpage and return its main content as markdown.
Args:
url: The URL to fetch
Returns:
Dict with 'url' and 'content' (markdown) fields
"""
result = _fetch(url)
return result.model_dump()
@tool
def search_and_fetch(query: str, max_results: int = 3) -> list[dict]:
"""Search and fetch content from top results in one step.
Args:
query: The search query string
max_results: Maximum number of results to fetch (default: 3)
Returns:
List of dicts with 'title', 'url', 'snippet', and 'content' fields
"""
results = _search_and_fetch(query, max_results)
return [r.model_dump() for r in results]
def get_all_tools() -> list:
"""Return a list of all available tools."""
return [search, fetch, search_and_fetch]