crewAIInc/crewAI · error · ValueError

Invalid response from AI-Mind

Error message

Invalid response from AI-Mind

What it means

After AIMindTool._run() calls the OpenAI-compatible Minds chat-completions endpoint, it asserts the returned object is an openai ChatCompletion instance. If the Minds service returns a shape the OpenAI client cannot parse into ChatCompletion (or a non-standard payload), this ValueError fires. It guards completion.choices[0].message.content from failing with a confusing AttributeError.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/ai_mind_tool/ai_mind_tool.py:99

        self.mind_name = mind.name

    def _run(self, query: str) -> str | None:
        # The Minds API is OpenAI compatible and therefore, the OpenAI client can be used.
        openai_client = OpenAI(
            base_url=AIMindToolConstants.MINDS_API_BASE_URL, api_key=self.api_key
        )

        if self.mind_name is None:
            raise ValueError("Mind name is not set.")

        completion = openai_client.chat.completions.create(
            model=self.mind_name,
            messages=[{"role": "user", "content": query}],
            stream=False,
        )
        if not isinstance(completion, ChatCompletion):
            raise ValueError("Invalid response from AI-Mind")

        return completion.choices[0].message.content

View on GitHub (pinned to 754d7323be)

Solutions

  1. Retry the query once — transient malformed responses from the API do occur.
  2. Check the Minds service status/dashboard for the mind and its model; recreate the mind if it is broken.
  3. Pin/align the openai package version with one known to work against the Minds API (check the tool's dependency pins).
  4. If it persists, capture the raw response (custom httpx transport or openai debug logging) and report it to Minds support.

Example fix

# before
content = tool._run(query)  # raises 'Invalid response from AI-Mind'

# after
try:
    content = tool._run(query)
except ValueError as e:
    if "Invalid response" in str(e):
        content = tool._run(query)  # single retry for transient bad payload
    else:
        raise
Defensive patterns

Strategy: retry

Try / catch

for attempt in range(2):
    try:
        return tool._run(query)
    except ValueError as e:
        if "Invalid response" in str(e) and attempt == 0:
            continue  # transient malformed payload
        raise

Prevention

When it happens

Trigger: Minds API returning an error body, unexpected event object, or changed schema that the OpenAI client parses into a different type; version drift between the installed openai client and the Minds endpoint's OpenAI compatibility layer.

Common situations: Minds backend outage or schema change; openai package upgraded to a version whose with_raw_response / stream=False return types differ; misconfigured base_url pointing at a non-OpenAI-compatible service.

Related errors


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