Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(agent): preserve legacy backend precedence

cyhb3e89a771345
diff --git a/core/controller.py b/core/controller.py
index 3c7e2e2b5..ced15840c 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -69,7 +69,10 @@ class Controller:
# Validate default_backend against registered agents
self._validate_default_backend()
self.vibe_agent_store = VibeAgentStore()
- self.vibe_agent_store.ensure_builtin_default_agents(self._enabled_agent_backends())
+ self.vibe_agent_store.ensure_builtin_default_agents(
+ self._enabled_agent_backends(),
+ default_backend=getattr(self.agent_router, "global_default", DEFAULT_AGENT_BACKEND),
+ )
# Setup callbacks
self._setup_callbacks()
diff --git a/core/vibe_agents.py b/core/vibe_agents.py
index da215c9a4..4c11168ae 100644
--- a/core/vibe_agents.py
+++ b/core/vibe_agents.py
@@ -299,7 +299,12 @@ class VibeAgentStore:
metadata=metadata,
)
- def ensure_builtin_default_agents(self, backends: Iterable[str]) -> list[VibeAgent]:
+ def ensure_builtin_default_agents(
+ self,
+ backends: Iterable[str],
+ *,
+ default_backend: Optional[str] = None,
+ ) -> list[VibeAgent]:
ensured: list[VibeAgent] = []
for backend in backends:
try:
@@ -308,7 +313,11 @@ class VibeAgentStore:
logger.warning("Skipping built-in default Agent for backend %s: %s", backend, exc)
default_agent = self.get_default_agent()
if default_agent is None and ensured:
- self.set_default_agent_name(ensured[0].name)
+ preferred = None
+ if default_backend:
+ preferred_backend = validate_agent_backend(default_backend)
+ preferred = next((agent for agent in ensured if agent.backend == preferred_backend), None)
+ self.set_default_agent_name((preferred or ensured[0]).name)
return ensured
def get_builtin_default_agent_for_backend(self, backend: str) -> Optional[VibeAgent]:
diff --git a/tests/test_ui_api.py b/tests/test_ui_api.py
index 89e8496d7..2885df50d 100644
--- a/tests/test_ui_api.py
+++ b/tests/test_ui_api.py
@@ -1206,6 +1206,16 @@ def test_vibe_agent_catalog_ensures_builtin_defaults_for_enabled_backends(tmp_pa
assert api.remove_vibe_agent("opencode")["code"] == "agent_builtin"
+def test_builtin_default_agents_respect_configured_default_backend(tmp_path, monkeypatch):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path / ".vibe_remote"))
+ store = VibeAgentStore()
+ try:
+ store.ensure_builtin_default_agents(["opencode", "claude", "codex"], default_backend="codex")
+ assert store.get_default_agent_name() == "codex"
+ finally:
+ store.close()
+
+
def test_builtin_default_agent_does_not_reuse_conflicting_user_agent(tmp_path, monkeypatch):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path / ".vibe_remote"))
store = VibeAgentStore()
diff --git a/ui/src/components/shared/RoutingConfigPanel.tsx b/ui/src/components/shared/RoutingConfigPanel.tsx
index 5ef43d496..e6acdb750 100644
--- a/ui/src/components/shared/RoutingConfigPanel.tsx
+++ b/ui/src/components/shared/RoutingConfigPanel.tsx
@@ -99,8 +99,9 @@ export const RoutingConfigPanel: React.FC<RoutingConfigPanelProps> = ({
const selectedVibeAgent = vibeAgents.find((agent) => agent.name === value.routing.agent_name) || null;
const defaultVibeAgent = vibeAgents.find((agent) => agent.name === defaultAgentName) || null;
- const inheritedVibeAgent = selectedVibeAgent || defaultVibeAgent;
- const effectiveBackend = inheritedVibeAgent?.backend || value.routing.agent_backend || globalConfig?.agents?.default_backend || 'opencode';
+ const legacyBackend = value.routing.agent_backend || null;
+ const inheritedVibeAgent = selectedVibeAgent || (!legacyBackend ? defaultVibeAgent : null);
+ const effectiveBackend = selectedVibeAgent?.backend || legacyBackend || defaultVibeAgent?.backend || globalConfig?.agents?.default_backend || 'opencode';
const effectiveModel = value.routing.model || inheritedVibeAgent?.model || '';
const getOpenCodeReasoningOptions = (modelKey: string) => {
diff --git a/ui/src/components/steps/ChannelList.tsx b/ui/src/components/steps/ChannelList.tsx
index a83644bbe..423ef1707 100644
--- a/ui/src/components/steps/ChannelList.tsx
+++ b/ui/src/components/steps/ChannelList.tsx
@@ -1287,8 +1287,9 @@ export const ChannelList: React.FC<ChannelListProps> = ({ data = {}, onNext, onB
};
const rowKey = `${channelPlatform}::${channel.id}`;
const expanded = expandedChannelId === rowKey;
- const selectedAgent = agentByName[channelConfig.routing.agent_name || ''] || agentByName[defaultAgentName || ''];
- const effectiveBackend = selectedAgent?.backend || channelConfig.routing.agent_backend || defaultBackend;
+ const legacyBackend = channelConfig.routing.agent_backend || null;
+ const selectedAgent = agentByName[channelConfig.routing.agent_name || ''] || (!legacyBackend ? agentByName[defaultAgentName || ''] : undefined);
+ const effectiveBackend = selectedAgent?.backend || legacyBackend || defaultBackend;
const effectiveCwd = channelConfig.custom_cwd || config.runtime?.default_cwd || '~/work';
const opencodeOptions = opencodeOptionsByCwd[effectiveCwd];
const claudeAgents = claudeAgentsByCwd[effectiveCwd] || [];
diff --git a/ui/src/components/steps/UserList.tsx b/ui/src/components/steps/UserList.tsx
index ed5d09010..9dd496c1a 100644
--- a/ui/src/components/steps/UserList.tsx
+++ b/ui/src/components/steps/UserList.tsx
@@ -739,8 +739,9 @@ export const UserList: React.FC = () => {
const expanded = expandedKey === u.key;
const userConfig = u.config;
const defaultBackend = config.agents?.default_backend || 'opencode';
- const selectedAgent = agentByName[userConfig.routing?.agent_name || ''] || agentByName[defaultAgentName || ''];
- const effectiveBackend = selectedAgent?.backend || userConfig.routing?.agent_backend || defaultBackend;
+ const legacyBackend = userConfig.routing?.agent_backend || null;
+ const selectedAgent = agentByName[userConfig.routing?.agent_name || ''] || (!legacyBackend ? agentByName[defaultAgentName || ''] : undefined);
+ const effectiveBackend = selectedAgent?.backend || legacyBackend || defaultBackend;
const effectiveCwd = userConfig.custom_cwd || config.runtime?.default_cwd || '~/work';
const opencodeOptions = opencodeOptionsByCwd[effectiveCwd];
const claudeAgents = claudeAgentsByCwd[effectiveCwd] || [];
diff --git a/vibe/api.py b/vibe/api.py
index 5d42d6270..77f4e1b55 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -18,7 +18,7 @@ from typing import Any, Dict, List, Optional
import yaml
from config import paths
-from config.v2_config import CONFIG_LOCK, V2Config
+from config.v2_config import CONFIG_LOCK, DEFAULT_AGENT_BACKEND, V2Config
from config.v2_settings import (
SettingsStore,
ChannelSettings,
@@ -94,13 +94,23 @@ def _enabled_agent_backends_from_config(config: Optional[V2Config] = None) -> li
return result
+def _default_agent_backend_from_config(config: Optional[V2Config] = None) -> str:
+ try:
+ cfg = config or load_config()
+ except FileNotFoundError:
+ return DEFAULT_AGENT_BACKEND
+ agents = getattr(cfg, "agents", None)
+ return str(getattr(agents, "default_backend", DEFAULT_AGENT_BACKEND) or DEFAULT_AGENT_BACKEND)
+
+
def _ensure_builtin_default_agents(config: Optional[V2Config] = None) -> None:
backends = _enabled_agent_backends_from_config(config)
if not backends:
return
+ default_backend = _default_agent_backend_from_config(config)
store = VibeAgentStore()
try:
- store.ensure_builtin_default_agents(backends)
+ store.ensure_builtin_default_agents(backends, default_backend=default_backend)
finally:
store.close()