Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain ExaSearchTools

From Leeroopedia
Knowledge Sources
Domains Tools, Web Search, Exa
Last Updated 2026-02-11 00:00 GMT

Overview

This module provides ExaSearchResults and ExaFindSimilarResults, two LangChain tool implementations that wrap the Exa Search API for query-based search and URL-based similarity search respectively.

Description

The module defines two BaseTool subclasses in the langchain_exa package:

  • ExaSearchResults -- A tool that performs Exa searches given a text query and returns search results with content, supporting neural, keyword, and auto search types.
  • ExaFindSimilarResults -- A tool that finds pages similar to a given URL using Exa's similarity search, with support for domain filtering, date filtering, and content options.

Both tools validate the Exa API key from the environment and instantiate an Exa client. They support configurable parameters for search refinement including domain filtering, date ranges, content highlighting, summaries, and live crawling.

Usage

Import these tools when building LangChain agents that need web search or similar-page discovery capabilities powered by the Exa API.

Code Reference

Source Location

Signature

class ExaSearchResults(BaseTool):
    name: str = "exa_search_results_json"
    description: str = "A wrapper around Exa Search. ..."
    client: Exa
    exa_api_key: SecretStr

    def _run(
        self,
        query: str,
        num_results: int = 10,
        text_contents_options: TextContentsOptions | dict[str, Any] | bool | None = None,
        highlights: HighlightsContentsOptions | bool | None = None,
        include_domains: list[str] | None = None,
        exclude_domains: list[str] | None = None,
        start_crawl_date: str | None = None,
        end_crawl_date: str | None = None,
        start_published_date: str | None = None,
        end_published_date: str | None = None,
        use_autoprompt: bool | None = None,
        livecrawl: Literal["always", "fallback", "never"] | None = None,
        summary: bool | dict[str, str] | None = None,
        type: Literal["neural", "keyword", "auto"] | None = None,
        run_manager: CallbackManagerForToolRun | None = None,
    ) -> list[dict] | str: ...


class ExaFindSimilarResults(BaseTool):
    name: str = "exa_find_similar_results_json"
    description: str = "A wrapper around Exa Find Similar. ..."
    client: Exa
    exa_api_key: SecretStr
    exa_base_url: str | None = None

    def _run(
        self,
        url: str,
        num_results: int = 10,
        text_contents_options: TextContentsOptions | dict[str, Any] | bool | None = None,
        highlights: HighlightsContentsOptions | bool | None = None,
        include_domains: list[str] | None = None,
        exclude_domains: list[str] | None = None,
        start_crawl_date: str | None = None,
        end_crawl_date: str | None = None,
        start_published_date: str | None = None,
        end_published_date: str | None = None,
        exclude_source_domain: bool | None = None,
        category: str | None = None,
        livecrawl: Literal["always", "fallback", "never"] | None = None,
        summary: bool | dict[str, str] | None = None,
        run_manager: CallbackManagerForToolRun | None = None,
    ) -> list[dict] | str: ...

Import

from langchain_exa import ExaSearchResults, ExaFindSimilarResults

I/O Contract

Inputs (ExaSearchResults._run)

Name Type Required Description
query str Yes The search query.
num_results int No Number of results to return (1 to 100). Default: 10.
text_contents_options dict | bool | None No How to set page content of results.
highlights bool | None No Whether to include highlights.
include_domains None No Domains to include.
exclude_domains None No Domains to exclude.
start_crawl_date None No Start date for crawl (YYYY-MM-DD).
end_crawl_date None No End date for crawl (YYYY-MM-DD).
start_published_date None No Start publication date (YYYY-MM-DD).
end_published_date None No End publication date (YYYY-MM-DD).
use_autoprompt None No Whether to use autoprompt.
livecrawl None No Live crawl option.
summary dict[str, str] | None No Whether to include summary.
type None No Search type.

Inputs (ExaFindSimilarResults._run)

Name Type Required Description
url str Yes The URL to find similar pages for.
num_results int No Number of results (1 to 100). Default: 10.
exclude_source_domain None No If True, exclude pages from the same domain as the source URL.
category None No Filter for similar pages by category.

Outputs

Name Type Description
return str Search results as a list of dictionaries, or an error string if an exception occurs.

Usage Examples

Basic Usage

from langchain_exa import ExaSearchResults, ExaFindSimilarResults

# Search tool
search_tool = ExaSearchResults()
results = search_tool.invoke({"query": "latest AI research", "num_results": 5})

# Find similar tool
similar_tool = ExaFindSimilarResults()
results = similar_tool.invoke({
    "url": "https://arxiv.org/abs/2301.00001",
    "num_results": 5,
})

With ToolCall

from langchain_exa import ExaSearchResults

tool = ExaSearchResults()
result = tool.invoke({
    "args": {"query": "what is the weather in SF", "num_results": 1},
    "id": "1",
    "name": tool.name,
    "type": "tool_call",
})

Related Pages

  • Requires langchain-exa and exa-py packages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment