Metadata-Version: 2.5
Name: llama-index-tools-webrouter
Version: 0.1.1
Summary: LlamaIndex tool spec for WebRouter: keyless web search and page extraction, routed across providers.
Project-URL: Homepage, https://docs.webrouter.net
Project-URL: Documentation, https://github.com/yogev-nimble/llama-index-tools-webrouter#readme
Project-URL: Repository, https://github.com/yogev-nimble/llama-index-tools-webrouter
Project-URL: Issues, https://github.com/yogev-nimble/llama-index-tools-webrouter/issues
Author: Nimble
Maintainer: yogev-nimble
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agents,extract,llama-index,llamaindex,tools,web-search,webrouter
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Requires-Python: <4.0,>=3.11
Requires-Dist: llama-index-core<0.15,>=0.13.0
Requires-Dist: webrouter<1,>=0.17.0
Provides-Extra: test
Requires-Dist: mypy>=1.10; extra == 'test'
Requires-Dist: pytest-cov>=6.1; extra == 'test'
Requires-Dist: pytest>=8.3; extra == 'test'
Requires-Dist: ruff<1,>=0.8; extra == 'test'
Description-Content-Type: text/markdown

# WebRouter Tool

[WebRouter](https://github.com/Nimbleway/webrouter) is an open-source (Apache-2.0) Python library that puts one interface in front of several web search and extraction providers. Each call goes to one provider and falls back to the next if that call fails.

**No API key is needed.** By default, calls use keyless providers. Starting with version 0.1.1 (WebRouter 0.17 or later), provider keys in the process environment are ignored. To use a credentialed provider, supply its key explicitly through `provider_config`; calls using that key are billed to its account. Version 0.1.0 reads environment credentials. The examples below describe 0.1.1; check PyPI for release availability.

WebRouter needs Python 3.11 or later.

## Installation

```bash
pip install llama-index-tools-webrouter
```

## Usage

```python
from llama_index.tools.webrouter import WebRouterToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

webrouter_tool = WebRouterToolSpec()
agent = FunctionAgent(
    tools=webrouter_tool.to_tool_list(),
    llm=OpenAI(model="gpt-4o"),
)

await agent.run("What changed in the latest Python release? Read the release notes.")
```

To send every call to one provider instead of letting WebRouter pick, name it and pass its credentials from your application’s secret store (`tavily_key` and `firecrawl_key` below):

```python
webrouter_tool = WebRouterToolSpec(
    search_provider="tavily",
    extract_provider="firecrawl",
    provider_config={
        "tavily": {"api_key": tavily_key},
        "firecrawl": {"api_key": firecrawl_key},
    },
)
```

## Available Functions

`search`: Search the web for a query. Returns a list of Documents, one per result, with the result's text and its `url`, `title`, `published_date` and the `provider` that served it in the metadata. `max_results` sets how many results come back, and `include_domains` limits them to given domains.

`extract`: Read one or more URLs. Returns a list of Documents, one per page, with the page content as markdown and its `url`, `title` and `provider` in the metadata. URLs that could not be read are logged as warnings and left out.

The functions can also be called directly:

```python
from llama_index.tools.webrouter import WebRouterToolSpec

webrouter_tool = WebRouterToolSpec()

for doc in webrouter_tool.search("LlamaIndex agents", max_results=3):
    print(doc.metadata["title"], doc.metadata["url"])

pages = webrouter_tool.extract(["https://docs.llamaindex.ai/"])
print(pages[0].text[:500])
```

This loader is designed to be used as a way to load data as a Tool in an Agent.

## Development

```bash
pip install -e ".[test]"
ruff check . && ruff format --check .
mypy llama_index
pytest
```

The tests run offline, including credential-isolation checks against the real WebRouter library with synthetic keys and mock HTTP transports. [examples/webrouter.ipynb](examples/webrouter.ipynb) runs the tools live; search and extract need no key, the agent cell needs an LLM key.

## Support and license

This package is maintained by the WebRouter maintainers. Report problems in this repository's [issues](https://github.com/yogev-nimble/llama-index-tools-webrouter/issues). Licensed under Apache-2.0.
