Skip to content

Self-improving AI Employees for everyone

feat(gateway): Gemini is the default model for installs on the gateway

trohitg3e81b70cb24d
diff --git a/docs-internal/chat_protocol.md b/docs-internal/chat_protocol.md
index 188c040f..155df628 100644
--- a/docs-internal/chat_protocol.md
+++ b/docs-internal/chat_protocol.md
@@ -626,7 +626,9 @@ the model thinks: Quick (`effort: "low"`), Balanced (no effort sent: the agent's
picker: each node keeps its model.
- **Auto** is the owner's default model (Set Global Model, `UserSettings.default_llm_provider` /
- `default_llm_model`). With none set it changes nothing, and the employee answers on its own model.
+ `default_llm_model`). With none set it is the OpenCompany Gateway's default while the gateway serves it
+ (`gateway_default`, Gemini 3.8 Flash; see `llm_gateway.md`). With neither it changes nothing, and the
+ employee answers on its own model.
- **The choice is the owner's**, saved with their settings (`UserSettings.chat_model`, default `"auto"`, and
`chat_effort`, default `""`) through `save_user_settings`, which refuses a model the picker doesn't offer or an
effort other than `low` / `high` (`chat_choice_refused`). The client sends it as `options.model` /
diff --git a/docs-internal/llm_gateway.md b/docs-internal/llm_gateway.md
index 405890dc..eeb87d80 100644
--- a/docs-internal/llm_gateway.md
+++ b/docs-internal/llm_gateway.md
@@ -17,6 +17,13 @@ OpenCompany's hosted LLM gateway is the stock open-source LiteLLM Proxy, deploye
**Routing: own keys first** (`services/gateway/routing.py`). A call whose provider has a key of the install's own goes to that vendor as always. Otherwise, if the gateway is enabled, its key is stored and the provider has a `"gateway"` block in `server/config/llm_defaults.json`, `ChatUnifier.chat` builds the client with the gateway key and base URL (instead of the `{ref}_proxy` row) and passes the block's `model_prefix` to `OpenAIProvider`, which applies it to the wire model only. The gateway key stays inside the router and ChatUnifier: callers pass no key (`_resolve_activity_api_key` returns `""`), and it never enters node parameters or Temporal payloads. `ChatUnifier.fetch_models` never routes (it validates a key against its own vendor); `AIService.fetch_models` lists a gateway-covered provider's curated models with no network call. The checks that used to refuse "no key configured" accept gateway coverage (`GatewayRouter.covers`, or `gateway_covers` outside the DI graph): the three in `services/ai.py`, `_resolve_activity_api_key` and `prepare_agent_payload`, `Connections.ai_providers` (employee setup and the chat model picker), the global model list, and translate.
+**Default model** (`gateway_default`, the `"gateway"` entry in `server/config/llm_defaults.json`). Where the owner has set no global model, an install that relies on the gateway uses Gemini's `default_model`, Gemini 3.8 Flash:
+- chat Auto (`services/chat/choice.py`);
+- employee setup, before the first usable provider (`services/employees/llm.py`);
+- the global model the editor shows (`get_validated_ai_providers`).
+
+It applies only while the gateway serves Gemini, and the owner's own choice always wins.
+
**Embeddings, speech and vision** call the gateway from their own clients, with the same rule and the provider's same `"gateway"` block: the gateway's key, its URL plus the block's `base_path`, the `model_prefix` on the wire model only, and the attribution headers built per call.
- **The key.** `key_or_route(ctx, credential_id, provider)` gives a plugin node its key: its own through `ctx.connection`, else the gateway's with the route. With neither, the annotated missing-key error still reaches the Credentials modal.
- **Embeddings** (`services/memory/vector_store.py`): `openai_embedding_access` tries the given key, then the stored OpenAI key, then the gateway. It routes only on OpenAI's own endpoint: an `endpoint` override names a server of the user's, which never gets the gateway key. `OpenAIEmbedder` never falls back to `OPENAI_API_KEY` from the environment.
diff --git a/gateway/README.md b/gateway/README.md
index a391b6e4..132806f3 100644
--- a/gateway/README.md
+++ b/gateway/README.md
@@ -28,7 +28,7 @@ The hosted LLM gateway for OpenCompany: invited people use LLMs on platform-owne
| Speech | OpenAI (speech and transcription) |
| Embeddings | OpenAI |
-Gemini runs on Vertex AI express mode with a Google Cloud Agent Platform key (`GOOGLE_AGENT_API_KEY`, a key starting `AQ.`), billed to that key's project. The Gemini Developer API refuses these keys, so `litellm/config.yaml` points the `gemini` provider's `api_base` at `https://aiplatform.googleapis.com/v1/publishers/google`.
+Gemini runs on Vertex AI express mode with a Google Cloud Agent Platform key (`GOOGLE_AGENT_API_KEY`, a key starting `AQ.`), billed to that key's project. The Gemini Developer API refuses these keys, so `litellm/config.yaml` points the `gemini` provider's `api_base` at `https://aiplatform.googleapis.com/v1/publishers/google`. Gemini is also OpenCompany's default model for installs that rely on the gateway (`"gateway"` in `server/config/llm_defaults.json`).
Not served: OpenRouter, DeepSeek and Sarvam (their default models have no price in the list), Groq speech (1.103.4 bills Groq transcription at $0), ElevenLabs and Deepgram (OpenCompany uses their native formats), and every tool API (Brave, Serper, TikHub, Google Maps, Perplexity, DeepL, Apify and the rest). Those stay on each install's own keys.
diff --git a/server/config/llm_defaults.json b/server/config/llm_defaults.json
index d6d911b4..fea150b1 100644
--- a/server/config/llm_defaults.json
+++ b/server/config/llm_defaults.json
@@ -23,6 +23,11 @@
]
},
+ "gateway": {
+ "_description": "The OpenCompany Gateway's default model for an install that relies on it (services/gateway/routing.py gateway_default): default_provider's default_model. It applies where the owner has set no global model (Set Global Model): chat Auto, employee setup and the global model the editor shows, and only while the gateway serves that provider.",
+ "default_provider": "gemini"
+ },
+
"providers": {
"openai": {
"display_name": "OpenAI",
diff --git a/server/services/chat/choice.py b/server/services/chat/choice.py
index 81c511b5..ccfac70f 100644
--- a/server/services/chat/choice.py
+++ b/server/services/chat/choice.py
@@ -9,8 +9,9 @@ edit and retry as ``options.model`` / ``options.effort``. Admission resolves it
here and keeps the result on the run (``ChatRun.options``), and
``prepare_agent_payload`` applies it to the agent that answers the run only.
-- Auto is the owner's default model (Set Global Model). With none set it
- changes nothing: the employee answers on its own model.
+- Auto is the owner's default model (Set Global Model), else the OpenCompany
+ Gateway's default while the gateway serves it (``gateway_default``). With
+ neither it changes nothing: the employee answers on its own model.
- A model whose provider has no key is refused, never swapped for another,
and so is a model the picker no longer offers.
@@ -72,6 +73,13 @@ def _default_of(settings: Mapping[str, Any]) -> Optional[Tuple[str, str]]:
return (provider, model) if provider and model else None
+async def _default(settings: Mapping[str, Any]) -> Optional[Tuple[str, str]]:
+ """Auto's model: the owner's default, else the OpenCompany Gateway's."""
+ from services.gateway.routing import gateway_default
+
+ return _default_of(settings) or await gateway_default()
+
+
def _unavailable(key: str, provider: str, model_name: str) -> str:
return str(choice_setting(key)).format(model=model_name, provider=provider_display_name(provider))
@@ -99,7 +107,7 @@ async def run_options(database: Any, auth: Any, raw: Any, *, principal: Optional
raise ValueError("model must be text")
connected = await _connected(auth, principal)
if model == AUTO:
- default = _default_of(await _settings(database))
+ default = await _default(await _settings(database))
if default is None:
return options
provider, name = default
@@ -183,7 +191,7 @@ async def list_models(
connected = await _connected(auth, principal)
settings = await _settings(database)
auto_words = choice_setting("auto")
- default = _default_of(settings)
+ default = await _default(settings)
if default is not None:
provider, model = default
model_name = _model_name(provider, model)
diff --git a/server/services/employees/llm.py b/server/services/employees/llm.py
index 1e65f9de..a9dd2a5e 100644
--- a/server/services/employees/llm.py
+++ b/server/services/employees/llm.py
@@ -7,7 +7,9 @@
"Keep everything on this computer" on;
2. the global default provider and model from Settings, when that
provider is usable;
-3. the first usable provider, then any saved OpenAI-compatible endpoint.
+3. the OpenCompany Gateway's default (``gateway_default``), when it is
+ usable;
+4. the first usable provider, then any saved OpenAI-compatible endpoint.
A provider is usable when its credential is stored (the same check the
credential catalogue serves). The model is the provider's saved default,
@@ -124,6 +126,12 @@ async def resolve_llm_choice(
if default_provider and (default_provider in usable or default_provider in endpoint_models):
return await choose(default_provider, str(settings.get("default_llm_model") or "") or None)
+ from services.gateway.routing import gateway_default
+
+ gateway = await gateway_default()
+ if gateway is not None and gateway[0] in usable:
+ return await choose(*gateway)
+
if usable:
return await choose(usable[0])
return await choose(endpoints[0].ref)
diff --git a/server/services/gateway/routing.py b/server/services/gateway/routing.py
index 1eb9ed2c..7b47b6d4 100644
--- a/server/services/gateway/routing.py
+++ b/server/services/gateway/routing.py
@@ -24,7 +24,7 @@ from __future__ import annotations
from dataclasses import dataclass
from typing import Any, List, Mapping, Optional, Tuple
-from services.llm.config import split_provider_ref
+from services.llm.config import LLM_DEFAULTS, split_provider_ref
#: Catalogue entry and credential id of the gateway key (Connectors).
GATEWAY_CREDENTIAL_ID = "opencompany_gateway"
@@ -113,6 +113,19 @@ async def gateway_covers(provider: str) -> bool:
return await gateway_route(provider) is not None
+async def gateway_default() -> Optional[Tuple[str, str]]:
+ """The gateway's default ``(provider, model)``: the ``"gateway"`` entry's
+ ``default_provider`` in llm_defaults.json and that provider's
+ ``default_model``. Where the owner has set no global model, an install
+ that relies on the gateway uses it. ``None`` while the gateway doesn't
+ serve that provider."""
+ provider = str((LLM_DEFAULTS.get("gateway") or {}).get("default_provider") or "")
+ model = str(((LLM_DEFAULTS.get("providers") or {}).get(provider) or {}).get("default_model") or "")
+ if not provider or not model or not await gateway_covers(provider):
+ return None
+ return provider, model
+
+
async def key_or_route(ctx: Any, credential_id: str, provider: str) -> Tuple[str, Optional[GatewayRoute]]:
"""A plugin node's key: the install's own for ``credential_id``, else the
gateway's for ``provider``, with its route (``None`` for an own key).
diff --git a/server/services/settings/handlers.py b/server/services/settings/handlers.py
index 8ae1ce62..3a493038 100644
--- a/server/services/settings/handlers.py
+++ b/server/services/settings/handlers.py
@@ -217,6 +217,11 @@ async def handle_get_validated_ai_providers(
settings = await database.get_user_settings(user_id)
global_provider = settings.get("default_llm_provider") if settings else None
global_model = settings.get("default_llm_model") if settings else None
+ if not (global_provider and global_model):
+ # The model that applies: the OpenCompany Gateway's default while it serves it.
+ from services.gateway.routing import gateway_default
+
+ global_provider, global_model = await gateway_default() or (global_provider, global_model)
return {
"providers": providers,
diff --git a/server/tests/gateway/test_routing.py b/server/tests/gateway/test_routing.py
index b2cbee72..1af0a163 100644
--- a/server/tests/gateway/test_routing.py
+++ b/server/tests/gateway/test_routing.py
@@ -109,6 +109,22 @@ async def test_gateway_covers_trusts_only_a_real_router(monkeypatch):
assert await gateway_covers("openai") is False
+async def test_the_gateway_default_is_gemini_while_the_gateway_serves_it(monkeypatch):
+ from services.gateway import routing
+ from services.llm.config import LLM_DEFAULTS
+
+ covered = {"gemini"}
+
+ async def covers(provider):
+ return provider in covered
+
+ monkeypatch.setattr(routing, "gateway_covers", covers)
+ assert LLM_DEFAULTS["gateway"]["default_provider"] == "gemini"
+ assert await routing.gateway_default() == ("gemini", LLM_DEFAULTS["providers"]["gemini"]["default_model"])
+ covered.clear()
+ assert await routing.gateway_default() is None
+
+
ROUTE = GatewayRoute(api_key="sk-gateway", base_url="https://gw.example/v1", model_prefix="openai/")
diff --git a/server/tests/services/chat/test_choice.py b/server/tests/services/chat/test_choice.py
index 1603df88..8bfca673 100644
--- a/server/tests/services/chat/test_choice.py
+++ b/server/tests/services/chat/test_choice.py
@@ -75,6 +75,22 @@ async def test_auto_is_the_owners_default_model(database, connected):
)
+async def test_auto_falls_back_to_the_gateways_default(database, connected, monkeypatch):
+ from services.gateway import routing
+
+ async def gateway_default():
+ return ("gemini", "gemini-3.8-flash")
+
+ monkeypatch.setattr(routing, "gateway_default", gateway_default)
+ connected.add("gemini")
+ assert await options(database, {"model": "auto"}) == {"model": "gemini::gemini-3.8-flash"}
+ picker = await choice.list_models(database, None, principal=None, graph=talk_graph(), name="Ada")
+ assert "Gemini 3.8 Flash" in picker["auto"]["description"] and picker["auto"]["available"] is True
+ # The owner's own default still wins.
+ await database.save_user_settings({"default_llm_provider": "anthropic", "default_llm_model": "claude-opus-5-5"})
+ assert await options(database, {"model": "auto"}) == {"model": OPUS}
+
+
async def test_what_cannot_answer_is_refused(database, connected):
with pytest.raises(choice.ChoiceRefused) as refused:
await options(database, {"model": GPT})
diff --git a/server/tests/services/employees/test_llm_choice.py b/server/tests/services/employees/test_llm_choice.py
index a5e5296d..c795bb88 100644
--- a/server/tests/services/employees/test_llm_choice.py
+++ b/server/tests/services/employees/test_llm_choice.py
@@ -1,6 +1,7 @@
"""Which model writes a setup screen: a local server when the owner keeps
everything on this computer, else the global default when it is usable,
-else the first usable provider, else a saved OpenAI-compatible endpoint."""
+else the OpenCompany Gateway's default when it is usable, else the first
+usable provider, else a saved OpenAI-compatible endpoint."""
from __future__ import annotations
@@ -74,6 +75,20 @@ async def test_a_default_that_is_not_usable_falls_through_to_the_first_usable():
assert choice.provider == "anthropic"
+async def test_the_gateways_default_before_the_first_usable(monkeypatch):
+ from services.gateway import routing
+
+ async def gateway_default():
+ return ("gemini", "gemini-3.8-flash")
+
+ monkeypatch.setattr(routing, "gateway_default", gateway_default)
+ choice = await choose(["openai", "gemini"], settings={"prefer_local_ai": False})
+ assert choice == llm.LLMChoice(provider="gemini", model="gemini-3.8-flash", local=False)
+ # The owner's usable default still wins.
+ choice = await choose(["openai", "gemini"], settings={"prefer_local_ai": False, "default_llm_provider": "openai", "default_llm_model": "gpt-x"})
+ assert choice.provider == "openai"
+
+
async def test_the_saved_provider_default_model_beats_the_json_default():
choice = await choose(["anthropic"], defaults={"anthropic": {"default_model": "claude-x"}})
assert choice.model == "claude-x"