> ## Documentation Index
> Fetch the complete documentation index at: https://docs.webrouter.net/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> Add WebRouter search and extraction tools to a LangChain agent.

WebRouter is [listed in LangChain’s integration catalog](https://docs.langchain.com/oss/python/integrations/providers/all_providers#:~:text=WebRouter%20provides%20LangChain%20tools).

`web_router.integrations.langchain` puts search and extract in front of a
LangChain agent as two tools, `web_search` and `web_extract`. The `langchain`
extra adds `langchain-core`, all the tools need; the agent loop and the model
are your own install, here `langchain` and `langchain-openai`:

```bash theme={null}
pip install "webrouter[langchain]" langchain langchain-openai
```

```python theme={null}
from langchain.agents import create_agent
from web_router import WebRouter
from web_router.integrations.langchain import web_router_tools

tools = web_router_tools(WebRouter(use_environment=False), max_results=5)
agent = create_agent("openai:gpt-4.1", tools=tools)
```

The tools in this example use keyless web backends. The model uses its own key
(`OPENAI_API_KEY` here). To enable a keyed web backend, pass its credentials
explicitly in [`provider_config`](https://docs.webrouter.net/configuration#keys-from-code-only).

`provider="tavily"` sends every call to one backend, which then needs its key.
A name that only searches leaves extract on the default routing;
`extract_provider=` picks that one.

Or build them one at a time — `WebRouterSearch(router=..., provider=...,
max_results=..., search_depth=...)` and `WebRouterExtract(...)` — and pass
`async_router=AsyncWebRouter(use_environment=False)` to serve `agent.ainvoke`
without a worker thread.
`WebRouterAnswer(router=..., provider="linkup")` adds `web_answer`, a backend's
written answer to one question with its sources. It is not among
`web_router_tools()`: every answer backend needs a key and bills each call.

**The model supplies the query or the URLs; you supply everything else.** The
provider, `max_results`, `search_depth` and the domain filters are fixed when
the tool is built and sent unchanged on every call, so an agent behaves the
same whichever backend serves it and switching backends is one argument. An
option the provider does not map raises on the first call, to you — not to the
model, which could not fix it.

**The model reads a compact rendering; you keep the whole response.** Each
tool answers in LangChain's `content_and_artifact` form: the model sees JSON in
one layout for every backend, each result's text cut to `result_chars` (a
page to `document_chars`), and the tool message's `artifact` carries the
untouched `SearchResponse` or `ExtractResponse`. A backend failure, or a call
past `timeout`, reaches the model as the short error the Claude and OpenAI
tools give (see [What the model reads when a call fails](https://docs.webrouter.net/integrations.md#what-the-model-reads-when-a-call-fails));
`web_extract` names the URLs it could not read rather than failing the call,
and refuses private hosts unless built with `url_policy=None`.

[Back to Integrations](https://docs.webrouter.net/integrations/overview.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.