{"record":{"id":"b5607e963e67ac8c","repo":"crewAIInc/crewAI","slug":"tavily-async-client-is-not-initialized-ensure-ta","errorCode":null,"errorMessage":"Tavily async client is not initialized. Ensure 'tavily-python' is installed and API key is set.","messagePattern":"Tavily async client is not initialized\\. Ensure 'tavily-python' is installed and API key is set\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/tavily_extractor_tool/tavily_extractor_tool.py","lineNumber":166,"sourceCode":"                timeout=self.timeout,\n            ),\n            indent=2,\n        )\n\n    async def _arun(\n        self,\n        urls: list[str] | str,\n    ) -> str:\n        \"\"\"Asynchronously extracts content from the given URL(s).\n\n        Args:\n            urls: The URL(s) to extract data from.\n\n        Returns:\n            A JSON string containing the extracted data.\n        \"\"\"\n        if not self.async_client:\n            raise ValueError(\n                \"Tavily async client is not initialized. Ensure 'tavily-python' is installed and API key is set.\"\n            )\n\n        results = await self.async_client.extract(\n            urls=urls,\n            extract_depth=self.extract_depth,\n            include_images=self.include_images,\n            timeout=self.timeout,\n        )\n        return json.dumps(results, indent=2)\n","sourceCodeStart":148,"sourceCodeEnd":177,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/tavily_extractor_tool/tavily_extractor_tool.py#L148-L177","documentation":"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.","triggerScenarios":"Awaiting tool._arun(urls) / tool.arun on an instance where tavily-python was unavailable during __init__, so AsyncTavilyClient was never created.","commonSituations":"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.","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."],"exampleFix":"# before\nresult = await tool._arun(\"https://example.com\")  # -> ValueError\n\n# after\nif not tool.async_client:\n    tool = TavilyExtractorTool()\nresult = await tool._arun(\"https://example.com\")","handlingStrategy":"type-guard","validationCode":"if not getattr(tool, \"async_client\", None):\n    raise RuntimeError(\"TavilyExtractorTool has no async client; re-create the tool\")","typeGuard":"def async_extractor_ready(tool) -> bool:\n    \"\"\"True when the async Tavily client is initialized.\"\"\"\n    return getattr(tool, \"async_client\", None) is not None","tryCatchPattern":"try:\n    out = await tool._arun(urls)\nexcept ValueError as e:\n    if \"async client is not initialized\" in str(e):\n        tool = TavilyExtractorTool()\n        out = await tool._arun(urls)\n    else:\n        raise","preventionTips":["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."],"tags":["tavily","not-initialized","async","lifecycle","crewai-tools"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}