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
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)
The tool needs no connect step and no config. You get it by path and it is ready to run.
Actions
| Action | What it does |
|---|---|
search | Searches the web, scrapes the top results and returns an answer with references, or the raw pages |
Inputs for search, passed in data:
| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | required | The search query. |
result_type | str | "raw" | "raw" returns each page's title, URL, snippet and text. "answer" adds an LLM step that returns a cited answer. |
num_results | int | 5 | How many top results to fetch and scrape. |
word_limit | int | 300 | Maximum words kept per scraped page. |
timeout | int | 2 | Per-URL scrape timeout in seconds. Slower pages are skipped. |
max_answer_words | int | none | Caps the answer length in "answer" mode. |
llm | str | platform default | Asset ID of the LLM that writes the answer in "answer" mode. |
search_asset_id | str | platform default | Asset ID of the underlying search model. |
include_domains, exclude_domains | list[str] | none | Restrict results to, or drop results from, these domains. Exclusion wins. |
after | str | none | Only results published on or after this year or date, for example "2024-01-31". |
gl, hl, location | str | none | Search 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"])
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)
Choose a mode
| Mode | Tool calls per question | Who summarizes | Use it when |
|---|---|---|---|
raw (default) | 1 | The agent | The agent should read the pages and quote or cite them itself. |
answer | 1 | The tool's LLM | You 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
- Tools: see every kind of tool an agent can call.
- Marketplace search: let an agent find models, tools and integrations.
- Agents: configure the agent that calls the tool.
- API reference: tool: every parameter and method.