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 twin of the sync guard: TavilyExtractorTool._arun raises this ValueError when self.async_client is None. The AsyncTavilyClient is only constructed in __init__ when tavily-python imports successfully, so a None async client means the package was missing (or init took the installer branch) at construction time.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/tavily_extractor_tool/tavily_extractor_tool.py:166
timeout=self.timeout,
),
indent=2,
)
async def _arun(
self,
urls: list[str] | str,
) -> str:
"""Asynchronously extracts content from the given URL(s).
Args:
urls: The URL(s) to extract data from.
Returns:
A JSON string containing the extracted data.
"""
if not self.async_client:
raise ValueError(
"Tavily async client is not initialized. Ensure 'tavily-python' is installed and API key is set."
)
results = await self.async_client.extract(
urls=urls,
extract_depth=self.extract_depth,
include_images=self.include_images,
timeout=self.timeout,
)
return json.dumps(results, indent=2)
View on GitHub (pinned to 754d7323be)
Solutions
- Install tavily-python, then re-instantiate TavilyExtractorTool so async_client is built.
- Confirm the api key resolves at construction (env TAVILY_API_KEY or api_key= argument).
- Guard async calls with a check on tool.async_client before awaiting.
Example fix
# before
result = await tool._arun("https://example.com") # -> ValueError
# after
if not tool.async_client:
tool = TavilyExtractorTool()
result = await tool._arun("https://example.com") Defensive patterns
Strategy: type-guard
Validate before calling
if not getattr(tool, "async_client", None):
raise RuntimeError("TavilyExtractorTool has no async client; re-create the tool") Type guard
def async_extractor_ready(tool) -> bool:
"""True when the async Tavily client is initialized."""
return getattr(tool, "async_client", None) is not None Try / catch
try:
out = await tool._arun(urls)
except ValueError as e:
if "async client is not initialized" in str(e):
tool = TavilyExtractorTool()
out = await tool._arun(urls)
else:
raise Prevention
- Verify tavily-python importability before building async crews that use Tavily tools.
- Check both client and async_client attributes at tool-assembly time.
- Rebuild tool objects whenever the runtime environment changes.
When it happens
Trigger: Awaiting tool._arun(urls) / tool.arun on an instance where tavily-python was unavailable during __init__, so AsyncTavilyClient was never created.
Common situations: Async CrewAI pipelines (arun-based execution) built with a stale tool instance after installing tavily-python post-hoc; mixed sync/async code paths where only the sync client was assumed.
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/b5607e963e67ac8c.
Report an issue: GitHub.