Valyu integrates seamlessly with LangChain as a search tool, allowing you to enhance your AI agents and RAG applications with real-time web search and proprietary data sources. The integration provides LLM-ready context from multiple sources including web pages, academic journals, financial data, and more.The package includes two main tools:
ValyuSearchTool: Deep search operations with comprehensive parameter control
ValyuContentsTool: Extract clean content from specific URLs
The ValyuSearchTool supports comprehensive search parameters for fine-tuned control:
import { ValyuSearchTool, ValyuAdapter } from "@valyu/langchain";const valyuClient = new ValyuAdapter(process.env.VALYU_API_KEY!);const tool = new ValyuSearchTool({ client: valyuClient,});const results = await tool.invoke({ query: "quantum computing breakthroughs 2024", search_type: "all", // "all", "web", or "proprietary" - Note: use "all" when using included_sources with URLs max_num_results: 10, // 1-20 results for standard API keys, up to 100 with a special API key relevance_threshold: 0.6, // 0.0-1.0 relevance score max_price: 30.0, // Maximum cost in dollars is_tool_call: true, // Optimized for LLM consumption start_date: "2024-01-01", // Time filtering (YYYY-MM-DD) end_date: "2024-12-31", included_sources: ["valyu/valyu-arxiv", "valyu/valyu-pubmed"], // Include specific sources excluded_sources: ["example.com"], // Exclude sources response_length: "medium", // "short", "medium", "large", "max", or int country_code: "US", // 2-letter ISO country code fast_mode: false, // Enable for faster but shorter results});
import { ValyuSearchTool, ValyuAdapter } from "@valyu/langchain";import { ChatAnthropic } from "@langchain/anthropic";import { createReactAgent } from "@langchain/langgraph/prebuilt";import { HumanMessage, SystemMessage } from "@langchain/core/messages";const valyuClient = new ValyuAdapter(process.env.VALYU_API_KEY!);const financialLLM = new ChatAnthropic({ model: "claude-sonnet-4-20250514", apiKey: process.env.ANTHROPIC_API_KEY,});const valyuTool = new ValyuSearchTool({ client: valyuClient,});const financialAgent = createReactAgent({ llm: financialLLM, tools: [valyuTool],});const query = "What are the latest developments in cryptocurrency regulation and their impact on institutional adoption?";const systemContext = new SystemMessage(`You are a financial research assistant. Use Valyu to search for:- Real-time market data and news- Academic research on financial models- Economic indicators and analysisAlways cite your sources and provide context about data recency.`);const stream = await financialAgent.stream({ messages: [systemContext, new HumanMessage(query)],});for await (const step of stream) { console.log(step.messages[step.messages.length - 1].content);}
import { SystemMessage, HumanMessage } from "@langchain/core/messages";import { ValyuSearchTool, ValyuAdapter } from "@valyu/langchain";import { createReactAgent } from "@langchain/langgraph/prebuilt";import { ChatAnthropic } from "@langchain/anthropic";const valyuClient = new ValyuAdapter(process.env.VALYU_API_KEY!);const systemMessage = new SystemMessage(`You are an AI research assistant with access to Valyu search.SEARCH GUIDELINES:- Use search_type="proprietary" for academic/scientific queries- Use search_type="web" for current events and general web content- Use search_type="all" for comprehensive research- Set higher relevance_threshold (0.6+) for precise results- Do not use search operators (e.g., site:, OR, AND, quotes). Use natural keyword queries instead.- Always cite sources from search resultsRESPONSE FORMAT:- Provide direct answers based on search results- Include source citations with URLs when available- Mention publication dates for time-sensitive information- Indicate if information might be outdated`);const llm = new ChatAnthropic({ model: "claude-sonnet-4-20250514", apiKey: process.env.ANTHROPIC_API_KEY,});const valyuTool = new ValyuSearchTool({ client: valyuClient,});const agent = createReactAgent({ llm, tools: [valyuTool] });const stream = await agent.stream({ messages: [systemMessage, new HumanMessage("Your query here")],});for await (const step of stream) { console.log(step.messages[step.messages.length - 1].content);}
For complete query writing guidelines and how to use API parameters instead,
see the Prompting Guide.
max_price: Maximum cost in dollars (default: 50.0)
is_tool_call: Optimize for LLM consumption (default: true)
start_date: Start date for time filtering in YYYY-MM-DD format (optional)
end_date: End date for time filtering in YYYY-MM-DD format (optional)
included_sources: Array of URLs/domains/datasets to include (optional)
excluded_sources: Array of URLs/domains/datasets to exclude (optional)
response_length: Content length - number (character count), “short”, “medium”, “large”, or “max” (optional)
country_code: 2-letter ISO country code for geo-bias, e.g., “US”, “GB” (optional)
fast_mode: Enable for faster but shorter results (default: false)
Note: The tool returns a JSON string. Use JSON.parse() to convert it to an object. The response structure includes a results array with search results.