Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

6.7 KB
Raw Blame
"""Registry of feature flags.

A feature flag is a named on/off switch for the whole deployment. It is set
when the server is deployed (``FEATURE_FLAGS_ENABLED``, a comma-separated list
of the flags that are on) and nobody can change it while the server runs.
Every flag not listed is off. Naming a key that is not registered here is a
startup error, so a typo cannot silently leave a flag off.

Core reads them from config. Agents read them at ``GET /agents/feature-flags``,
and Switch Console and the dashboard at ``GET /gateway/feature-flags``. Console
re-reads every server it is connected to on a schedule, keeps its own list of
the keys it acts on, and treats a key it does not know, or one the server did
not send, as off.
"""

from __future__ import annotations

# Gate the ecosystem graph's "Show owners" overlay. When OFF the graph never
# exposes owner data, so the frontend toggle has nothing to reveal.
ECOSYSTEM_SHOW_OWNERS = "ecosystem.show_owners"

# Switch Cloud. Core has nothing of its own behind it; clients read it.
SWITCH_CLOUD = "switch_cloud"

# Cloud machines: one machine per user, run by Switch, that agents can be
# placed on. The flag offers them; whether this server can run them is its
# hosted settings (HOSTED_LAUNCH_CAPACITY and the controller config), and a
# server that cannot says so when one is claimed.
HOSTED_AGENTS = "hosted_agents"

# Agent management: managed agents, the machines and agent controllers that
# run them, and the controller-facing routes under /v1/management and
# /v1/controllers. With it off none of those routes are mounted.
AGENT_MANAGEMENT = "agent_management"

# Service connections: people connect outside services (GitHub's grants,
# Atlassian, Google Workspace, Datadog and the rest of the catalog) and grant
# them to their agents. With it off, the routes for connections, sign-ins,
# keys and grants (`/gateway/service-connections`, `/gateway/agents/{id}/
# service-grants`, `/agents/{id}/service-grants` and `service-tokens`) are not
# mounted: agent hosts read that as no grants, and Console and the dashboard
# show no services but GitHub's link, as before connections. GitHub's own
# connect routes stay.
SERVICE_CONNECTIONS = "service_connections"

# Follow the conversation: a person's message that mentions nobody reaches an
# agent when it is a reply in a thread the agent is taking part in, the next
# message in an exchange the agent has just answered, or a message in a room
# whose main agent it is (`delivery/conversation.py`). With it off such
# messages reach nobody, as before.
FOLLOW_THE_CONVERSATION = "follow_the_conversation"

# Decision routing: in a room that turned it on (`!auto-route on`), a person's
# message that no rule delivered to any agent is sent, once it is saved, to
# the decision service its workspace uses (`decision/settings.py`: the
# workspace's choice, else `DECISION_ENDPOINT_URL`), which picks the one agent
# that should answer it, or nobody (`delivery/decision.py`). It builds on the
# follow-the-conversation filters, so the server refuses it without that flag.
DECISION_ROUTING = "decision_routing"

# Agent chats in Switch Console: an agent's page opens on its chats (its
# direct chats and the rooms it is in) beside the conversation. Core puts an
# agent's owner back in each chat they started that holds the agent; with it
# off, owning an agent gives no room membership.
AGENT_CHATS = "agent_chats"

# switch-buddy: each person's own assistant, which Switch Console creates on
# their computer at the end of its first run. Core serves the built-in
# switch-buddy template only with it on (and agent management, which the
# buddy runs as), and Console offers the buddy only on a server that turns it
# on, so a server without the template is never asked to make one.
SWITCH_BUDDY = "switch_buddy"

# Group chats in Switch Console: chats with people and with no or several
# agents, adding and removing a chat's agents, naming people in a message, and
# the agents a person may add. Turn it on only once every switch-core process
# runs a release that has it: the guarantee is server-first rollout, then the
# flag. An upgraded process refuses those requests while it is off, but a
# process still on an older release ignores the fields it does not know, so
# 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"

# Connector apps per organization: a workspace signs in to GitHub and the
# static OAuth services through the app its organization registered, where
# it registered one, and through the server's otherwise
# (`connections/organization_apps.py`). With it off every workspace uses the
# server's apps, as before organizations.
ORGANIZATION_CONNECTOR_APPS = "organization_connector_apps"

# The dashboard's new layout: Overview, Templates and Connectors on the rail,
# Workspace and Organization settings as their own areas, and the operator's
# pages in a Platform area. Today's pages move into it and their old URLs
# redirect. Core has nothing of its own behind it; the dashboard reads it. It
# stays off until every page of the new layout is built, and on a server with
# it off the dashboard is laid out as before.
GATEWAY_V2 = "gateway_v2"

# Flags that need another flag on: the server refuses a configuration with
# the key on and any of its values off, and tools that turn flags off one at a
# time (scripts/e2e_surface.py) turn the dependants off with it.
FLAG_REQUIRES: dict[str, frozenset[str]] = {
    DECISION_ROUTING: frozenset({FOLLOW_THE_CONVERSATION}),
}


def without_flag(flags: frozenset[str], flag: str) -> frozenset[str]:
    """`flags` with `flag` off, and every flag that needs it off too."""
    off = {flag}
    changed = True
    while changed:
        changed = False
        for dependant, needs in FLAG_REQUIRES.items():
            if dependant not in off and needs & off:
                off.add(dependant)
                changed = True
    return flags - off


# Every flag the server recognises.
KNOWN_FEATURE_FLAGS: frozenset[str] = frozenset(
    {
        ECOSYSTEM_SHOW_OWNERS,
        SWITCH_CLOUD,
        HOSTED_AGENTS,
        AGENT_MANAGEMENT,
        SERVICE_CONNECTIONS,
        FOLLOW_THE_CONVERSATION,
        DECISION_ROUTING,
        AGENT_CHATS,
        SWITCH_BUDDY,
        GROUP_CHATS,
        BUDDY_SLACK_HANDOFF,
        ORGANIZATION_CONNECTOR_APPS,
        GATEWAY_V2,
    }
)