Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Put the buddy Slack hand-off behind the buddy_slack_handoff flag
raullopez-sandboxf74dc2df7412
diff --git a/.env.example b/.env.exampleindex dccc3f259..2c7f49abb 100644--- a/.env.example+++ b/.env.example@@ -185,6 +185,9 @@ CONTROLLER_TOKEN_SECRET=# switch_buddy each person's own assistant, created by Switch# Console at the end of its first run (needs# agent_management)+# buddy_slack_handoff switch-buddy's welcome moves to a private+# channel on the team's chat app (turn on only+# once every switch-core process has it)FEATURE_FLAGS_ENABLED=# ── Server keys ──────────────────────────────────────────────────────────────diff --git a/console/apps/switch-console-desktop/src/renderer/features/managed-agents/agent-chats.tsx b/console/apps/switch-console-desktop/src/renderer/features/managed-agents/agent-chats.tsxindex 0b1ed8dfa..b0961d020 100644--- a/console/apps/switch-console-desktop/src/renderer/features/managed-agents/agent-chats.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/managed-agents/agent-chats.tsx@@ -12,6 +12,7 @@ import { RoomListRow } from '@renderer/features/sidebar/main-section';import { SidebarItemMiniButton } from '@renderer/features/sidebar/sidebar-primitives';import { isBuddy } from '@renderer/features/switch-buddy/buddy-identity';import { BuddySetupCards } from '@renderer/features/switch-buddy/buddy-setup-cards';+import { buddySetupCardsEnabled } from '@renderer/features/switch-buddy/buddy-setup-step';import { EmbeddedRoom } from '@renderer/features/switch-rooms/view';import { isConsoleDirectChatSummary } from '@renderer/features/switch-servers/room-filters';import { switchRoomsStore } from '@renderer/features/switch-servers/switch-rooms-store';@@ -184,6 +185,7 @@ export const AgentChats = observer(function AgentChats({ agent }: { agent: Managconst roomsError = switchRoomsStore.errorFor(workspaceId, agentId);const { sections, section } = useAgentSection(serverId, agent, params.section);const thisComputer = useRunsOnThisComputer(agent);+ const setupCards = buddySetupCardsEnabled(useFeatureFlags(serverId));const shownRoom = openAgentRoom(agent, params.room, section);// The unsaved chat open before a reload is kept, but not in memory yet: it opens again.const restoring =@@ -332,7 +334,7 @@ export const AgentChats = observer(function AgentChats({ agent }: { agent: ManagserverId={serverId}roomId={roomId}afterMessages={- isBuddy(agent) ? (+ isBuddy(agent) && setupCards ? (<BuddySetupCardsserverId={serverId}workspaceId={workspaceId}diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.test.tsindex 02de26fb3..b2e53ef90 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.test.ts@@ -1,7 +1,7 @@import { describe, expect, it } from 'vitest';import type { ChatSummary } from '@shared/core/chats/chats';import type { LinkedIdentity, RemoteBridge } from '@shared/core/switch-servers/switch-servers';-import { buddySetupStep } from './buddy-setup-step';+import { buddySetupCardsEnabled, buddySetupStep } from './buddy-setup-step';const slack = { id: 'b-1', type: 'slack', status: 'active' } as RemoteBridge;const slack2 = { id: 'b-2', type: 'slack', status: 'active' } as RemoteBridge;@@ -11,6 +11,15 @@ const handedOff = { roomId: 'r-2', channelType: 'direct', bridgeType: 'slack' }const base = { bridges: [], identities: [], resumes: {}, failed: false };+describe('buddySetupCardsEnabled', () => {+ it('is on only when the server turns the flag on', () => {+ expect(buddySetupCardsEnabled(undefined)).toBe(false);+ expect(buddySetupCardsEnabled({})).toBe(false);+ expect(buddySetupCardsEnabled({ buddy_slack_handoff: false })).toBe(false);+ expect(buddySetupCardsEnabled({ buddy_slack_handoff: true })).toBe(true);+ });+});+describe('buddySetupStep', () => {it('waits for the reads, and says unknown when one failed, never not connected', () => {expect(buddySetupStep({ ...base, bridges: null })).toEqual({ kind: 'loading' });diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.tsindex 8382cd9ca..ec8b775e4 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-setup-step.ts@@ -1,4 +1,5 @@import type { ChatSummary } from '@shared/core/chats/chats';+import type { FeatureFlags } from '@shared/core/feature-flags/feature-flags';import type { LinkedIdentity, RemoteBridge } from '@shared/core/switch-servers/switch-servers';export type BuddySetupStep =@@ -10,6 +11,11 @@ export type BuddySetupStep =| { kind: 'create'; bridge: RemoteBridge }| { kind: 'done'; chat: ChatSummary };+/** Whether to show the setup cards: only when the server says so, since an older one would turn their resume into an internal chat. */+export function buddySetupCardsEnabled(flags: Partial<FeatureFlags> | null | undefined): boolean {+ return flags?.buddy_slack_handoff === true;+}+/** A hand-off resumed on one Slack connection: its chat, null for none started, or failed. */export type BuddyResume = ChatSummary | null | 'failed';diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.tsindex 6bc9fc5d6..918adf395 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-buddy/buddy-welcome-message.ts@@ -39,7 +39,7 @@ export function buddyWelcomeMessage({'- 🏠 Set up rooms where your team and agents work together','- 💬 Answer anything about Switch','',- 'Pick where your team chats below to get started.',+ 'Tell me which app your team uses, and I’ll walk you through connecting it.',].join('\n');}diff --git a/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.ts b/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.tsindex 18ef386f8..aa2fa3b48 100644--- a/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.ts+++ b/console/apps/switch-console-desktop/src/shared/core/feature-flags/feature-flags.ts@@ -18,6 +18,7 @@ export const CONSOLE_FEATURE_FLAGS = ['agent_chats','switch_buddy','group_chats',+ 'buddy_slack_handoff',] as const;export type FeatureFlagKey = (typeof CONSOLE_FEATURE_FLAGS)[number];diff --git a/core/switch_core/chats/service.py b/core/switch_core/chats/service.pyindex 366dda558..f15ba68b7 100644--- a/core/switch_core/chats/service.py+++ b/core/switch_core/chats/service.py@@ -178,12 +178,14 @@ class ChatService:media_max_bytes: int,agent_chats_enabled: bool,group_chats_enabled: bool,+ buddy_slack_handoff_enabled: bool,connections: AgentConnectionRegistry,) -> None:self.session_factory = session_factoryself._connections = connectionsself.agent_chats_enabled = agent_chats_enabledself.group_chats_enabled = group_chats_enabled+ self.buddy_slack_handoff_enabled = buddy_slack_handoff_enabledself.listener = listenerself.activity_listener = activity_listenerself._activity_store = AgentSessionActivityStore()@@ -1392,6 +1394,12 @@ class ChatService:"""member_user_ids = sorted(set(member_user_ids) - {user.id})direct = kind != "group" and len(agent_ids) == 1 and not member_user_ids+ if bridge_id is not None and not self.buddy_slack_handoff_enabled:+ raise ChatError(+ 409,+ "BUDDY_SLACK_HANDOFF_OFF",+ "Chats on a bridge are not turned on for this server.",+ )if bridge_id is not None and not direct:raise ChatError(422,diff --git a/core/switch_core/config.py b/core/switch_core/config.pyindex 4e7d66f3c..477c15b33 100644--- a/core/switch_core/config.py+++ b/core/switch_core/config.py@@ -17,6 +17,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDictfrom switch_core.feature_flags import (AGENT_CHATS,AGENT_MANAGEMENT,+ BUDDY_SLACK_HANDOFF,FOLLOW_THE_CONVERSATION,GROUP_CHATS,HOSTED_AGENTS,@@ -1324,6 +1325,10 @@ class SwitchConfig(BaseSettings):def group_chats_enabled(self) -> bool:return self.feature_flags[GROUP_CHATS]+ @property+ def buddy_slack_handoff_enabled(self) -> bool:+ return self.feature_flags[BUDDY_SLACK_HANDOFF]+@model_validator(mode="after")def _validate_outbound_allowed_private_hosts(self) -> "SwitchConfig":OutboundPolicy.parse(self.outbound_allowed_private_hosts)diff --git a/core/switch_core/feature_flags.py b/core/switch_core/feature_flags.pyindex 81ea0cfb0..0feb13de3 100644--- a/core/switch_core/feature_flags.py+++ b/core/switch_core/feature_flags.py@@ -72,6 +72,14 @@ SWITCH_BUDDY = "switch_buddy"# turning it on before the rollout finishes is not protected.GROUP_CHATS = "group_chats"+# switch-buddy's chat on a bridge: Console offers to move the buddy's welcome+# to a private channel with the person on their team's chat app (a chat+# created with `bridgeId`, resumed with `resumeOnly`). Like group chats, turn+# it on only after every switch-core process runs a release that has it: an+# upgraded process refuses those requests while it is off, but an older one+# ignores the fields and makes an internal chat instead.+BUDDY_SLACK_HANDOFF = "buddy_slack_handoff"+# Every flag the server recognises.KNOWN_FEATURE_FLAGS: frozenset[str] = frozenset({@@ -84,5 +92,6 @@ KNOWN_FEATURE_FLAGS: frozenset[str] = frozenset(AGENT_CHATS,SWITCH_BUDDY,GROUP_CHATS,+ BUDDY_SLACK_HANDOFF,})diff --git a/core/switch_core/main.py b/core/switch_core/main.pyindex 038d868ad..97c9ec60c 100644--- a/core/switch_core/main.py+++ b/core/switch_core/main.py@@ -1170,6 +1170,7 @@ async def run(config: SwitchConfig, process_id: str) -> None:media_max_bytes=config.agent_media_max_bytes,agent_chats_enabled=config.agent_chats_enabled,group_chats_enabled=config.group_chats_enabled,+ buddy_slack_handoff_enabled=config.buddy_slack_handoff_enabled,connections=connections,)# Changes to people's chats made in another process wake the Consolediff --git a/core/tests/switch_core/gateway/conftest.py b/core/tests/switch_core/gateway/conftest.pyindex 2d2b204fb..c2eb48dc8 100644--- a/core/tests/switch_core/gateway/conftest.py+++ b/core/tests/switch_core/gateway/conftest.py@@ -302,6 +302,7 @@ def _chat_service(media_max_bytes=1024,agent_chats_enabled=True,group_chats_enabled=True,+ buddy_slack_handoff_enabled=True,connections=connections,)room_service.on_room_agents_changed(service.sync_room)diff --git a/core/tests/switch_core/gateway/test_chats_bridged_direct.py b/core/tests/switch_core/gateway/test_chats_bridged_direct.pyindex 63a0dc995..1c2e489b7 100644--- a/core/tests/switch_core/gateway/test_chats_bridged_direct.py+++ b/core/tests/switch_core/gateway/test_chats_bridged_direct.py@@ -231,6 +231,22 @@ async def test_an_unlinked_caller_is_told_to_link_their_account(assert core.dm_calls == []+async def test_a_bridged_chat_is_refused_while_the_flag_is_off(+ chats: _Harness,+) -> None:+ agent = await chats.agent("helper", owner=chats.alice)+ bridge_id, core = await _slack(chats, link=chats.alice)+ chats.service.buddy_slack_handoff_enabled = False++ response = await _create(chats, [agent], bridge_id)++ assert response.status_code == 409+ assert _code(response) == "BUDDY_SLACK_HANDOFF_OFF"+ assert core.dm_calls == []+ async with chats.factory() as session:+ assert await session.scalar(select(func.count()).select_from(Room)) == 0++async def test_a_bridged_chat_has_one_agent(chats: _Harness) -> None:one = await chats.agent("one", owner=chats.alice)two = await chats.agent("two", owner=chats.alice)diff --git a/deploy/remote/helm/switch/values.yaml b/deploy/remote/helm/switch/values.yamlindex 6fd033211..1535a91c6 100644--- a/deploy/remote/helm/switch/values.yaml+++ b/deploy/remote/helm/switch/values.yaml@@ -450,7 +450,7 @@ switchCore:# them while the server runs. An unknown flag stops switch-core at startup.# Known flags: ecosystem.show_owners, agent_management, switch_cloud,# hosted_agents, service_connections, agent_chats, follow_the_conversation,- # switch_buddy.+ # switch_buddy, buddy_slack_handoff.featureFlags:enabled: []# Invitation e-mails. When enabled, an invitation addressed to an e-mail is