Skip to content

fix: Auto-discover Ollama models without requiring API key#20872

Closed
marcodelpin wants to merge 2 commits intoopenclaw:mainfrom
marcodelpin:fix/ollama-auto-discovery
Closed

fix: Auto-discover Ollama models without requiring API key#20872
marcodelpin wants to merge 2 commits intoopenclaw:mainfrom
marcodelpin:fix/ollama-auto-discovery

Conversation

@marcodelpin
Copy link

@marcodelpin marcodelpin commented Feb 19, 2026

Summary

Fixes #4544
Ref #4782

Ollama is a local service that doesn't require API authentication, but resolveImplicitProviders() only registered the Ollama provider when OLLAMA_API_KEY was explicitly configured. This caused locally installed models to show as "missing" in openclaw models list and fail with "Unknown model" at runtime.

Root Cause

In src/agents/models-config.providers.ts, the Ollama provider registration was gated behind:

const ollamaKey = resolveEnvApiKeyVarName("ollama") ?? resolveApiKeyFromProfiles(...);
if (ollamaKey) { // <-- never true for default Ollama installs
  providers.ollama = ...;
}

Since Ollama runs locally without authentication, most users never set OLLAMA_API_KEY, so discovery never ran.

Changes

  • Auto-discover Ollama models by always calling buildOllamaProvider() — if models are found via /api/tags, the provider is registered with a placeholder "ollama-local" API key
  • Silent auto-discovery: added a quiet option to discoverOllamaModels() to suppress console.warn when the user hasn't explicitly configured Ollama. This prevents noisy warnings for users who don't have Ollama installed (addresses review feedback on fix: Auto-discover Ollama models without requiring explicit API key #4782)
  • Backward compatible: explicit OLLAMA_API_KEY or auth profile configuration still works as before, with warnings preserved when Ollama is unreachable
  • 3 new tests validating auto-discovery, silent failure, and explicit-key warning behavior

Files Changed (2)

  • src/agents/models-config.providers.ts — provider resolution logic + quiet flag (+28/-10)
  • src/agents/models-config.providers.ollama-autodiscovery.test.ts — 3 new tests

Test Plan

  • 3 new auto-discovery tests pass (mock fetch, cover all paths)
  • 10 existing models-config.providers tests pass
  • 28 models list command tests pass
  • Manual: install Ollama, pull model, verify openclaw models list shows it without API key

Greptile Summary

Enables Ollama models to be auto-discovered without requiring OLLAMA_API_KEY, fixing a key usability issue where locally installed Ollama models appeared as "missing". The implementation adds a quiet parameter to suppress warnings when Ollama isn't explicitly configured, preventing noise for users without Ollama while preserving warnings for users who explicitly set up Ollama but can't reach it.

  • Auto-discovery now runs unconditionally, registering the provider with placeholder "ollama-local" API key when models are found
  • Silent mode (quiet: true) when no API key configured prevents unnecessary warnings for users without Ollama
  • Backward compatible: explicit API key configuration preserves original warning behavior
  • Well-tested with 3 new tests covering auto-discovery, silent failure, and explicit-key warning scenarios

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-isolated to Ollama provider discovery logic, backward compatible, and thoroughly tested. The implementation follows existing patterns (similar to vLLM provider), adds proper error handling with the quiet flag, and includes comprehensive test coverage for all code paths. No security concerns or breaking changes identified.
  • No files require special attention

Last reviewed commit: 81c8562


🤖 Generated with Claude Code
Testing: fully tested (automated + manual verification)
I understand and can explain all changes in this PR.

…4544)

Ollama is a local service that doesn't require authentication, but the
provider was only registered when OLLAMA_API_KEY was set. This caused
locally installed models to show as "missing" in openclaw models list.

Changes:
- Always attempt Ollama model discovery via /api/tags
- Register provider with placeholder key "ollama-local" when models found
- Add quiet flag to suppress warnings during implicit auto-discovery,
  so users without Ollama won't see noisy console output
- Preserve existing behavior when API key is explicitly configured

Fixes openclaw#4544
Ref openclaw#4782
@vincentkoc
Copy link
Member

Superseded by #29201, which carries this fix forward with conflict resolution and additional hardening. Credit to @marcodelpin for the core implementation direction in this PR.

@vincentkoc vincentkoc closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cannot change model to Ollama Deepseek-r1:latest

2 participants