Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
feat(model): Ollama + LM Studio chat-model plugins
trohitg0fd661f4d799
diff --git a/client/src/assets/icons/index.ts b/client/src/assets/icons/index.tsindex a5e17510..f4460a76 100644--- a/client/src/assets/icons/index.ts+++ b/client/src/assets/icons/index.ts@@ -44,6 +44,8 @@ import OpenRouter from '@lobehub/icons/es/OpenRouter';import DeepSeek from '@lobehub/icons/es/DeepSeek';import Kimi from '@lobehub/icons/es/Kimi';import Mistral from '@lobehub/icons/es/Mistral';+import Ollama from '@lobehub/icons/es/Ollama';+import LmStudio from '@lobehub/icons/es/LmStudio';type RawSvg = string;@@ -135,6 +137,8 @@ const LOBEHUB_BRANDS: Readonly<Record<string, any>> = {deepseek: DeepSeek,kimi: Kimi,mistral: Mistral,+ ollama: Ollama,+ lmstudio: LmStudio,};const ICON_LIBRARIES: Readonly<Record<string, LibraryResolver>> = {diff --git a/client/src/components/credentials/panels/ApiKeyPanel.tsx b/client/src/components/credentials/panels/ApiKeyPanel.tsxindex 3377d5bf..da962a78 100644--- a/client/src/components/credentials/panels/ApiKeyPanel.tsx+++ b/client/src/components/credentials/panels/ApiKeyPanel.tsx@@ -77,23 +77,30 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ csetValidated(false);}}onSave={() =>- panel.actions- .validate(config.id, inputValue.trim())- .then((r) => {- if (r?.isValid) setValidated(true);- })+ // Cloud providers store under config.id and validate via+ // the upstream API. Local servers (Ollama, LM Studio)+ // declare a non-`apiKey` field key (e.g. `ollama_proxy`)+ // because nothing remote needs validating — just persist+ // the base URL where the existing proxy_url lookup in+ // execute_chat will find it.+ (field.key === 'apiKey'+ ? panel.actions.validate(config.id, inputValue.trim())+ : panel.actions.save(field.key, inputValue.trim())+ ).then((r) => {+ if (r?.isValid) setValidated(true);+ })}onDelete={validated? () => {- panel.actions.remove(config.id);+ panel.actions.remove(field.key === 'apiKey' ? config.id : field.key);setInputValue('');setValidated(false);}: undefined}placeholder={field.placeholder}- loading={panel.loading === 'validate'}+ loading={panel.loading === 'validate' || panel.loading === 'save'}isStored={validated}/>)}diff --git a/client/src/components/credentials/providers.tsx b/client/src/components/credentials/providers.tsxindex bbafa523..8f34244b 100644--- a/client/src/components/credentials/providers.tsx+++ b/client/src/components/credentials/providers.tsx@@ -21,13 +21,31 @@ const AI_PLACEHOLDERS: Record<string, string> = {openai: 'sk-...', anthropic: 'sk-ant-...', gemini: 'AIza...',groq: 'gsk_...', cerebras: 'csk-...', openrouter: 'sk-or-...',deepseek: 'sk-...', kimi: 'sk-...', mistral: 'sk-...',+ // Local LLM servers — the field stores the base URL, not an API key.+ // Backend reads it from the `{provider}_proxy` credential, the same+ // path cloud providers already use for Ollama-style auth delegation.+ ollama: 'http://localhost:11434/v1',+ lmstudio: 'http://localhost:1234/v1',};-const aiProviders: ProviderConfig[] = Object.entries(AI_PROVIDER_META).map(([id, meta]) => ({- id, name: meta.label, category: 'ai', categoryLabel: 'AI Providers',- color: meta.color, kind: 'apiKey' as const, iconRef: meta.iconRef, hasDefaults: true,- fields: [{ key: 'apiKey', label: 'API Key', secret: true, placeholder: AI_PLACEHOLDERS[id], required: true }],-}));+// Local LLM servers reuse the existing `{provider}_proxy` credential+// for their base URL — no new field plumbing. The single-field+// ApiKeyPanel renders this as "Base URL" via the override below; the+// backend's _LocalLLM.resolve() returns a placeholder api_key so the+// "API key required" check in execute_chat passes.+const LOCAL_PROVIDER_IDS = new Set(['ollama', 'lmstudio']);++const aiProviders: ProviderConfig[] = Object.entries(AI_PROVIDER_META).map(([id, meta]) => {+ const isLocal = LOCAL_PROVIDER_IDS.has(id);+ const fields = isLocal+ ? [{ key: `${id}_proxy`, label: 'Base URL', placeholder: AI_PLACEHOLDERS[id], required: true }]+ : [{ key: 'apiKey', label: 'API Key', secret: true, placeholder: AI_PLACEHOLDERS[id], required: true }];+ return {+ id, name: meta.label, category: 'ai', categoryLabel: 'AI Providers',+ color: meta.color, kind: 'apiKey' as const, iconRef: meta.iconRef, hasDefaults: true,+ fields,+ };+});// ============================================================================// ALL PROVIDERS — flat array. Categories derived below.diff --git a/client/src/components/icons/AIProviderIcons.tsx b/client/src/components/icons/AIProviderIcons.tsxindex 3fc83144..aa454216 100644--- a/client/src/components/icons/AIProviderIcons.tsx+++ b/client/src/components/icons/AIProviderIcons.tsx@@ -12,6 +12,8 @@ import Cerebras from '@lobehub/icons/es/Cerebras';import DeepSeek from '@lobehub/icons/es/DeepSeek';import Kimi from '@lobehub/icons/es/Kimi';import Mistral from '@lobehub/icons/es/Mistral';+import Ollama from '@lobehub/icons/es/Ollama';+import LmStudio from '@lobehub/icons/es/LmStudio';import { dracula, solarized } from '../../styles/theme';// Icon size constant for consistency@@ -58,6 +60,16 @@ export const MistralIcon: React.FC<{ size?: number }> = ({ size = ICON_SIZE }) =<Mistral.Color size={size} />);+// Local LLM servers — Ollama exposes a Color variant; LmStudio's lobehub+// entry only ships an Avatar so we use that for parity.+export const OllamaIcon: React.FC<{ size?: number }> = ({ size = ICON_SIZE }) => (+ <Ollama.Avatar size={size} />+);++export const LmStudioIcon: React.FC<{ size?: number }> = ({ size = ICON_SIZE }) => (+ <LmStudio.Avatar size={size} />+);+// Map provider IDs to their icon componentsexport const AI_PROVIDER_ICONS: Record<string, React.FC<{ size?: number }>> = {openai: OpenAIIcon,@@ -69,6 +81,8 @@ export const AI_PROVIDER_ICONS: Record<string, React.FC<{ size?: number }>> = {deepseek: DeepSeekIcon,kimi: KimiIcon,mistral: MistralIcon,+ ollama: OllamaIcon,+ lmstudio: LmStudioIcon,};// Centralized provider metadata (icon ref, theme color, display label).@@ -86,6 +100,8 @@ export const AI_PROVIDER_META: Record<string, { iconRef: string; Icon: React.FC<deepseek: { iconRef: 'lobehub:DeepSeek', Icon: DeepSeekIcon, color: dracula.cyan, label: 'DeepSeek' },kimi: { iconRef: 'lobehub:Kimi', Icon: KimiIcon, color: dracula.purple, label: 'Kimi' },mistral: { iconRef: 'lobehub:Mistral', Icon: MistralIcon, color: dracula.pink, label: 'Mistral' },+ ollama: { iconRef: 'lobehub:Ollama', Icon: OllamaIcon, color: dracula.foreground, label: 'Ollama' },+ lmstudio: { iconRef: 'lobehub:LmStudio', Icon: LmStudioIcon, color: solarized.cyan, label: 'LM Studio' },};// Get icon component by provider IDdiff --git a/server/config/credential_providers.json b/server/config/credential_providers.jsonindex 172a4379..118ea1f5 100644--- a/server/config/credential_providers.json+++ b/server/config/credential_providers.json@@ -115,6 +115,48 @@]},+ "ollama": {+ "_description": "Local Ollama server. The single field stores a base URL; the backend's _LocalLLM credential class returns a placeholder api_key, and execute_chat reads `{provider}_proxy` to override base_url via the existing OpenAI-style auth-delegation path. No `extends` — the field shape diverges from the cloud `_ai_base` template.",+ "name": "Ollama",+ "category": "ai",+ "category_label": "AI Providers",+ "color": "dracula.foreground",+ "kind": "apiKey",+ "icon_ref": "lobehub:ollama",+ "has_defaults": true,+ "fields": [+ {+ "key": "ollama_proxy",+ "label": "Base URL",+ "type": "string",+ "placeholder": "http://localhost:11434/v1",+ "required": true+ }+ ],+ "instructions": "Run `ollama serve` locally (or point Base URL at any reachable Ollama server). API key is not needed — the credential resolver supplies the documented `ollama` placeholder."+ },++ "lmstudio": {+ "_description": "Local LM Studio server (OpenAI-compatible /v1). Same shape as ollama: single base-URL field stored as `lmstudio_proxy`.",+ "name": "LM Studio",+ "category": "ai",+ "category_label": "AI Providers",+ "color": "solarized.cyan",+ "kind": "apiKey",+ "icon_ref": "lobehub:lmstudio",+ "has_defaults": true,+ "fields": [+ {+ "key": "lmstudio_proxy",+ "label": "Base URL",+ "type": "string",+ "placeholder": "http://localhost:1234/v1",+ "required": true+ }+ ],+ "instructions": "Start the LM Studio local server from the Developer tab. API key is not required."+ },+"whatsapp_personal": {"name": "WhatsApp Personal","category": "social",diff --git a/server/config/llm_defaults.json b/server/config/llm_defaults.jsonindex 70ac4eab..7730e0a3 100644--- a/server/config/llm_defaults.json+++ b/server/config/llm_defaults.json@@ -250,6 +250,32 @@"_default": 131072},"temperature_range": [0.0, 1.5]+ },++ "ollama": {+ "_description": "Local Ollama server (OpenAI-compatible /v1). The shape mirrors deepseek/kimi/mistral: base_url + models_endpoint, no auth field. The user's custom server address lives in the {provider}_proxy credential (existing Ollama-style auth-delegation path) which OpenAIProvider treats as the API base.",+ "default_model": "llama3.2:3b",+ "detection_patterns": ["ollama"],+ "base_url": "http://localhost:11434/v1",+ "models_endpoint": "http://localhost:11434/v1/models",+ "api_key_param": "api_key",+ "max_tokens_param": "max_tokens",+ "max_output_tokens": {"_default": 4096},+ "context_length": {"_default": 32768},+ "temperature_range": [0.0, 2.0]+ },++ "lmstudio": {+ "_description": "Local LM Studio server (pure OpenAI-compatible). Same OpenAIProvider+base_url path as deepseek/kimi/mistral; user's custom URL rides via {provider}_proxy.",+ "default_model": "local-model",+ "detection_patterns": ["lmstudio", "lm_studio", "lm-studio"],+ "base_url": "http://localhost:1234/v1",+ "models_endpoint": "http://localhost:1234/v1/models",+ "api_key_param": "api_key",+ "max_tokens_param": "max_tokens",+ "max_output_tokens": {"_default": 4096},+ "context_length": {"_default": 32768},+ "temperature_range": [0.0, 2.0]}}}diff --git a/server/config/pricing.json b/server/config/pricing.jsonindex 2f6c9b2c..47ede630 100644--- a/server/config/pricing.json+++ b/server/config/pricing.json@@ -62,6 +62,14 @@"codestral-latest": {"input": 0.30, "output": 0.90},"open-mistral-nemo": {"input": 0.15, "output": 0.15},"_default": {"input": 0.20, "output": 0.60}+ },+ "ollama": {+ "_description": "Local inference is free at the API layer — user-borne hardware costs are not tracked here.",+ "_default": {"input": 0.00, "output": 0.00}+ },+ "lmstudio": {+ "_description": "Local inference — same zero-cost convention as ollama.",+ "_default": {"input": 0.00, "output": 0.00}}},diff --git a/server/constants.py b/server/constants.pyindex 55a1b41b..8b7dde79 100644--- a/server/constants.py+++ b/server/constants.py@@ -20,6 +20,10 @@ AI_CHAT_MODEL_TYPES: FrozenSet[str] = frozenset(['deepseekChatModel','kimiChatModel','mistralChatModel',+ # Local-server providers (Phase 1 of the LiteLLM adoption — see+ # plans/i-plan-to-implement-nested-orbit.md).+ 'ollamaChatModel',+ 'lmstudioChatModel',])AI_AGENT_TYPES: FrozenSet[str] = frozenset([diff --git a/server/nodes/model/_credentials.py b/server/nodes/model/_credentials.pyindex c15ae1b3..8bc7bc51 100644--- a/server/nodes/model/_credentials.py+++ b/server/nodes/model/_credentials.py@@ -1,16 +1,26 @@"""LLM provider credentials (Wave 11.E.1 — per-domain).-One :class:`ApiKeyCredential` per provider. Used by the 9 chat-model+One :class:`ApiKeyCredential` per provider. Used by the chat-modelplugins in this folder (openai, anthropic, gemini, openrouter, groq,-cerebras, deepseek, kimi, mistral) plus the xAI credential referenced-by agent plugins. At execution time the plugin's LangChain / native-SDK client pulls the key directly from :mod:`services.auth`; this-class is the Credentials-modal + discovery manifest, not the runtime-client.+cerebras, deepseek, kimi, mistral, ollama, lmstudio) plus the xAI+credential referenced by agent plugins. At execution time the plugin's+LangChain / native SDK client pulls the key directly from+:mod:`services.auth`; this class is the Credentials-modal + discovery+manifest, not the runtime client.++Local servers (Ollama, LM Studio) follow the same shape as the cloud+credentials but their api_key is optional — many users run them on+localhost with no auth. The existing ``{provider}_proxy`` mechanism+in :func:`services.ai.AIService.create_model` already handles the+"override base_url + use placeholder api_key" path; the credential+class only needs to return a placeholder when nothing is stored so+the central "API key is required" check in ``execute_chat`` passes."""from __future__ import annotations+from typing import Any, Dict+from services.plugin.credential import ApiKeyCredential@@ -95,3 +105,36 @@ class XaiCredential(_LLMApiKey):display_name = "xAI (Grok)"icon = "asset:xai"docs_url = "https://console.x.ai"+++class _LocalLLM(_LLMApiKey):+ """Base for local-server credentials (Ollama, LM Studio).++ Same shape as :class:`_LLMApiKey`, but ``resolve()`` returns the+ documented Ollama placeholder when no key is stored instead of+ raising. The user's custom server address rides on the existing+ ``{id}_proxy`` credential — :func:`services.ai.AIService.create_model`+ already reads it and OpenAIProvider already overrides ``base_url``+ + forces ``api_key="ollama"``. Nothing else to wire.+ """++ @classmethod+ async def resolve(cls, *, user_id: str = "owner") -> Dict[str, Any]:+ from core.container import container++ api_key = await container.auth_service().get_api_key(cls.id)+ return {"api_key": api_key or "ollama"}+++class OllamaCredential(_LocalLLM):+ id = "ollama"+ display_name = "Ollama"+ icon = "lobehub:ollama"+ docs_url = "https://ollama.com/download"+++class LMStudioCredential(_LocalLLM):+ id = "lmstudio"+ display_name = "LM Studio"+ icon = "lobehub:lmstudio"+ docs_url = "https://lmstudio.ai/docs/local-server"diff --git a/server/nodes/model/lmstudio_chat_model.py b/server/nodes/model/lmstudio_chat_model.pynew file mode 100644index 00000000..3a38144c--- /dev/null+++ b/server/nodes/model/lmstudio_chat_model.py@@ -0,0 +1,23 @@+"""LM Studio chat-model plugin.++Auto-registers via BaseNode.__init_subclass__. LM Studio exposes a pure+OpenAI-compatible endpoint at ``http://localhost:1234/v1`` by default,+so the existing OpenAI-compatible fallback in+``services/llm/factory.py`` routes it through ``OpenAIProvider`` with+``base_url`` from ``llm_defaults.json`` — same path as deepseek/kimi/+mistral. The user's custom server URL is stored as the+``lmstudio_proxy`` credential.+"""++from ._base import ChatModelBase++from ._credentials import LMStudioCredential+++class LMStudioChatModelNode(ChatModelBase):+ type = "lmstudioChatModel"+ display_name = "LM Studio"+ subtitle = "Chat Model"+ group = ("model",)+ description = "Run local LLMs via LM Studio's OpenAI-compatible server"+ credentials = (LMStudioCredential,)diff --git a/server/nodes/model/ollama_chat_model.py b/server/nodes/model/ollama_chat_model.pynew file mode 100644index 00000000..7ec9f5b1--- /dev/null+++ b/server/nodes/model/ollama_chat_model.py@@ -0,0 +1,25 @@+"""Ollama chat-model plugin.++Auto-registers via BaseNode.__init_subclass__. Same shape as+``mistral_chat_model.py`` — a single ``ChatModelBase`` subclass plus a+credential class. Routing happens through the existing OpenAI-compatible+fallback in ``services/llm/factory.py``: Ollama serves an OpenAI-shaped+``/v1`` endpoint, so the factory hands it to ``OpenAIProvider`` with+``base_url`` from ``llm_defaults.json``. The user's custom server URL+(if not localhost) is stored as the ``ollama_proxy`` credential and+flows through the same ``proxy_url`` parameter cloud providers already+use for Ollama-style auth delegation.+"""++from ._base import ChatModelBase++from ._credentials import OllamaCredential+++class OllamaChatModelNode(ChatModelBase):+ type = "ollamaChatModel"+ display_name = "Ollama"+ subtitle = "Chat Model"+ group = ("model",)+ description = "Run local LLMs via Ollama (llama, mistral, qwen, deepseek-r1, ...)"+ credentials = (OllamaCredential,)diff --git a/server/nodes/visuals.json b/server/nodes/visuals.jsonindex 2efb039c..8712c8fa 100644--- a/server/nodes/visuals.json+++ b/server/nodes/visuals.json@@ -251,6 +251,10 @@"icon": "lobehub:kimi","color": "#bd93f9"},+ "lmstudioChatModel": {+ "icon": "lobehub:lmstudio",+ "color": "#4F8EFF"+ },"location": {"icon": "📍","skill": "location-skill"@@ -273,6 +277,10 @@"networkMonitor": {"icon": "📡"},+ "ollamaChatModel": {+ "icon": "lobehub:ollama",+ "color": "#000000"+ },"openaiChatModel": {"icon": "lobehub:openai","color": "#00A67E"diff --git a/server/pyproject.toml b/server/pyproject.tomlindex 2509b7f4..2ba918a3 100644--- a/server/pyproject.toml+++ b/server/pyproject.toml@@ -58,6 +58,7 @@ dependencies = ["langchain-cerebras==0.8.2","langgraph==1.1.6","deepagents==0.5.2",+# Pydantic 2.13 changed validator ordering; pin to main's 2.12 line# to keep AIMessage construction/tool-schema generation identical."pydantic==2.12.5",diff --git a/server/services/llm/factory.py b/server/services/llm/factory.pyindex cbf2d15c..a649ac73 100644--- a/server/services/llm/factory.py+++ b/server/services/llm/factory.py@@ -12,8 +12,14 @@ logger = get_logger(__name__)# Providers with dedicated SDK implementations_DEDICATED_PROVIDERS = frozenset({"anthropic", "openai", "gemini", "openrouter"})-# All providers supported by native SDK path (dedicated + OpenAI-compatible via base_url)-NATIVE_PROVIDERS = _DEDICATED_PROVIDERS | frozenset({"xai", "deepseek", "kimi", "mistral"})+# All providers supported by native SDK path (dedicated + OpenAI-compatible via base_url).+# Local servers (ollama, lmstudio) expose OpenAI-compatible /v1 endpoints, so they fall+# through to OpenAIProvider with base_url from llm_defaults.json — same path as deepseek/+# kimi/mistral. The user's custom URL rides via the existing {provider}_proxy credential.+NATIVE_PROVIDERS = _DEDICATED_PROVIDERS | frozenset({+ "xai", "deepseek", "kimi", "mistral",+ "ollama", "lmstudio",+})def create_provider(