From 73af69bd21a73a3b044450cbe5e05472fc11dc70 Mon Sep 17 00:00:00 2001 From: spiceoogway Date: Fri, 30 Jan 2026 08:50:30 -0500 Subject: [PATCH] fix: Auto-discover Ollama models without requiring API key (#4544) Ollama is a local service that doesn't require authentication, but the code was only enabling the Ollama provider if an API key was configured. This caused locally installed Ollama models to show as 'missing' even when they were available. Changes: - Modified resolveImplicitProviders() to auto-discover Ollama models - Add provider if models are found, using 'local' as placeholder API key - Falls back to configured API key if one exists - Updated test to reflect new auto-discovery behavior Fixes #4544 --- src/agents/models-config.providers.ollama.test.ts | 5 +++-- src/agents/models-config.providers.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/agents/models-config.providers.ollama.test.ts b/src/agents/models-config.providers.ollama.test.ts index d9e51c9c5..88466d1cd 100644 --- a/src/agents/models-config.providers.ollama.test.ts +++ b/src/agents/models-config.providers.ollama.test.ts @@ -5,11 +5,12 @@ import { join } from "node:path"; import { tmpdir } from "node:os"; describe("Ollama provider", () => { - it("should not include ollama when no API key is configured", async () => { + it("should not include ollama in test environment (no local discovery)", async () => { const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-")); const providers = await resolveImplicitProviders({ agentDir }); - // Ollama requires explicit configuration via OLLAMA_API_KEY env var or profile + // In test environments, Ollama discovery is skipped and no API key is configured, + // so the provider should not be included expect(providers?.ollama).toBeUndefined(); }); }); diff --git a/src/agents/models-config.providers.ts b/src/agents/models-config.providers.ts index 0cd034c82..ca9d5a8a8 100644 --- a/src/agents/models-config.providers.ts +++ b/src/agents/models-config.providers.ts @@ -446,12 +446,18 @@ export async function resolveImplicitProviders(params: { providers.xiaomi = { ...buildXiaomiProvider(), apiKey: xiaomiKey }; } - // Ollama provider - only add if explicitly configured + // Ollama provider - auto-discover local models, no API key needed const ollamaKey = resolveEnvApiKeyVarName("ollama") ?? resolveApiKeyFromProfiles({ provider: "ollama", store: authStore }); - if (ollamaKey) { - providers.ollama = { ...(await buildOllamaProvider()), apiKey: ollamaKey }; + const ollamaProvider = await buildOllamaProvider(); + // Add provider if models are discovered OR if explicitly configured with API key + if (ollamaProvider.models.length > 0 || ollamaKey) { + providers.ollama = { + ...ollamaProvider, + // Use configured key if available, otherwise use placeholder for local auth + apiKey: ollamaKey ?? "local", + }; } return providers;