Skip to main content

Web search

The web search tool queries a search engine, scrapes the top results in parallel and returns a cited answer or the clean page text.

Asset path: aixplain/aixplain-web-search/aixplain · Marketplace card

tip

One call searches and scrapes the top results in parallel. An agent does not need a separate scraper tool or one call per URL.

Try it​

from aixplain import Aixplain

aix = Aixplain(api_key="YOUR_API_KEY")

web_search = aix.Tool.get("aixplain/aixplain-web-search/aixplain")
web_search.allowed_actions = ["search"]

agent = aix.Agent(
name="Web researcher",
description="Answers questions with live web search and cited sources.",
instructions="Use web search for anything time-sensitive. Cite your sources.",
tools=[web_search],
).save()

result = agent.run("What is the latest stable Python release? One sentence.")
print(result.data.output)
Show output

The tool needs no connect step and no config. You get it by path and it is ready to run.

Actions​

ActionWhat it does
searchSearches the web, scrapes the top results and returns an answer with references, or the raw pages

Inputs for search, passed in data:

ParameterTypeDefaultDescription
querystrrequiredThe search query.
result_typestr"raw""raw" returns each page's title, URL, snippet and text. "answer" adds an LLM step that returns a cited answer.
num_resultsint5How many top results to fetch and scrape.
word_limitint300Maximum words kept per scraped page.
timeoutint2Per-URL scrape timeout in seconds. Slower pages are skipped.
max_answer_wordsintnoneCaps the answer length in "answer" mode.
llmstrplatform defaultAsset ID of the LLM that writes the answer in "answer" mode.
search_asset_idstrplatform defaultAsset ID of the underlying search model.
include_domains, exclude_domainslist[str]noneRestrict results to, or drop results from, these domains. Exclusion wins.
afterstrnoneOnly results published on or after this year or date, for example "2024-01-31".
gl, hl, locationstrnoneSearch as if from a country ("us"), in an interface language ("en") or from a place ("Toronto, Ontario, Canada").

Run the tool directly​

By default the tool returns the scraped pages. Each record has a title, url, description and the cleaned page text in data.

result = web_search.run(action="search", data={
"query": "what is retrieval augmented generation",
"num_results": 3,
"word_limit": 60,
})
for page in result.data:
print(page["title"], "|", page["url"])
Show output

Get a cited answer​

Set result_type="answer" to add an LLM step. The tool returns a short answer and the URLs that support it.

result = web_search.run(action="search", data={
"query": "what is retrieval augmented generation",
"result_type": "answer",
"num_results": 3,
"max_answer_words": 60,
})
print(result.data)
Show output

Choose a mode​

ModeTool calls per questionWho summarizesUse it when
raw (default)1The agentThe agent should read the pages and quote or cite them itself.
answer1The tool's LLMYou want a short cited answer with the fewest moving parts.

In raw mode, keep num_results and word_limit modest so large payloads do not fill the agent's context. Scraped text is tag-free, and in answer mode every answer comes with the source URLs that support it.

Clean up​

agent.delete()

Next steps​