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
TavilyResearchTool._arun raises this ValueError when self._async_client is None prior to awaiting async_client.research(...). As with the sync path, the async client is created only during successful __init__, so the guard rejects calls on a tool that was never properly initialized.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/tavily_research_tool/tavily_research_tool.py:181
),
)
if use_stream:
return cast(Generator[bytes, None, None], result)
return self._stringify_response(result)
async def _arun(
self,
input: str,
model: Literal["mini", "pro", "auto"] | None = None,
output_schema: dict[str, Any] | None = None,
stream: bool | None = None,
citation_format: Literal["numbered", "mla", "apa", "chicago"] | None = None,
) -> str | AsyncGenerator[bytes, None]:
"""Asynchronously creates Tavily research tasks or streams results."""
if not self._async_client:
raise ValueError(
"Tavily async client is not initialized. Ensure 'tavily-python' is "
"installed and API key is set."
)
use_stream = self.stream if stream is None else stream
result = await self._async_client.research(
input=input,
model=self.model if model is None else model,
output_schema=self.output_schema
if output_schema is None
else output_schema,
stream=use_stream,
citation_format=(
self.citation_format if citation_format is None else citation_format
),
)
if use_stream:View on GitHub (pinned to 754d7323be)
Solutions
- Install tavily-python, confirm TAVILY_API_KEY, and instantiate a new TavilyResearchTool.
- Check tool._async_client truthiness before the awaited call; rebuild if missing.
Example fix
# before
out = await tool._arun(input="...") # -> ValueError
# after
if not tool._async_client:
tool = TavilyResearchTool()
out = await tool._arun(input="...") Defensive patterns
Strategy: type-guard
Validate before calling
if not getattr(tool, "_async_client", None):
raise RuntimeError("TavilyResearchTool async client missing; rebuild the tool") Type guard
def async_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(input="...")
except ValueError as e:
if "async client is not initialized" in str(e):
tool = TavilyResearchTool()
out = await tool._arun(input="...")
else:
raise Prevention
- Check _async_client when assembling async crews.
- Install deps and set TAVILY_API_KEY before app start.
- Treat a None client as a build-time configuration bug, not a runtime surprise.
When it happens
Trigger: Awaiting tool._arun(input=...) on an instance constructed without tavily-python (or with client creation skipped).
Common situations: Async agent pipelines holding long-lived tool objects across environment fixes; deploying code that constructs tools before env vars/deps are ready.
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/f18230ea984802aa.
Report an issue: GitHub.