Skip to content

[Bug]: Ollama + Gemma 4 requires native think: false to avoid slow or empty responses #188

Description

@phvisty

Home Assistant version

2026.8.3

AI Automation Suggester version

1.5.10

Provider and model

Ollama 0.32.13 / gemma4:12b

What happened?

Issue

This may be specific to the Ollama provider in AI Automation Suggester when using gemma4:12b.

With the integration configured for Ollama, even very small suggestion runs would often take 2–4 minutes and then fail with:

The provider returned no usable suggestion content

The integration uses Ollama's /api/chat endpoint. Its existing Disable Think option appears to add a /no_think system message, but the request body does not send Ollama's native think parameter.

Testing

I compared the same simple prompt directly against Ollama /api/chat with and without native thinking enabled.

With default thinking:

  • 2,372 generated tokens
  • ~65.2 seconds generation time
  • Large message.thinking output

With:

"think": false

the same request produced:

  • 424 generated tokens
  • ~11.2 seconds generation time
  • No large thinking output
  • Valid response content

This suggested that Gemma 4's native thinking mode was consuming substantial generation time and output budget.

Local fix

The relevant Home Assistant file is:
/config/custom_components/ai_automation_suggester/coordinator.py

Repository path:
custom_components/ai_automation_suggester/coordinator.py

Inside the integration's _ollama() function, the request body originally contained:

body = {
    "model": self._current_model("Ollama"),
    "messages": messages,
    "stream": False,
    "options": {
        "temperature": float(self._opt(CONF_OLLAMA_TEMPERATURE, DEFAULT_TEMPERATURE)),
        "num_predict": out_budget,
    },
}

I changed it locally to:

body = {
    "model": self._current_model("Ollama"),
    "messages": messages,
    "stream": False,
    "think": False,
    "options": {
        "temperature": float(self._opt(CONF_OLLAMA_TEMPERATURE, DEFAULT_TEMPERATURE)),
        "num_predict": out_budget,
    },
}

After restarting Home Assistant, the previous The provider returned no usable suggestion content failures stopped occurring.

Observed results after the change:

  • 5 entities: succeeded in under 30 seconds
  • 50 entities: succeeded in ~53–58 seconds
  • 100 entities: succeeded in ~62–80 seconds

A possible upstream implementation would be to have the existing Disable Think option send Ollama's native parameter:

if self._opt(CONF_OLLAMA_DISABLE_THINK, False):
body["think"] = False

This would preserve the current user-facing option while using Ollama's native thinking control for models such as Gemma 4.

Relevant logs

No full traceback was captured. Failures occurred after approximately 133–245 seconds before applying the Ollama think:false patch.

Service call data

action: ai_automation_suggester.generate_suggestions
data:
  all_entities: true
  domains: []
  exclude_domains: []
  exclude_entities: []
  exclude_areas: []
  entity_limit: 5
  automation_read_yaml: false
  automation_limit: 100
  script_read_yaml: false
  script_limit: 100

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions