{"record":{"id":"41a438e7439f2ad1","repo":"crewAIInc/crewAI","slug":"tavily-async-client-is-not-initialized-ensure-ta-41a438","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_get_research_tool/tavily_get_research_tool.py","lineNumber":115,"sourceCode":"    def _stringify_response(response: Any) -> str:\n        if isinstance(response, str):\n            return response\n        return json.dumps(response, indent=2)\n\n    def _run(self, request_id: str) -> str:\n        \"\"\"Synchronously retrieves Tavily research task status and results.\"\"\"\n        if not self._client:\n            raise ValueError(\n                \"Tavily client is not initialized. Ensure 'tavily-python' is \"\n                \"installed and API key is set.\"\n            )\n\n        return self._stringify_response(self._client.get_research(request_id))\n\n    async def _arun(self, request_id: str) -> str:\n        \"\"\"Asynchronously retrieves Tavily research task status and results.\"\"\"\n        if not self._async_client:\n            raise ValueError(\n                \"Tavily async client is not initialized. Ensure 'tavily-python' is \"\n                \"installed and API key is set.\"\n            )\n\n        return self._stringify_response(\n            await self._async_client.get_research(request_id)\n        )\n","sourceCodeStart":97,"sourceCodeEnd":123,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/tavily_get_research_tool/tavily_get_research_tool.py#L97-L123","documentation":"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.","triggerScenarios":"Awaiting tool._arun(request_id) on an instance built while tavily-python was missing or init otherwise skipped client creation.","commonSituations":"Async crews reusing stale tool objects after installing the dependency; environments where TAVILY_API_KEY was absent at build time.","solutions":["Install tavily-python, set TAVILY_API_KEY, and construct a new TavilyGetResearchTool.","Guard async invocations on tool._async_client being truthy."],"exampleFix":"# before\nres = await tool._arun(req_id)  # -> ValueError\n\n# after\nif not tool._async_client:\n    tool = TavilyGetResearchTool()\nres = await tool._arun(req_id)","handlingStrategy":"type-guard","validationCode":"if not getattr(tool, \"_async_client\", None):\n    raise RuntimeError(\"TavilyGetResearchTool async client missing; rebuild the tool\")","typeGuard":"def async_get_research_ready(tool) -> bool:\n    \"\"\"True when the async Tavily research client exists.\"\"\"\n    return getattr(tool, \"_async_client\", None) is not None","tryCatchPattern":"try:\n    out = await tool._arun(request_id)\nexcept ValueError as e:\n    if \"async client is not initialized\" in str(e):\n        tool = TavilyGetResearchTool()\n        out = await tool._arun(request_id)\n    else:\n        raise","preventionTips":["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."],"tags":["tavily","not-initialized","async","lifecycle","crewai-tools"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}