{"record":{"id":"f61ae31617922fe8","repo":"crewAIInc/crewAI","slug":"mind-name-is-not-set","errorCode":null,"errorMessage":"Mind name is not set.","messagePattern":"Mind name is not set\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/ai_mind_tool/ai_mind_tool.py","lineNumber":91,"sourceCode":"            )\n            datasources.append(config)\n\n        name = f\"{AIMindToolConstants.MIND_NAME_PREFIX}_{secrets.token_hex(5)}\"\n\n        mind = minds_client.minds.create(\n            name=name, datasources=datasources, replace=True\n        )\n\n        self.mind_name = mind.name\n\n    def _run(self, query: str) -> str | None:\n        # The Minds API is OpenAI compatible and therefore, the OpenAI client can be used.\n        openai_client = OpenAI(\n            base_url=AIMindToolConstants.MINDS_API_BASE_URL, api_key=self.api_key\n        )\n\n        if self.mind_name is None:\n            raise ValueError(\"Mind name is not set.\")\n\n        completion = openai_client.chat.completions.create(\n            model=self.mind_name,\n            messages=[{\"role\": \"user\", \"content\": query}],\n            stream=False,\n        )\n        if not isinstance(completion, ChatCompletion):\n            raise ValueError(\"Invalid response from AI-Mind\")\n\n        return completion.choices[0].message.content\n","sourceCodeStart":73,"sourceCodeEnd":102,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/ai_mind_tool/ai_mind_tool.py#L73-L102","documentation":"AIMindTool._run() sends the query to the Minds API using self.mind_name as the model name. The constructor normally sets self.mind_name from the created mind (mind.name), so hitting this ValueError means the attribute is None at run time — typically because construction was bypassed, the attribute was overwritten, or object state was mutated/restored (e.g. pickling) without it.","triggerScenarios":"Calling tool._run(query) on an instance whose __init__ did not complete the mind-creation step (e.g. an exception swallowed after client creation); serializing/deserializing the tool without the attribute; manually setting tool.mind_name = None; subclass overrides skipping super().__init__.","commonSituations":"Deep-copying or caching tool instances; crew flows that rebuild tools from config and skip the constructor; tests constructing the object via __new__ or mocks.","solutions":["Ensure the tool is created normally via AIMindTool(api_key=..., datasources=...) so __init__ completes mind creation and sets mind_name.","If state was mutated, re-set it: tool.mind_name = <name from Minds dashboard> before running.","Avoid serializing the tool instance; recreate it per run instead.","Check for swallowed exceptions during construction that leave the object half-initialized."],"exampleFix":"# before\nopenai_client = OpenAI(...)\nresult = tool._run(query)  # mind_name is None\n\n# after\nassert tool.mind_name, \"AIMindTool not fully initialized; recreate the tool\"\nresult = tool._run(query)","handlingStrategy":"type-guard","validationCode":"def aimind_ready(tool) -> bool:\n    return getattr(tool, \"mind_name\", None) is not None","typeGuard":"def is_initialized_aimind(tool: object) -> bool:\n    return bool(getattr(tool, \"mind_name\", None)) and bool(getattr(tool, \"api_key\", None))","tryCatchPattern":"try:\n    result = tool._run(query)\nexcept ValueError as e:\n    if \"Mind name is not set\" in str(e):\n        tool = AIMindTool(api_key=..., datasources=[...])  # re-create properly\n        result = tool._run(query)\n    else:\n        raise","preventionTips":["Always construct AIMindTool through its __init__ so mind creation completes.","Don't deep-copy, pickle, or cache tool instances; rebuild them per session.","Add a preflight assert on tool.mind_name before first use."],"tags":["state","api-misuse","initialization","agent-tool"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}