{"record":{"id":"f18230ea984802aa","repo":"crewAIInc/crewAI","slug":"tavily-async-client-is-not-initialized-ensure-ta-f18230","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_research_tool/tavily_research_tool.py","lineNumber":181,"sourceCode":"            ),\n        )\n\n        if use_stream:\n            return cast(Generator[bytes, None, None], result)\n\n        return self._stringify_response(result)\n\n    async def _arun(\n        self,\n        input: str,\n        model: Literal[\"mini\", \"pro\", \"auto\"] | None = None,\n        output_schema: dict[str, Any] | None = None,\n        stream: bool | None = None,\n        citation_format: Literal[\"numbered\", \"mla\", \"apa\", \"chicago\"] | None = None,\n    ) -> str | AsyncGenerator[bytes, None]:\n        \"\"\"Asynchronously creates Tavily research tasks or streams 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        use_stream = self.stream if stream is None else stream\n        result = await self._async_client.research(\n            input=input,\n            model=self.model if model is None else model,\n            output_schema=self.output_schema\n            if output_schema is None\n            else output_schema,\n            stream=use_stream,\n            citation_format=(\n                self.citation_format if citation_format is None else citation_format\n            ),\n        )\n\n        if use_stream:","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/tavily_research_tool/tavily_research_tool.py#L163-L199","documentation":"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.","triggerScenarios":"Awaiting tool._arun(input=...) on an instance constructed without tavily-python (or with client creation skipped).","commonSituations":"Async agent pipelines holding long-lived tool objects across environment fixes; deploying code that constructs tools before env vars/deps are ready.","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."],"exampleFix":"# before\nout = await tool._arun(input=\"...\")  # -> ValueError\n\n# after\nif not tool._async_client:\n    tool = TavilyResearchTool()\nout = await tool._arun(input=\"...\")","handlingStrategy":"type-guard","validationCode":"if not getattr(tool, \"_async_client\", None):\n    raise RuntimeError(\"TavilyResearchTool async client missing; rebuild the tool\")","typeGuard":"def async_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(input=\"...\")\nexcept ValueError as e:\n    if \"async client is not initialized\" in str(e):\n        tool = TavilyResearchTool()\n        out = await tool._arun(input=\"...\")\n    else:\n        raise","preventionTips":["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."],"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"}