Represents built-in tools available from AI/LLM services that can be used within the LangChain framework.
Native tools are functionalities provided directly by language model services (like Google AI, OpenAI) that can be invoked by LLMs to perform specific actions or retrieve information. They are "native" because they're built into the AI service itself, rather than implemented externally.
Each native tool has:
- A unique name that identifies it (e.g., "google_search", "code_interpreter")
- A configuration map that contains tool-specific settings
Google Search Grounding
Starting with Gemini 2.0, Google Search is available as a native tool. This enables the model to decide when to use Google Search to enhance the factuality and recency of responses.
Google Search as a tool enables:
- More accurate and up-to-date answers with grounding sources
- Retrieving information from the web for further analysis
- Finding relevant images, videos, or other media for multimodal reasoning
- Supporting specialized tasks like coding, technical troubleshooting, etc.
Example with Google Search
alias LangChain.Chains.LLMChain
alias LangChain.Message
alias LangChain.NativeTool
model = ChatGoogleAI.new!(%{temperature: 0, stream: false, model: "gemini-2.0-flash"})
{:ok, updated_chain} =
%{llm: model, verbose: false, stream: false}
|> LLMChain.new!()
|> LLMChain.add_message(
Message.new_user!("What is the current Google stock price?")
)
|> LLMChain.add_tools(NativeTool.new!(%{name: "google_search", configuration: %{}}))
|> LLMChain.run()Tool Search
tool_search/1 builds a provider-neutral search tool. Add it to a chain
alongside functions marked defer_loading: true (see "Tool search options"
in LangChain.Function). Deferred functions are declared on every request
but kept out of the model's context until the model searches for them, so
the request prefix never changes and prompt caching keeps working.
chain
|> LLMChain.add_tools(NativeTool.tool_search())
|> LLMChain.add_tools(deferred_functions)Keep at least one function, normally the most-used ones, not deferred.
A chat model that offers tool search translates the tool for its provider.
A chat model without tool search falls back: it leaves the search tool out
of the request and sends deferred functions as ordinary tools, so every tool
is available from the start. Search items another model added to the
conversation are left out, and :tool_reference parts are sent as text. A
chain configured for tool search therefore runs on any chat model, which
keeps fallbacks and model swaps working.
| Chat model | Tool search | Namespaces | Verified |
|---|---|---|---|
LangChain.ChatModels.ChatAnthropic | Server-side search (:bm25 or :regex), and client-side loading with :tool_reference parts | Not used | Live |
LangChain.ChatModels.ChatOpenAIResponses | OpenAI's hosted search; :variant does not apply | Yes | Live |
LangChain.ChatModels.ChatReqLLM, anthropic: models | Server-side and client-side, as ChatAnthropic | Not used | Live |
LangChain.ChatModels.ChatReqLLM, Anthropic models on amazon_bedrock: | Server-side and client-side | Not used | Request encoding only |
LangChain.ChatModels.ChatReqLLM, openai: models | OpenAI's hosted search; :variant does not apply | Yes | Live |
LangChain.ChatModels.ChatReqLLM, any other provider | Falls back | Request encoding | |
LangChain.ChatModels.ChatOpenAI, LangChain.ChatModels.ChatOpenAICompatible, LangChain.ChatModels.ChatAwsMantle | Falls back. The Chat Completions API rejects the search tool. | Request encoding and replay | |
LangChain.ChatModels.ChatDeepSeek, LangChain.ChatModels.ChatGoogleAI, LangChain.ChatModels.ChatVertexAI, LangChain.ChatModels.ChatGrok, LangChain.ChatModels.ChatMistralAI, LangChain.ChatModels.ChatOllamaAI, LangChain.ChatModels.ChatOrq, LangChain.ChatModels.ChatPerplexity | Falls back | Request encoding | |
LangChain.ChatModels.ChatBumblebee | Falls back | Untested |
"Live" means a model searched for a deferred tool, called it, and accepted the replayed conversation on a later turn. "Request encoding" means unit tests of the request body only.
A chat model without tool search uses drop_tool_search/1 to leave the
search tool out.
Summary
Functions
Remove the tool search tool from a list of tools.
Build a new native tool.
Build a new native tool and return it or raise an error if invalid.
Build the provider-neutral tool search tool.
Return true when the tool is the tool search tool built by tool_search/1.
Types
Functions
Remove the tool search tool from a list of tools.
A chat model without tool search calls this before encoding its tools, so a chain configured for tool search runs on it with every function mounted. Deferred functions are left in the list and sent as ordinary tools. A debug message is logged when the search tool is removed.
@spec new(attrs :: map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Build a new native tool.
Build a new native tool and return it or raise an error if invalid.
Build the provider-neutral tool search tool.
Options
:variant- How the model writes its search, on providers that offer a choice.:bm25(default) searches with natural language queries;:regexsearches with regular expressions. Providers with a single kind of search ignore it.
Return true when the tool is the tool search tool built by tool_search/1.