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
import osfrom langchain_valyu import ValyuSearchTool# Set your API keyos.environ["VALYU_API_KEY"] = "your-api-key-here"# Initialize the search tooltool = ValyuSearchTool()# Perform a searchsearch_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, max_price=30.0)print("Search Results:", search_results.results)
The ValyuSearchTool supports comprehensive search parameters for fine-tuned control:
from langchain_valyu import ValyuSearchTooltool = ValyuSearchTool()# Advanced search with all available parametersresults = tool._run( query="quantum computing breakthroughs 2024", search_type="proprietary", # "all", "web", or "proprietary" max_num_results=10, # 1-20 results for standard API keys, up to 100 with a [special API key](http://platform.valyu.ai/user/account/apikeys?req=increase_results) 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)
from langchain_valyu import ValyuSearchToolfrom langchain_anthropic import ChatAnthropicfrom langgraph.prebuilt import create_react_agentfrom langchain_core.messages import HumanMessage, SystemMessage# Create financial research agentfinancial_llm = ChatAnthropic(model="claude-sonnet-4-20250514")valyu_tool = ValyuSearchTool()financial_agent = create_react_agent(financial_llm, [valyu_tool])# Query financial markets with system contextquery = "What are the latest developments in cryptocurrency regulation and their impact on institutional adoption?"system_context = SystemMessage(content="""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.""")for step in financial_agent.stream( {"messages": [system_context, HumanMessage(content=query)]}, stream_mode="values",): step["messages"][-1].pretty_print()
# Set appropriate price limits based on use casetool = ValyuSearchTool()# For quick lookupsquick_search = tool._run( query="current bitcoin price", max_price=30.0, # Lower cost for simple queries max_num_results=3)# For comprehensive researchdetailed_search = tool._run( query="comprehensive analysis of renewable energy trends", max_price=50.0, # Higher budget for complex queries max_num_results=15, search_type="all")
from langchain_core.messages import SystemMessage, HumanMessage# Optimize agent behavior with good system messagessystem_message = SystemMessage(content="""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="news" for news articles only- Use search_type="all" for comprehensive research- Set higher relevance_threshold (0.6+) for precise results- Use category parameter to guide search context- 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""")valyu_tool = ValyuSearchTool()agent = create_react_agent(llm, [valyu_tool])# Use the agent with system contextfor step in agent.stream( {"messages": [system_message, HumanMessage(content="Your query here")]}, stream_mode="values",): step["messages"][-1].pretty_print()
For complete query writing guidelines and how to use API parameters instead, see the Prompting Guide.
max_price: Maximum cost in dollars per thousand retrievals (CPM). Only applies when provided. If not provided, adjusts automatically based on search type and max number of results.
is_tool_call: Optimize for LLM consumption (default: true)
start_date/end_date: Time filtering in YYYY-MM-DD format (optional)
included_sources: List of URLs/domains to include (optional)
excluded_sources: List of URLs/domains to exclude (optional)