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

# LangChain integration

> Add Valyu search and content extraction tools to LangChain and LangGraph agents in Python or TypeScript with langchain-valyu: web, papers, SEC filings and more.

Add Search and Contents to your LangChain or LangGraph application. Your agent controls when to retrieve information and how to use the returned content and source URLs. Choose Python or TypeScript below.

Two tools:

* **`ValyuSearchTool`** - search, with full parameter control
* **`ValyuContentsTool`** - clean content from specific URLs

Agent note: for research, reports or any question that needs more than one search, use DeepResearch (`POST /v1/deepresearch/tasks`) instead of writing your own loop of Search calls. Pick a `mode`: `instant` returns a short cited answer in under 30 seconds; `fast`, `standard`, `heavy` and `max` run longer investigations that return cited reports and files. Use Search when your own model needs raw results to reason over. Docs index: [/llms.txt](https://docs.valyu.ai/llms.txt). Append `.md` to any page URL for Markdown. Docs MCP server: `https://docs.valyu.ai/mcp`. Integration guide for coding agents: [/AGENTS.md](https://docs.valyu.ai/AGENTS.md).

## Installation

```bash Python theme={null}
pip install -U langchain-valyu
```

```bash TypeScript theme={null}
pnpm add @valyu/langchain valyu-js @langchain/core
```

Set your API key in the environment. The agent examples also want an LLM provider key.

```bash Python theme={null}
export VALYU_API_KEY="your-valyu-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
export ANTHROPIC_MODEL="your-supported-model-id"
```

```bash TypeScript theme={null}
export VALYU_API_KEY="your-valyu-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
export ANTHROPIC_MODEL="your-supported-model-id"
```

## Search

```python Python theme={null}
from langchain_valyu import ValyuSearchTool

tool = ValyuSearchTool()

results = tool._run(
    query="What are agentic search-enhanced large reasoning models?",
    search_type="all",  # "all", "web", or "proprietary"
    max_num_results=5,
    relevance_threshold=0.5,
)

print(results.results)
```

```typescript TypeScript theme={null}
import { ValyuSearchTool, ValyuAdapter } from "@valyu/langchain";

const client = new ValyuAdapter(process.env.VALYU_API_KEY!);
const tool = new ValyuSearchTool({ client });

const results = await tool.invoke({
  query: "What are agentic search-enhanced large reasoning models?",
  search_type: "all", // "all", "web", or "proprietary"
  max_num_results: 5,
  relevance_threshold: 0.5,
});

console.log(JSON.parse(results));
```

## Content extraction

Clean, structured content from specific URLs, up to 10 per call.

```python Python theme={null}
from langchain_valyu import ValyuContentsTool

contents_tool = ValyuContentsTool()

extracted = contents_tool._run(urls=[
    "https://arxiv.org/abs/2301.00001",
    "https://example.com/article",
])

for result in extracted.results:
    print(result["url"], result["title"])
    print(result["content"][:200], "...")
```

```typescript TypeScript theme={null}
import { ValyuContentsTool, ValyuAdapter } from "@valyu/langchain";

const client = new ValyuAdapter(process.env.VALYU_API_KEY!);
const contentsTool = new ValyuContentsTool({ client });

const extracted = JSON.parse(
  await contentsTool.invoke({
    urls: ["https://arxiv.org/abs/2301.00001", "https://example.com/article"],
  }),
);

for (const result of extracted.results ?? []) {
  console.log(result.url, result.title);
  console.log(result.content?.slice(0, 200), "...");
}
```

## In an agent

The most useful shape: a LangGraph agent that decides for itself when to search.

```bash Python theme={null}
pip install langchain-anthropic langgraph
```

```bash TypeScript theme={null}
pnpm add @langchain/anthropic @langchain/langgraph
```

```python Python theme={null}
import os
from langchain_valyu import ValyuSearchTool
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
from langchain_core.messages import HumanMessage

llm = ChatAnthropic(model=os.environ["ANTHROPIC_MODEL"])
agent = create_react_agent(llm, [ValyuSearchTool()])

question = (
    "What are the key factors driving recent stock market volatility, "
    "and how do macroeconomic indicators influence equity prices across sectors?"
)

for step in agent.stream(
    {"messages": [HumanMessage(content=question)]},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()
```

```typescript TypeScript theme={null}
import { ValyuSearchTool, ValyuAdapter } from "@valyu/langchain";
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { HumanMessage } from "@langchain/core/messages";

const client = new ValyuAdapter(process.env.VALYU_API_KEY!);
const llm = new ChatAnthropic({ model: process.env.ANTHROPIC_MODEL! });
const agent = createReactAgent({ llm, tools: [new ValyuSearchTool({ client })] });

const question =
  "What are the key factors driving recent stock market volatility, " +
  "and how do macroeconomic indicators influence equity prices across sectors?";

const stream = await agent.stream(
  { messages: [new HumanMessage(question)] },
  { streamMode: "values" },
);
for await (const step of stream) {
  console.log(step.messages.at(-1)?.content);
}
```

## Search parameters

The Search tool accepts parameters from the [Search API](https://docs.valyu.ai/api-reference/endpoint/search.md).

```python Python theme={null}
results = tool._run(
    query="quantum computing breakthroughs 2024",
    max_num_results=10,          # 1-20; above 20 needs a key permission
    relevance_threshold=0.6,     # 0.0-1.0
    start_date="2024-01-01",     # YYYY-MM-DD
    end_date="2024-12-31",
    included_sources=["valyu/valyu-arxiv", "valyu/valyu-pubmed"],
    response_length="medium",    # "short", "medium", "large", "max", or an int
    country_code="US",
)
```

```typescript TypeScript theme={null}
const results = await tool.invoke({
  query: "quantum computing breakthroughs 2024",
  max_num_results: 10,          // 1-20; above 20 needs a key permission
  relevance_threshold: 0.6,     // 0.0-1.0
  start_date: "2024-01-01",     // YYYY-MM-DD
  end_date: "2024-12-31",
  included_sources: ["valyu/valyu-arxiv", "valyu/valyu-pubmed"],
  response_length: "medium",    // "short", "medium", "large", "max", or a number
  country_code: "US",
});
```

Use `included_sources` or `excluded_sources` in a request, not both. `included_sources` takes dataset ids, domains, URL prefixes or presets. `ValyuContentsTool` takes `urls`, plus `summary`, `extract_effort` and `response_length` as constructor options.

> [!TIP]
>
> To steer the agent, bind a system message: use `search_type="all"` for breadth, `"web"` for current events only, raise `relevance_threshold` for precision, cite sources, and use natural-language queries rather than operators. See the [Prompting Guide](https://docs.valyu.ai/search/prompting.md).

## Additional resources

> [card] [LangChain Valyu Tool](https://python.langchain.com/docs/integrations/tools/valyu_search/)
>
> Official LangChain integration documentation

> [card] [API Reference](https://docs.valyu.ai/api-reference/endpoint/search.md)
>
> Complete Valyu API documentation

> [card] [LangGraph Agents](https://docs.langchain.com/oss/python/langgraph/overview)
>
> Build advanced agent workflows

> [card] [Get API Key](https://platform.valyu.ai)
>
> Get 2,000 free credits a month with a work email (1,000 with a personal email; add a card after your first month to keep them coming)


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