Tavily Core
Documentation of the TavilyDeepResearch class, the dynamic wrapper over the Tavily API used by the Deep Research module.
On this page
#Overview
The TavilyDeepResearch class is a dynamic wrapper over the TavilyClient of the tavily library. Instead of defining its own signature for each operation, each method receives a single configuration dictionary (params) and forwards it, as named arguments, to the corresponding method of the Tavily client.
In practice, this gives maximum flexibility: any parameter accepted by Tavily can be sent without changing the class. It is the Tavily access layer used by the Context Builder, which turns a web search into context ready for language models.
#Execution Flow
- Instantiation: the class receives an optional API key. If it is not provided, it is read from the
TAVILY_API_KEYenvironment variable. - Key validation: if no key is found, a
RuntimeErroris raised. - Client creation: a
TavilyClientis created with the key and stored inself.client. - Method call: the user calls a method (for example,
start_search) passing a dictionary with the operation's parameters. - Parameter forwarding: the dictionary is unpacked with
**paramsand sent to the same-named method of the Tavily client, whose return value is returned unchanged.
#Class Methods Table
| Method | Tavily client method | Description |
|---|---|---|
__init__ | — | Resolves the API key and creates the Tavily client. |
start_search | search | General search. |
get_context | get_search_context | Returns context for LLMs. |
qna | qna_search | Direct question and answer. |
extract_content | extract | Content extraction from URLs. |
map_site | map | Maps the URL structure of a site. |
crawl_site | crawl | Explores a site recursively. |
get_company | get_company_info | Firmographic data of a company. |
start_research | research | Starts the autonomous research agent. |
get_research_status | get_research | Checks the status of a research. |
#Environment Variables
TAVILY_API_KEY: Tavily API key. Used whenapi_keyis not passed to the constructor. The module callsload_dotenv()when imported, so the variable can also come from a.envfile.
#Important Architecture Points and Insights
- Thin, dynamic wrapper: the class neither validates nor transforms the parameters; it only forwards them. The accepted names and values are those of the
tavilylibrary. - Return without processing: the methods return exactly what the Tavily client returns. Processing, filtering and formatting are left to the caller, such as the Context Builder.
- Errors: besides the key check in the constructor, the class does not catch exceptions. Any Tavily error propagates to the caller.
- Autonomous research topic: in
start_research, the topic is sent in theinputkey, which is the name used by the original library'sresearchmethod.
#Class and Methods Description
#TavilyDeepResearch Class
#Description
Dynamic wrapper for Tavily AI. Receives configuration dictionaries for maximum flexibility.
#Constructor Arguments
| Argument | Type | Description | Default Value |
|---|---|---|---|
api_key | str | None | Tavily API key. If omitted, uses TAVILY_API_KEY. | None |
#Methods
#1. __init__
#Description
Resolves the API key (argument or environment variable) and creates the TavilyClient.
#Arguments
api_key(str | None): Tavily API key.
#Returns
- Does not return a value.
#Raises
RuntimeError: if the key is not provided andTAVILY_API_KEYis not defined.
#Examples
# Usando a chave definida em TAVILY_API_KEY
researcher = TavilyDeepResearch()
# Informando a chave diretamente
researcher = TavilyDeepResearch(api_key="tvly-...")#2. start_search
#Description
General search. Expects keys such as query, search_depth, max_results, among others accepted by Tavily.
#Arguments
params(Dict[str, Any]): search parameters, forwarded toclient.search.
#Returns
dict: search response.
#Examples
result = researcher.start_search({
"query": "Quais as principais tendências de IA em 2026?",
"search_depth": "advanced",
"max_results": 5,
})#3. get_context
#Description
Returns context for LLMs. Expects query, max_tokens, among others.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.get_search_context.
#Returns
str: context for use in language models.
#Examples
context = researcher.get_context({"query": "tendências de IA em 2026", "max_tokens": 1500})#4. qna
#Description
Direct question and answer. Usually requires only {'query': 'sua pergunta'}.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.qna_search.
#Returns
str: answer to the question.
#Examples
answer = researcher.qna({"query": "Quem criou a linguagem Python?"})#5. extract_content
#Description
Content extraction. Expects urls (list or string) and format.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.extract.
#Returns
dict: extracted content.
#Examples
content = researcher.extract_content({"urls": ["https://example.com"], "format": "markdown"})#6. map_site
#Description
Maps the URL structure of a site. Expects url and, optionally, limit.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.map.
#Returns
dict: map of the site's URLs.
#Examples
site_map = researcher.map_site({"url": "https://example.com", "limit": 50})#7. crawl_site
#Description
Explores a site recursively. Expects url, limit and max_depth.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.crawl.
#Returns
dict: result of the exploration.
#Examples
crawl = researcher.crawl_site({"url": "https://example.com", "limit": 20, "max_depth": 2})#8. get_company
#Description
Firmographic data of a company. Expects query.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.get_company_info.
#Returns
List[dict]: company data.
#Examples
company = researcher.get_company({"query": "Tavily"})#9. start_research
#Description
Starts the autonomous research agent. Expects input (the topic) and model.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.research. The original library usesinputfor the topic.
#Returns
dict: response to the research request.
#Examples
research = researcher.start_research({"input": "Mercado de energia solar no Brasil", "model": "gpt-4o-mini"})#10. get_research_status
#Description
Checks the status of a research started with start_research. Expects request_id.
#Arguments
params(Dict[str, Any]): parameters forwarded toclient.get_research.
#Returns
dict: research status.
#Examples
status = researcher.get_research_status({"request_id": "..."})Source: src/deep_research/tavily_research/tavily_core.py