PluginSelector Model

PluginSelector model for defining plugin selection strategies within the Smarter platform.

class smarter.apps.plugin.models.plugin_selector.PluginSelector(*args, **kwargs)[source]

Bases: TimestampedModel

Stores plugin selection strategies for a Smarter plugin.

The PluginSelector model defines how and when a plugin is included in the prompt sent to the LLM (Large Language Model). Each instance is linked to a PluginMeta object, representing the plugin whose selection logic is being configured.

The primary function of this model is to specify a selection directive—such as search_terms, always, or llm—that determines the conditions under which the plugin should be activated. For example, when the directive is search_terms, the search_terms field contains a list of keywords or phrases (in JSON format). If any of these terms are detected in the user’s prompt, Smarter will prioritize loading and invoking the associated plugin. This enables context-aware, dynamic plugin routing based on user intent.

PluginSelector works in concert with other models in this module:
  • It references PluginMeta to associate selection logic with a specific plugin.

  • It is audited by PluginSelectorHistory, which records each activation event, the triggering search term, and relevant user prompt context for analytics and debugging.

  • It complements PluginPrompt, which customizes the LLM prompt for each plugin, allowing for both selection and prompt configuration to be managed independently.

By supporting multiple selection strategies, this model enables flexible, intelligent plugin discovery and orchestration within the Smarter platform. It is essential for implementing advanced plugin routing, ensuring that the most relevant plugins are surfaced to the LLM based on user input and system configuration.

See also:

Parameters:
  • id (Unknown) – Primary key: ID

  • created_at (Unknown) – Created at

  • updated_at (Unknown) – Updated at

  • directive (Unknown) – Directive. The selection strategy to use for this plugin.

  • search_terms (Unknown) – Search terms. search terms in JSON format that, if detected in the user prompt, will incentivize Smarter to load this plugin.

Relationship fields:

Parameters:

plugin (Unknown) – Plugin (related name: plugin_selector_plugin)

Reverse relationships:

Parameters:

plugin_selector_history_plugin_selector (Unknown) – All plugin selector history plugin selector of this plugin selector (related name of plugin_selector)

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

SELECT_DIRECTIVES = [('search_terms', 'search_terms'), ('always', 'always'), ('llm', 'llm')]
created_at

DateTimeField

Created at

Timestamp indicating when the model instance was created.

This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.

Type:

Type

directive

CharField

Directive. The selection strategy to use for this plugin.

Choices:

  • search_terms

  • always

  • llm

Type:

Type

classmethod get_cached_selector_by_plugin(plugin, invalidate=False)[source]

Return a single instance of PluginSelector by plugin.

This method caches the results to improve performance.

Parameters:

plugin (PluginMeta) – The plugin whose selector should be retrieved.

Returns:

A PluginSelector instance if found, otherwise None.

Return type:

PluginSelector | None

get_directive_display(*, field=<django.db.models.CharField: directive>)

Shows the label of the directive. See get_FOO_display() for more information.

id

BigAutoField

Primary key: ID

Type:

Type

objects = <django.db.models.Manager object>
plugin

OneToOneField to PluginMeta

Plugin (related name: plugin_selector_plugin)

Type:

Type

plugin_id

Internal field, use plugin instead.

plugin_selector_history_plugin_selector

Reverse ForeignKey from PluginSelectorHistory

All plugin selector history plugin selector of this plugin selector (related name of plugin_selector)

Type:

Type

search_terms

JSONField

Search terms. search terms in JSON format that, if detected in the user prompt, will incentivize Smarter to load this plugin.

Type:

Type

updated_at

DateTimeField

Updated at

Timestamp indicating when the model instance was last updated.

This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.

Type:

Type

class smarter.apps.plugin.models.plugin_selector.PluginSelectorSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Serializer for the PluginSelector model.