Resource Types’ Feature Flags

Each Django app that owns SAM resource kinds, e.g. the guardrail app, which owns the Guardrail kind, has a feature flag, smarter_settings.enable_<app>, set with its SMARTER_ENABLE_<APP> environment variable. Every flag defaults to true. SAM_APPS lists the apps, their flags and their kinds. What an operator sees when a flag is false is in Turning resource types off.

Code that serves an app’s resources asks this module whether the app is on, rather than reading the flag itself:

  • a urlconf mounts each app’s urls with sam_app_urlpatterns(), from a table of SamAppUrls, e.g. SAM_APP_CONSOLE_URLS in smarter.urls.console;

  • code that links to an app’s page reverses it with reverse_if_enabled(), which returns None while the app is off;

  • the cli api calls raise_if_kind_disabled() before it brokers a manifest, and the commands that apply manifests skip a kind for which kind_is_enabled() is false;

  • each app’s AppConfig names its flag in enabled_setting. See Apps.

A new resource kind is added to its app’s kinds in SAM_APPS, or to CORE_KINDS if it belongs to a core app. A test fails until it is in exactly one of them. A new SAM app gets an entry in SAM_APPS, a flag in FeatureSettings, and a row in each urlconf’s table. Tests fail until it has all of them.

In a test, smarter.lib.unittest.sam_apps.disabled_sam_apps() turns flags off.

The SAM resource apps’ feature flags: one smarter_settings.enable_<app> flag per app.

Each SAM resource app (Connection, Guardrail, LLMClient, …) can be turned off with its SMARTER_ENABLE_<APP> environment variable. Every flag defaults to true. A disabled app is off everywhere:

The account, prompt and other core apps have no flag: the platform doesn’t work without them. Their kinds (Account, User, Budget, AuthToken, Prompt) are always enabled.

smarter.lib.manifest.sam_apps.CORE_KINDS: tuple[str, ...] = ('Account', 'SmarterAuthToken', 'Budget', 'Prompt', 'User')

The kinds of the core apps, which have no feature flag and are always enabled.

('Account', 'SmarterAuthToken', 'Budget', 'Prompt', 'User')
exception smarter.lib.manifest.sam_apps.SAMKindDisabledError(message='')[source]

A manifest’s kind belongs to a SAM app that this platform has disabled.

smarter.lib.manifest.sam_apps.SAM_APPS: tuple[SamApp, ...] = (('connection', 'app_connection_enable', 'Connection', ('ApiConnection', 'SqlConnection')), ('guardrail', 'app_guardrail_enable', 'Guardrail', ('Guardrail',)), ('llmclient', 'app_llmclient_enable', 'LLMClient', ('LLMClient', 'CustomDomain')), ('llmhost', 'app_llmhost_enable', 'LLMHost', ('LLMHost', 'LLMHostCompute')), ('llmtool', 'app_llmtool_enable', 'LLMTool', ('ApiPlugin', 'ImageSearchPlugin', 'SkillPlugin', 'SqlPlugin', 'Plugin', 'WebsearchPlugin')), ('mcpclient', 'app_mcpclient_enable', 'MCPClient', ('MCPClient',)), ('orchestrator', 'app_orchestrator_enable', 'Orchestrator', ('Orchestrator',)), ('provider', 'app_provider_enable', 'Provider', ('Provider',)), ('proxy', 'app_proxy_enable', 'Proxy', ('Proxy',)), ('secret', 'app_secret_enable', 'Secret', ('Secret',)), ('vectorsearch', 'app_vectorsearch_enable', 'VectorSearch', ('Vectorsearch',)), ('vectorstore', 'app_vectorstore_enable', 'Vectorstore', ('Vectorstore',)))

Every SAM resource app that has a feature flag.

(
    SamApp(app_label='connection', setting='app_connection_enable', label='Connection', kinds=('ApiConnection', 'SqlConnection')),
    SamApp(app_label='guardrail', setting='app_guardrail_enable', label='Guardrail', kinds=('Guardrail',)),
    SamApp(app_label='llmclient', setting='app_llmclient_enable', label='LLMClient', kinds=('LLMClient', 'CustomDomain')),
    SamApp(app_label='llmhost', setting='app_llmhost_enable', label='LLMHost', kinds=('LLMHost', 'LLMHostCompute')),
    SamApp(app_label='llmtool', setting='app_llmtool_enable', label='LLMTool', kinds=('ApiPlugin', 'ImageSearchPlugin', 'SkillPlugin', 'SqlPlugin', 'Plugin', 'WebsearchPlugin')),
    SamApp(app_label='mcpclient', setting='app_mcpclient_enable', label='MCPClient', kinds=('MCPClient',)),
    SamApp(app_label='orchestrator', setting='app_orchestrator_enable', label='Orchestrator', kinds=('Orchestrator',)),
    SamApp(app_label='provider', setting='app_provider_enable', label='Provider', kinds=('Provider',)),
    SamApp(app_label='proxy', setting='app_proxy_enable', label='Proxy', kinds=('Proxy',)),
    SamApp(app_label='secret', setting='app_secret_enable', label='Secret', kinds=('Secret',)),
    SamApp(app_label='vectorsearch', setting='app_vectorsearch_enable', label='VectorSearch', kinds=('Vectorsearch',)),
    SamApp(app_label='vectorstore', setting='app_vectorstore_enable', label='Vectorstore', kinds=('Vectorstore',)),
)
class smarter.lib.manifest.sam_apps.SamApp(app_label: str, setting: str, label: str, kinds: tuple[str, ...])[source]

A SAM resource app, the feature flag that enables it, and the manifest kinds it owns.

app_label: str

The Django app label, e.g. guardrail.

property env_name: str

The environment variable that sets the flag, e.g. SMARTER_APP_GUARDRAIL_ENABLE.

is_enabled(settings)[source]

Whether the app is enabled.

Parameters:

settings (FeatureSettings) – The settings that hold the flag, normally smarter_settings.

Return type:

bool

Returns:

The value of the app’s flag.

kinds: tuple[str, ...]

The manifest kinds that the app owns, e.g. ("Guardrail",).

label: str

The app’s name in messages, e.g. Guardrail.

setting: str

The name of the smarter_settings flag that enables the app, e.g. app_guardrail_enable.

class smarter.lib.manifest.sam_apps.SamAppUrls(setting: str, label: str, prefix: str, urls: ModuleType, namespace: str)[source]

The urls of one SAM resource app in one urlconf, and the feature flag that mounts them.

label: str

The urls’ name in log messages, e.g. Guardrail.

namespace: str

The urls’ namespace.

prefix: str

The urls’ path prefix, e.g. guardrail/.

setting: str

The name of the smarter_settings flag that mounts the urls, e.g. app_guardrail_enable.

urls: ModuleType

The app’s urls module.

smarter.lib.manifest.sam_apps.get_sam_app(setting)[source]

Return the SAM app that a flag enables.

Parameters:

setting (str) – The flag’s name, e.g. app_guardrail_enable.

Return type:

SamApp

Returns:

The app.

Raises:

KeyError – If no SAM app has that flag.

smarter.lib.manifest.sam_apps.kind_is_enabled(kind, settings=None)[source]

Whether this platform accepts manifests of a kind.

Parameters:
  • kind (str) – The kind, in any case.

  • settings (FeatureSettings | None) – The settings that hold the flags. Defaults to smarter_settings.

Return type:

bool

Returns:

False if the kind’s SAM app is disabled, otherwise True, for core and unknown kinds too.

smarter.lib.manifest.sam_apps.raise_if_kind_disabled(kind, settings=None)[source]

Refuse a manifest kind whose SAM app is disabled.

Parameters:
  • kind (str) – The kind, in any case.

  • settings (FeatureSettings | None) – The settings that hold the flags. Defaults to smarter_settings.

Raises:

SAMKindDisabledError – If the kind’s app is disabled. Its message names the environment variable that enables it.

Return type:

None

smarter.lib.manifest.sam_apps.sam_app_of_kind(kind)[source]

Return the SAM app that owns a manifest kind.

Parameters:

kind (str) – The kind, in any case, e.g. Guardrail or guardrail.

Return type:

SamApp | None

Returns:

The app, or None for a core kind, e.g. Account, or an unknown one.

smarter.lib.manifest.sam_apps.sam_app_urlpatterns(settings, apps_urls, description)[source]

Return the url patterns of the SAM resource apps whose feature flag is true.

Logs, for each one, whether its urls are mounted, and the environment variable that mounts them when they aren’t. The log entries are named after the caller, the urlconf whose urls they are, e.g. smarter.apps.api.v1.urls, rather than after this function.

Parameters:
  • settings (FeatureSettings) – The settings that hold the enable_<app> flags, normally smarter_settings.

  • apps_urls (list[SamAppUrls]) – The apps’ urls and the flag that mounts each one.

  • description (str) – What the urls are, in log messages, e.g. web console pages.

Return type:

list[URLResolver]

Returns:

One include() per enabled app, in the order of apps_urls.

System checks

Django system checks of the SAM resource apps’ feature flags.

A SAM app can be turned off with its SMARTER_ENABLE_<APP> flag (see smarter.lib.manifest.sam_apps). Some combinations of flags don’t hold together, e.g. LLMClients enabled while Providers, which an LLMClient’s model refers to, are disabled. Rather than keep a list of dependencies by hand, these checks read them from the models’ relations:

  • smarter.W003: a model of an enabled SAM app has a foreign key, one-to-one or many-to-many field to a model of a disabled one. The enabled app’s resources can’t be applied or work as declared.

  • smarter.W004: a disabled SAM app’s models still have rows. They stay in the database, unused: nothing can read, change or delete them through Smarter until the app is enabled again. This check reads the database, so it runs only with manage.py check --database default.

They are registered by smarter.apps.api.apps.ApiConfig.

smarter.lib.manifest.checks.DISABLED_APP_HAS_ROWS_ID = 'smarter.W004'

The id of the warning that a disabled SAM app’s models still have rows.

smarter.lib.manifest.checks.DISABLED_DEPENDENCY_ID = 'smarter.W003'

The id of the warning that an enabled SAM app’s model refers to a disabled SAM app’s model.

smarter.lib.manifest.checks.check_disabled_sam_app_rows(app_configs=None, **kwargs)[source]

Warn about disabled SAM apps whose models still have rows.

Runs only with manage.py check --database.

Parameters:
  • app_configs (Any) – The apps to check, or None for all of them. Ignored: the check is about the whole platform.

  • kwargs (Any) – Django’s, among them databases, which --database names. The check does nothing without one.

Return type:

list[CheckMessage]

Returns:

The warnings.

smarter.lib.manifest.checks.check_sam_app_dependencies(app_configs=None, **kwargs)[source]

Warn about enabled SAM apps whose models refer to a disabled SAM app’s models.

Parameters:

app_configs (Any) – The apps to check, or None for all of them. Ignored: the check is about the whole platform.

Return type:

list[CheckMessage]

Returns:

The warnings.

smarter.lib.manifest.checks.disabled_app_rows_warnings(settings)[source]

Warn about each disabled SAM app whose models still have rows.

Parameters:

settings (Any) – The settings that hold the flags, normally smarter_settings.

Return type:

list[CheckMessage]

Returns:

One warning per disabled app that has rows.

smarter.lib.manifest.checks.disabled_dependency_warnings(settings)[source]

Warn about each relation from an enabled SAM app’s model to a disabled SAM app’s model.

Parameters:

settings (Any) – The settings that hold the flags, normally smarter_settings.

Return type:

list[CheckMessage]

Returns:

One warning per relation.

smarter.lib.manifest.checks.sam_app_of_model(model)[source]

Return the SAM app that a model belongs to.

Parameters:

model (type[Model]) – The model class.

Return type:

SamApp | None

Returns:

The SAM app, or None for a model of a core or third-party app.