Spaces:
Sleeping
Sleeping
Replace GoogleSearchTool with TavilySearch for web search
Browse files- agents/__init__.py +3 -0
- agents/base_agent.py +5 -6
- pyproject.toml +1 -0
- tools/web_search.py +6 -0
- uv.lock +53 -0
agents/__init__.py
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
+
|
| 3 |
+
load_dotenv()
|
agents/base_agent.py
CHANGED
|
@@ -5,24 +5,23 @@ from tools.arxiv_search import arxiv_tool
|
|
| 5 |
from tools.wikipedia_search import wikipedia_search_tool
|
| 6 |
from tools.calculator import calculator_tool
|
| 7 |
from tools.code_execution import CodeExecutionTool
|
| 8 |
-
from tools.google_search import GoogleSearchTool
|
|
|
|
| 9 |
from tools.wikipedia_search import wikipedia_search_tool
|
| 10 |
import os
|
| 11 |
-
from dotenv import load_dotenv
|
| 12 |
-
|
| 13 |
-
load_dotenv()
|
| 14 |
|
| 15 |
SYSTEM_PROMPT = "You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."
|
| 16 |
model = get_default_model()
|
| 17 |
|
| 18 |
code_execution_tool = CodeExecutionTool(api_key=os.environ['GOOGLE_API_KEY'])
|
| 19 |
-
google_search_tool = GoogleSearchTool(api_key=os.environ['GOOGLE_API_KEY'])
|
| 20 |
tools = [
|
| 21 |
arxiv_tool,
|
| 22 |
wikipedia_search_tool,
|
| 23 |
calculator_tool,
|
| 24 |
code_execution_tool,
|
| 25 |
-
google_search_tool,
|
|
|
|
| 26 |
]
|
| 27 |
|
| 28 |
agent_executor = create_react_agent(model, tools, prompt=SYSTEM_PROMPT)
|
|
|
|
| 5 |
from tools.wikipedia_search import wikipedia_search_tool
|
| 6 |
from tools.calculator import calculator_tool
|
| 7 |
from tools.code_execution import CodeExecutionTool
|
| 8 |
+
# from tools.google_search import GoogleSearchTool
|
| 9 |
+
from tools.web_search import tavily_search_tool
|
| 10 |
from tools.wikipedia_search import wikipedia_search_tool
|
| 11 |
import os
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
SYSTEM_PROMPT = "You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."
|
| 14 |
model = get_default_model()
|
| 15 |
|
| 16 |
code_execution_tool = CodeExecutionTool(api_key=os.environ['GOOGLE_API_KEY'])
|
| 17 |
+
# google_search_tool = GoogleSearchTool(api_key=os.environ['GOOGLE_API_KEY'])
|
| 18 |
tools = [
|
| 19 |
arxiv_tool,
|
| 20 |
wikipedia_search_tool,
|
| 21 |
calculator_tool,
|
| 22 |
code_execution_tool,
|
| 23 |
+
# google_search_tool,
|
| 24 |
+
tavily_search_tool
|
| 25 |
]
|
| 26 |
|
| 27 |
agent_executor = create_react_agent(model, tools, prompt=SYSTEM_PROMPT)
|
pyproject.toml
CHANGED
|
@@ -9,6 +9,7 @@ dependencies = [
|
|
| 9 |
"google-genai>=1.22.0",
|
| 10 |
"gradio>=5.34.2",
|
| 11 |
"langchain-community>=0.3.26",
|
|
|
|
| 12 |
"langchain[google-genai]>=0.3.26",
|
| 13 |
"langgraph>=0.4.10",
|
| 14 |
"numexpr>=2.11.0",
|
|
|
|
| 9 |
"google-genai>=1.22.0",
|
| 10 |
"gradio>=5.34.2",
|
| 11 |
"langchain-community>=0.3.26",
|
| 12 |
+
"langchain-tavily>=0.2.4",
|
| 13 |
"langchain[google-genai]>=0.3.26",
|
| 14 |
"langgraph>=0.4.10",
|
| 15 |
"numexpr>=2.11.0",
|
tools/web_search.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_tavily import TavilySearch
|
| 2 |
+
|
| 3 |
+
tavily_search_tool = TavilySearch(
|
| 4 |
+
max_results=5,
|
| 5 |
+
topic="general"
|
| 6 |
+
)
|
uv.lock
CHANGED
|
@@ -369,6 +369,7 @@ dependencies = [
|
|
| 369 |
{ name = "gradio" },
|
| 370 |
{ name = "langchain", extra = ["google-genai"] },
|
| 371 |
{ name = "langchain-community" },
|
|
|
|
| 372 |
{ name = "langgraph" },
|
| 373 |
{ name = "numexpr" },
|
| 374 |
{ name = "pandas" },
|
|
@@ -385,6 +386,7 @@ requires-dist = [
|
|
| 385 |
{ name = "gradio", specifier = ">=5.34.2" },
|
| 386 |
{ name = "langchain", extras = ["google-genai"], specifier = ">=0.3.26" },
|
| 387 |
{ name = "langchain-community", specifier = ">=0.3.26" },
|
|
|
|
| 388 |
{ name = "langgraph", specifier = ">=0.4.10" },
|
| 389 |
{ name = "numexpr", specifier = ">=2.11.0" },
|
| 390 |
{ name = "pandas", specifier = ">=2.3.0" },
|
|
@@ -887,6 +889,22 @@ wheels = [
|
|
| 887 |
{ url = "https://files.pythonhosted.org/packages/5e/70/0747358eca996f713f715e2bfc2d0805804f8f705af57381fbee91bb475a/langchain_google_genai-2.1.5-py3-none-any.whl", hash = "sha256:6c8ccaf33a41f83b1d08a2398edbf47a1eebea27a7ec6930f34a0c019f309253", size = 44788, upload-time = "2025-05-28T13:49:08.22Z" },
|
| 888 |
]
|
| 889 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 890 |
[[package]]
|
| 891 |
name = "langchain-text-splitters"
|
| 892 |
version = "0.3.8"
|
|
@@ -1101,6 +1119,32 @@ wheels = [
|
|
| 1101 |
{ url = "https://files.pythonhosted.org/packages/07/9f/d4719ce55a1d8bf6619e8bb92f1e2e7399026ea85ae0c324ec77ee06c050/multidict-6.5.1-py3-none-any.whl", hash = "sha256:895354f4a38f53a1df2cc3fa2223fa714cff2b079a9f018a76cad35e7f0f044c", size = 12185, upload-time = "2025-06-24T22:16:03.816Z" },
|
| 1102 |
]
|
| 1103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1104 |
[[package]]
|
| 1105 |
name = "mypy-extensions"
|
| 1106 |
version = "1.1.0"
|
|
@@ -1285,6 +1329,15 @@ wheels = [
|
|
| 1285 |
{ url = "https://files.pythonhosted.org/packages/39/c2/646d2e93e0af70f4e5359d870a63584dacbc324b54d73e6b3267920ff117/pandas-2.3.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:bb3be958022198531eb7ec2008cfc78c5b1eed51af8600c6c5d9160d89d8d249", size = 13231847, upload-time = "2025-06-05T03:27:51.465Z" },
|
| 1286 |
]
|
| 1287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1288 |
[[package]]
|
| 1289 |
name = "pillow"
|
| 1290 |
version = "11.2.1"
|
|
|
|
| 369 |
{ name = "gradio" },
|
| 370 |
{ name = "langchain", extra = ["google-genai"] },
|
| 371 |
{ name = "langchain-community" },
|
| 372 |
+
{ name = "langchain-tavily" },
|
| 373 |
{ name = "langgraph" },
|
| 374 |
{ name = "numexpr" },
|
| 375 |
{ name = "pandas" },
|
|
|
|
| 386 |
{ name = "gradio", specifier = ">=5.34.2" },
|
| 387 |
{ name = "langchain", extras = ["google-genai"], specifier = ">=0.3.26" },
|
| 388 |
{ name = "langchain-community", specifier = ">=0.3.26" },
|
| 389 |
+
{ name = "langchain-tavily", specifier = ">=0.2.4" },
|
| 390 |
{ name = "langgraph", specifier = ">=0.4.10" },
|
| 391 |
{ name = "numexpr", specifier = ">=2.11.0" },
|
| 392 |
{ name = "pandas", specifier = ">=2.3.0" },
|
|
|
|
| 889 |
{ url = "https://files.pythonhosted.org/packages/5e/70/0747358eca996f713f715e2bfc2d0805804f8f705af57381fbee91bb475a/langchain_google_genai-2.1.5-py3-none-any.whl", hash = "sha256:6c8ccaf33a41f83b1d08a2398edbf47a1eebea27a7ec6930f34a0c019f309253", size = 44788, upload-time = "2025-05-28T13:49:08.22Z" },
|
| 890 |
]
|
| 891 |
|
| 892 |
+
[[package]]
|
| 893 |
+
name = "langchain-tavily"
|
| 894 |
+
version = "0.2.4"
|
| 895 |
+
source = { registry = "https://pypi.org/simple" }
|
| 896 |
+
dependencies = [
|
| 897 |
+
{ name = "aiohttp" },
|
| 898 |
+
{ name = "langchain" },
|
| 899 |
+
{ name = "langchain-core" },
|
| 900 |
+
{ name = "mypy" },
|
| 901 |
+
{ name = "requests" },
|
| 902 |
+
]
|
| 903 |
+
sdist = { url = "https://files.pythonhosted.org/packages/15/df/faf9b205c93a048b96d013a88623bf31f974cf8d2785fc877d239861f1e8/langchain_tavily-0.2.4.tar.gz", hash = "sha256:68281a47e2e45e857a0d8087478f2638ea7e7c3a8a61a00cc0a2e3b7541240ea", size = 20722, upload-time = "2025-06-22T22:01:35.217Z" }
|
| 904 |
+
wheels = [
|
| 905 |
+
{ url = "https://files.pythonhosted.org/packages/61/10/9c7fc924a4a099840d03cf7b58da337f9ca54949bb0cfd26fe5320959c6c/langchain_tavily-0.2.4-py3-none-any.whl", hash = "sha256:36a80f2dd331cd68e26f4f6e6c3602e2615df4da21da05d787b904f7a564d487", size = 24465, upload-time = "2025-06-22T22:01:33.987Z" },
|
| 906 |
+
]
|
| 907 |
+
|
| 908 |
[[package]]
|
| 909 |
name = "langchain-text-splitters"
|
| 910 |
version = "0.3.8"
|
|
|
|
| 1119 |
{ url = "https://files.pythonhosted.org/packages/07/9f/d4719ce55a1d8bf6619e8bb92f1e2e7399026ea85ae0c324ec77ee06c050/multidict-6.5.1-py3-none-any.whl", hash = "sha256:895354f4a38f53a1df2cc3fa2223fa714cff2b079a9f018a76cad35e7f0f044c", size = 12185, upload-time = "2025-06-24T22:16:03.816Z" },
|
| 1120 |
]
|
| 1121 |
|
| 1122 |
+
[[package]]
|
| 1123 |
+
name = "mypy"
|
| 1124 |
+
version = "1.16.1"
|
| 1125 |
+
source = { registry = "https://pypi.org/simple" }
|
| 1126 |
+
dependencies = [
|
| 1127 |
+
{ name = "mypy-extensions" },
|
| 1128 |
+
{ name = "pathspec" },
|
| 1129 |
+
{ name = "typing-extensions" },
|
| 1130 |
+
]
|
| 1131 |
+
sdist = { url = "https://files.pythonhosted.org/packages/81/69/92c7fa98112e4d9eb075a239caa4ef4649ad7d441545ccffbd5e34607cbb/mypy-1.16.1.tar.gz", hash = "sha256:6bd00a0a2094841c5e47e7374bb42b83d64c527a502e3334e1173a0c24437bab", size = 3324747, upload-time = "2025-06-16T16:51:35.145Z" }
|
| 1132 |
+
wheels = [
|
| 1133 |
+
{ url = "https://files.pythonhosted.org/packages/b4/d6/39482e5fcc724c15bf6280ff5806548c7185e0c090712a3736ed4d07e8b7/mypy-1.16.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:af4792433f09575d9eeca5c63d7d90ca4aeceda9d8355e136f80f8967639183d", size = 11066493, upload-time = "2025-06-16T16:47:01.683Z" },
|
| 1134 |
+
{ url = "https://files.pythonhosted.org/packages/e6/e5/26c347890efc6b757f4d5bb83f4a0cf5958b8cf49c938ac99b8b72b420a6/mypy-1.16.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:66df38405fd8466ce3517eda1f6640611a0b8e70895e2a9462d1d4323c5eb4b9", size = 10081687, upload-time = "2025-06-16T16:48:19.367Z" },
|
| 1135 |
+
{ url = "https://files.pythonhosted.org/packages/44/c7/b5cb264c97b86914487d6a24bd8688c0172e37ec0f43e93b9691cae9468b/mypy-1.16.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:44e7acddb3c48bd2713994d098729494117803616e116032af192871aed80b79", size = 11839723, upload-time = "2025-06-16T16:49:20.912Z" },
|
| 1136 |
+
{ url = "https://files.pythonhosted.org/packages/15/f8/491997a9b8a554204f834ed4816bda813aefda31cf873bb099deee3c9a99/mypy-1.16.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0ab5eca37b50188163fa7c1b73c685ac66c4e9bdee4a85c9adac0e91d8895e15", size = 12722980, upload-time = "2025-06-16T16:37:40.929Z" },
|
| 1137 |
+
{ url = "https://files.pythonhosted.org/packages/df/f0/2bd41e174b5fd93bc9de9a28e4fb673113633b8a7f3a607fa4a73595e468/mypy-1.16.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:dedb6229b2c9086247e21a83c309754b9058b438704ad2f6807f0d8227f6ebdd", size = 12903328, upload-time = "2025-06-16T16:34:35.099Z" },
|
| 1138 |
+
{ url = "https://files.pythonhosted.org/packages/61/81/5572108a7bec2c46b8aff7e9b524f371fe6ab5efb534d38d6b37b5490da8/mypy-1.16.1-cp312-cp312-win_amd64.whl", hash = "sha256:1f0435cf920e287ff68af3d10a118a73f212deb2ce087619eb4e648116d1fe9b", size = 9562321, upload-time = "2025-06-16T16:48:58.823Z" },
|
| 1139 |
+
{ url = "https://files.pythonhosted.org/packages/28/e3/96964af4a75a949e67df4b95318fe2b7427ac8189bbc3ef28f92a1c5bc56/mypy-1.16.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:ddc91eb318c8751c69ddb200a5937f1232ee8efb4e64e9f4bc475a33719de438", size = 11063480, upload-time = "2025-06-16T16:47:56.205Z" },
|
| 1140 |
+
{ url = "https://files.pythonhosted.org/packages/f5/4d/cd1a42b8e5be278fab7010fb289d9307a63e07153f0ae1510a3d7b703193/mypy-1.16.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:87ff2c13d58bdc4bbe7dc0dedfe622c0f04e2cb2a492269f3b418df2de05c536", size = 10090538, upload-time = "2025-06-16T16:46:43.92Z" },
|
| 1141 |
+
{ url = "https://files.pythonhosted.org/packages/c9/4f/c3c6b4b66374b5f68bab07c8cabd63a049ff69796b844bc759a0ca99bb2a/mypy-1.16.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0a7cfb0fe29fe5a9841b7c8ee6dffb52382c45acdf68f032145b75620acfbd6f", size = 11836839, upload-time = "2025-06-16T16:36:28.039Z" },
|
| 1142 |
+
{ url = "https://files.pythonhosted.org/packages/b4/7e/81ca3b074021ad9775e5cb97ebe0089c0f13684b066a750b7dc208438403/mypy-1.16.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:051e1677689c9d9578b9c7f4d206d763f9bbd95723cd1416fad50db49d52f359", size = 12715634, upload-time = "2025-06-16T16:50:34.441Z" },
|
| 1143 |
+
{ url = "https://files.pythonhosted.org/packages/e9/95/bdd40c8be346fa4c70edb4081d727a54d0a05382d84966869738cfa8a497/mypy-1.16.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:d5d2309511cc56c021b4b4e462907c2b12f669b2dbeb68300110ec27723971be", size = 12895584, upload-time = "2025-06-16T16:34:54.857Z" },
|
| 1144 |
+
{ url = "https://files.pythonhosted.org/packages/5a/fd/d486a0827a1c597b3b48b1bdef47228a6e9ee8102ab8c28f944cb83b65dc/mypy-1.16.1-cp313-cp313-win_amd64.whl", hash = "sha256:4f58ac32771341e38a853c5d0ec0dfe27e18e27da9cdb8bbc882d2249c71a3ee", size = 9573886, upload-time = "2025-06-16T16:36:43.589Z" },
|
| 1145 |
+
{ url = "https://files.pythonhosted.org/packages/cf/d3/53e684e78e07c1a2bf7105715e5edd09ce951fc3f47cf9ed095ec1b7a037/mypy-1.16.1-py3-none-any.whl", hash = "sha256:5fc2ac4027d0ef28d6ba69a0343737a23c4d1b83672bf38d1fe237bdc0643b37", size = 2265923, upload-time = "2025-06-16T16:48:02.366Z" },
|
| 1146 |
+
]
|
| 1147 |
+
|
| 1148 |
[[package]]
|
| 1149 |
name = "mypy-extensions"
|
| 1150 |
version = "1.1.0"
|
|
|
|
| 1329 |
{ url = "https://files.pythonhosted.org/packages/39/c2/646d2e93e0af70f4e5359d870a63584dacbc324b54d73e6b3267920ff117/pandas-2.3.0-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:bb3be958022198531eb7ec2008cfc78c5b1eed51af8600c6c5d9160d89d8d249", size = 13231847, upload-time = "2025-06-05T03:27:51.465Z" },
|
| 1330 |
]
|
| 1331 |
|
| 1332 |
+
[[package]]
|
| 1333 |
+
name = "pathspec"
|
| 1334 |
+
version = "0.12.1"
|
| 1335 |
+
source = { registry = "https://pypi.org/simple" }
|
| 1336 |
+
sdist = { url = "https://files.pythonhosted.org/packages/ca/bc/f35b8446f4531a7cb215605d100cd88b7ac6f44ab3fc94870c120ab3adbf/pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712", size = 51043, upload-time = "2023-12-10T22:30:45Z" }
|
| 1337 |
+
wheels = [
|
| 1338 |
+
{ url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", size = 31191, upload-time = "2023-12-10T22:30:43.14Z" },
|
| 1339 |
+
]
|
| 1340 |
+
|
| 1341 |
[[package]]
|
| 1342 |
name = "pillow"
|
| 1343 |
version = "11.2.1"
|