crewAIInc/crewAI · error · ValueError
Tavily async client is not initialized. Ensure 'tavily-pytho
Error message
Tavily async client is not initialized. Ensure 'tavily-python' is installed and API key is set.
What it means
Async counterpart: TavilyGetResearchTool._arun raises this ValueError when self._async_client is None before awaiting get_research(request_id). The AsyncTavilyClient is only created in __init__ when tavily-python is available, so the guard indicates the tool was constructed without a working client.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/tavily_get_research_tool/tavily_get_research_tool.py:115
def _stringify_response(response: Any) -> str:
if isinstance(response, str):
return response
return json.dumps(response, indent=2)
def _run(self, request_id: str) -> str:
"""Synchronously retrieves Tavily research task status and results."""
if not self._client:
raise ValueError(
"Tavily client is not initialized. Ensure 'tavily-python' is "
"installed and API key is set."
)
return self._stringify_response(self._client.get_research(request_id))
async def _arun(self, request_id: str) -> str:
"""Asynchronously retrieves Tavily research task status and results."""
if not self._async_client:
raise ValueError(
"Tavily async client is not initialized. Ensure 'tavily-python' is "
"installed and API key is set."
)
return self._stringify_response(
await self._async_client.get_research(request_id)
)
View on GitHub (pinned to 754d7323be)
Solutions
- Install tavily-python, set TAVILY_API_KEY, and construct a new TavilyGetResearchTool.
- Guard async invocations on tool._async_client being truthy.
Example fix
# before
res = await tool._arun(req_id) # -> ValueError
# after
if not tool._async_client:
tool = TavilyGetResearchTool()
res = await tool._arun(req_id) Defensive patterns
Strategy: type-guard
Validate before calling
if not getattr(tool, "_async_client", None):
raise RuntimeError("TavilyGetResearchTool async client missing; rebuild the tool") Type guard
def async_get_research_ready(tool) -> bool:
"""True when the async Tavily research client exists."""
return getattr(tool, "_async_client", None) is not None Try / catch
try:
out = await tool._arun(request_id)
except ValueError as e:
if "async client is not initialized" in str(e):
tool = TavilyGetResearchTool()
out = await tool._arun(request_id)
else:
raise Prevention
- Validate async client presence during crew assembly.
- Install tavily-python before app start; never rely on post-hoc installs with long-lived tools.
- Set TAVILY_API_KEY in the environment where tools are constructed.
When it happens
Trigger: Awaiting tool._arun(request_id) on an instance built while tavily-python was missing or init otherwise skipped client creation.
Common situations: Async crews reusing stale tool objects after installing the dependency; environments where TAVILY_API_KEY was absent at build time.
Related errors
- Tavily async client is not initialized. Ensure 'tavily-pytho
- Tavily async client is not initialized. Ensure 'tavily-pytho
- Tavily client is not initialized. Ensure 'tavily-python' is
- Tavily client is not initialized. Ensure 'tavily-python' is
- Tavily client is not initialized. Ensure 'tavily-python' is
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/41a438e7439f2ad1.
Report an issue: GitHub.