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

  1. Install tavily-python, set TAVILY_API_KEY, and construct a new TavilyGetResearchTool.
  2. 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

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


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/41a438e7439f2ad1. Report an issue: GitHub.