Web search finds information on the World Wide Web in response to a query. In an agent, it supplies information that a connected database cannot provide. section 10.4.2 section 10.4.4
A language-model agent can decide when to search, formulate a query from the user’s question and earlier database results, then combine the returned snippets into an answer. section 10.4.4
A LangChain setup connects web search to an SQL agent:
- Register for SerpAPI, retrieve an API key, and install the required search-results extension. section 10.4.2
- Load the SerpAPI search tool with load_tools, passing the API key and language model. section 10.4.2
- Pass the search tool as an extra tool when creating the SQL agent, then invoke the agent with a task. section 10.4.2
Combining database and web results
Given “What was the most sold game in 2016, and how is it played?”, the agent queries the games database, identifies FIFA 17, searches for “How to play FIFA 17,” and combines the search snippets with database information. section 10.4.4
from langchain.agents.load_tools import load_tools
extra_tools = load_tools(
['serpapi'], serpapi_api_key=serpaikey, llm=llm)
Inspect the Python listing that loads the SerpAPI web-search tool. section 10.4.2
[1m> Entering new SQL Agent Executor chain...[0m
[32;1m[1;3m
#1
Invoking: `sql_db_list_tables` with `{'tool_input': "}`
[0m[38;5;200m[1;3mgames[0m[32;1m[1;3m
#2
Invoking: `sql_db_schema` with `{'table_names': 'games'}`
[0m[33;1m[1;3m
CREATE TABLE games (
rank INTEGER,
name TEXT,
platform TEXT,
year INTEGER,
genre TEXT,
publisher TEXT,
americasales NUMERIC,
eusales NUMERIC,
japansales NUMERIC,
othersales NUMERIC,
globalsales NUMERIC
)
/*
3 rows from the games table:
rank name platform year genre publisher
americasales eusales japansales othersales globalsales
1 Wii Sports Wii 2006 Sports Nintendo 41.4900000000
29.0200000000 3.7700000000 8.4600000000 82.7400000000
2 Super Mario Bros. NES 1985 Platform Nintendo 29.0800000000
3.5800000000 6.8100000000 0.7700000000 40.2400000000
3 Mario Kart Wii Wii 2008 Racing Nintendo 15.8500000000
12.8800000000 3.7900000000 3.3100000000 35.8200000000
*/[0m[32;1m[1;3m
#3
Invoking: `sql_db_query_checker` with `{'query': 'SELECT name
FROM games WHERE year = 2016 ORDER BY globalsales DESC LIMIT 1'}`
responded: The games table contains the information we need.
I will query for the game with the highest global sales in 2016.
[0m[36;1m[1;3mSELECT name FROM games WHERE year = 2016
ORDER BY globalsales DESC LIMIT 1[0m[32;1m[1;3m
#4
Invoking: `sql_db_query` with `{'query': 'SELECT name
FROM games WHERE year = 2016 ORDER BY globalsales DESC LIMIT 1'}`
[0m[36;1m[1;3m[('FIFA 17',)][0m[32;1m[1;3m
#5
Invoking: `Search` with `How to play FIFA 17`
[0m[33;1m[1;3m["A Beginner's Guide To Complete FIFA 17 Domination ... The
main steps you should take are to jump right in with a quick play game. ...
EA Sports FIFA ...", 'Play FIFA 17 up to 5 days before launch for a full
10 hours when you join EA Access on Xbox One and Origin Access on PC.',
"1. Shield the ball in 360 degrees · 2. Use Driven Shots and Driven Headers ·
3. Use set piece upgrades to score with style · 4. Make Fifa 17's ...",
'Play FIFA 17 as much as you want with EA Access or Origin Access
for only $4.99 per month. Now available in The Vault.',
'Cautiously Start An Online Match. Score Early After Some Self-Proclaimed
Beautiful Build Up Play. Concede 4 Goals In A Row And Convince ...',
'FIFA 17 TUTORIALS & ULTIMATE TEAM ➞
Twitter: https://twitter.com/KrasiFIFA ➞
Instagram: http://instagram.com/KrasiFIFA How I record my ...',
"Draft mode is another way to play FIFA Ultimate Team,
giving you the ability to play with Players you don't own.
You'll have the opportunity to draft a random ..."]
#6
[0m[32;1m[1;3mThe most sold game in 2016 was FIFA 17.
To play FIFA 17, you can follow these steps:
1. Jump right in with a quick play game.
2. Shield the ball in 360 degrees.
3. Use Driven Shots and Driven Headers.
4. Use set piece upgrades to score with style.
5. Start an online match cautiously.
6. Score early after some self-proclaimed beautiful build-up play.
7. Draft mode is another way to play FIFA Ultimate Team,
giving you the ability to play with players you don't own.
You'll have the opportunity to draft a random team.
Remember, practice makes perfect



