Receivers

Django signal receivers for the llmtool app.

Each module holds the receivers of one kind of work, alongside its signals in smarter.apps.llmtool.signals. Importing this package, as smarter.apps.llmtool.apps.PluginConfig.ready() does, connects them all.

  • plugin: the lifecycle of every plugin.

  • models: the llmtool Django models’ post_save and pre_delete signals.

  • websearch: WebsearchPlugin searches and page reads.

  • extension: Smarter Extensions.

  • sql, api, image_search and skill: the request lifecycle of each plugin kind’s tool calls.

Plugin lifecycle

Django signal receivers of the lifecycle of every plugin: create, clone, update, delete, select and call.

smarter.apps.llmtool.receivers.plugin.handle_broker_ready(sender, broker, **kwargs)[source]

Log that a broker is ready.

Brokers of every kind send this signal, so the message names the broker’s own class, e.g. smarter.apps.guardrail.manifest.brokers.guardrail.SAMGuardrailBroker.broker_ready(), rather than this module.

smarter.apps.llmtool.receivers.plugin.handle_plugin_called(sender, plugin, **kwargs)[source]

Handle plugin called signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • kwargs – The signal’s other arguments, of which inquiry_type are logged.

smarter.apps.llmtool.receivers.plugin.handle_plugin_cloned(sender, plugin, **kwargs)[source]

Handle plugin cloned signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

smarter.apps.llmtool.receivers.plugin.handle_plugin_created(sender, plugin, **kwargs)[source]

Handle plugin created signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

smarter.apps.llmtool.receivers.plugin.handle_plugin_deleted(sender, plugin, plugin_name, **kwargs)[source]

Handle plugin deleted signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • plugin_name (str) – The deleted plugin’s name.

smarter.apps.llmtool.receivers.plugin.handle_plugin_deleting(sender, plugin, plugin_meta, **kwargs)[source]

Handle plugin deleting signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin – The plugin.

  • plugin_meta (PluginMeta) – The plugin’s PluginMeta, whose name is logged.

smarter.apps.llmtool.receivers.plugin.handle_plugin_ready(sender, plugin, **kwargs)[source]

Handle plugin ready signal.

DEBUG, not INFO: the signal is sent each time PluginBase.ready() passes, which happens several times for every prompt that uses the plugin.

smarter.apps.llmtool.receivers.plugin.handle_plugin_responded(sender, plugin, **kwargs)[source]

Handle plugin responded signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • kwargs – The signal’s other arguments, of which inquiry_type, response, inquiry_return are logged.

smarter.apps.llmtool.receivers.plugin.handle_plugin_selected(sender, *args, **kwargs)[source]

Handle plugin selected signal.

smarter.apps.llmtool.receivers.plugin.handle_plugin_updated(sender, plugin, **kwargs)[source]

Handle plugin updated signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

smarter.apps.llmtool.receivers.plugin.handle_search_term_matched(sender, prompt, search_term, method, matched_text=None, **kwargs)[source]

Handle search term matched signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • prompt (str) – The user’s prompt, which is logged at DEBUG only, because it is the user’s conversation.

  • search_term (str) – The plugin’s search term that matched.

  • method (str) – How it matched, e.g. thesaurus.

  • matched_text – The text of the prompt that matched, if any.

WebsearchPlugin

Django signal receivers of WebsearchPlugin searches and page reads.

smarter.apps.llmtool.receivers.websearch.handle_websearch_failed(sender, plugin, operation, target, error, **kwargs)[source]

Handle websearch failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • operation (str) – What failed, e.g. search or fetch.

  • target (str) – The query or URL that failed.

  • error (str) – Why it failed.

smarter.apps.llmtool.receivers.websearch.handle_websearch_fetched(sender, plugin, url, **kwargs)[source]

Handle websearch fetched signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • url (str) – The URL.

  • kwargs – The signal’s other arguments, of which final_url, characters, truncated, cached are logged.

smarter.apps.llmtool.receivers.websearch.handle_websearch_searched(sender, plugin, query, provider, result_count, **kwargs)[source]

Handle websearch searched signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • query (str) – The search query.

  • provider (str) – The web search API, e.g. brave.

  • result_count (int) – How many results the search returned.

  • kwargs – The signal’s other arguments, of which cached are logged.

Extensions

Django signal receivers of Smarter Extensions: installation, and calls to their tools.

smarter.apps.llmtool.receivers.extension.handle_extension_disabled(sender, extension, reason='', **kwargs)[source]

Handle extension disabled signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • extension – The extension.

  • reason (str) – Why it was disabled.

smarter.apps.llmtool.receivers.extension.handle_extension_enabled(sender, extension, **kwargs)[source]

Handle extension enabled signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • extension – The extension.

smarter.apps.llmtool.receivers.extension.handle_extension_installed(sender, extension, version, **kwargs)[source]

Handle extension installed signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • extension – The extension.

  • version – The installed ExtensionVersion.

smarter.apps.llmtool.receivers.extension.handle_extension_tool_called(sender, slug, version, tool_name, arguments=None, **kwargs)[source]

Handle extension tool called signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • slug (str) – The extension’s slug.

  • version (str) – The extension’s version.

  • tool_name (str) – The tool’s name.

  • arguments – The arguments that the LLM called the tool with.

smarter.apps.llmtool.receivers.extension.handle_extension_tool_completed(sender, slug, version, tool_name, success, duration, **kwargs)[source]

Handle extension tool completed signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • slug (str) – The extension’s slug.

  • version (str) – The extension’s version.

  • tool_name (str) – The tool’s name.

  • success (bool) – Whether the request succeeded.

  • duration (float) – Seconds that the request took.

smarter.apps.llmtool.receivers.extension.handle_extension_tool_failed(sender, slug, version, tool_name, error, **kwargs)[source]

Handle extension tool failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • slug (str) – The extension’s slug.

  • version (str) – The extension’s version.

  • tool_name (str) – The tool’s name.

  • error (str) – Why it failed.

smarter.apps.llmtool.receivers.extension.handle_extension_tool_responded(sender, slug, version, tool_name, characters=0, cached=False, **kwargs)[source]

Handle extension tool responded signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • slug (str) – The extension’s slug.

  • version (str) – The extension’s version.

  • tool_name (str) – The tool’s name.

  • characters (int) – The length of the tool’s result, in characters.

  • cached (bool) – Whether the response was served from the cache.

smarter.apps.llmtool.receivers.extension.handle_extension_uninstalled(sender, slug, **kwargs)[source]

Handle extension uninstalled signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • slug (str) – The extension’s slug.

smarter.apps.llmtool.receivers.extension.handle_extension_upgraded(sender, extension, version, previous_version, **kwargs)[source]

Handle extension upgraded signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • extension – The extension.

  • version – The ExtensionVersion that is now installed.

  • previous_version (str) – The version that was installed before.

SqlPlugin

Django signal receivers of SqlPlugin tool calls.

smarter.apps.llmtool.receivers.sql.handle_sql_plugin_authenticated(sender, plugin, **kwargs)[source]

Handle SqlPlugin authenticated signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • kwargs – The signal’s other arguments, of which connection are logged.

smarter.apps.llmtool.receivers.sql.handle_sql_plugin_authentication_failed(sender, plugin, error, **kwargs)[source]

Handle SqlPlugin authentication failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • error (str) – Why it failed.

  • kwargs – The signal’s other arguments, of which connection are logged.

smarter.apps.llmtool.receivers.sql.handle_sql_plugin_failed(sender, plugin, error, **kwargs)[source]

Handle SqlPlugin failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • error (str) – Why it failed.

smarter.apps.llmtool.receivers.sql.handle_sql_plugin_request_completed(sender, plugin, success, duration, **kwargs)[source]

Handle SqlPlugin request completed signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • success (bool) – Whether the request succeeded.

  • duration (float) – Seconds that the request took.

smarter.apps.llmtool.receivers.sql.handle_sql_plugin_request_started(sender, plugin, function_args=None, **kwargs)[source]

Handle SqlPlugin request started signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • function_args – The arguments that the LLM called the tool with.

smarter.apps.llmtool.receivers.sql.handle_sql_plugin_responded(sender, plugin, response=None, cached=False, **kwargs)[source]

Handle SqlPlugin responded signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • response – The response, whose length in characters is logged.

  • cached (bool) – Whether the response was served from the cache.

  • kwargs – The signal’s other arguments, of which sql are logged.

ApiPlugin

Django signal receivers of ApiPlugin tool calls.

smarter.apps.llmtool.receivers.api.handle_api_plugin_authenticated(sender, plugin, **kwargs)[source]

Handle ApiPlugin authenticated signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • kwargs – The signal’s other arguments, of which connection, auth_method, status_code are logged.

smarter.apps.llmtool.receivers.api.handle_api_plugin_authentication_failed(sender, plugin, error, **kwargs)[source]

Handle ApiPlugin authentication failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • error (str) – Why it failed.

  • kwargs – The signal’s other arguments, of which connection, auth_method, status_code are logged.

smarter.apps.llmtool.receivers.api.handle_api_plugin_failed(sender, plugin, error, **kwargs)[source]

Handle ApiPlugin failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • error (str) – Why it failed.

smarter.apps.llmtool.receivers.api.handle_api_plugin_request_completed(sender, plugin, success, duration, **kwargs)[source]

Handle ApiPlugin request completed signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • success (bool) – Whether the request succeeded.

  • duration (float) – Seconds that the request took.

smarter.apps.llmtool.receivers.api.handle_api_plugin_request_started(sender, plugin, function_args=None, **kwargs)[source]

Handle ApiPlugin request started signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • function_args – The arguments that the LLM called the tool with.

smarter.apps.llmtool.receivers.api.handle_api_plugin_responded(sender, plugin, response=None, cached=False, **kwargs)[source]

Handle ApiPlugin responded signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • response – The response, whose length in characters is logged.

  • cached (bool) – Whether the response was served from the cache.

  • kwargs – The signal’s other arguments, of which method, endpoint are logged.

SkillPlugin

Django signal receivers of SkillPlugin tool calls, and the retrieval of remote skills.

smarter.apps.llmtool.receivers.skill.handle_skill_plugin_failed(sender, plugin, error, **kwargs)[source]

Handle SkillPlugin failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • error (str) – Why it failed.

smarter.apps.llmtool.receivers.skill.handle_skill_plugin_request_completed(sender, plugin, success, duration, **kwargs)[source]

Handle SkillPlugin request completed signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • success (bool) – Whether the request succeeded.

  • duration (float) – Seconds that the request took.

smarter.apps.llmtool.receivers.skill.handle_skill_plugin_request_started(sender, plugin, function_args=None, **kwargs)[source]

Handle SkillPlugin request started signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • function_args – The arguments that the LLM called the tool with.

smarter.apps.llmtool.receivers.skill.handle_skill_plugin_responded(sender, plugin, response=None, cached=False, **kwargs)[source]

Handle SkillPlugin responded signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • response – The response, whose length in characters is logged.

  • cached (bool) – Whether the response was served from the cache.

  • kwargs – The signal’s other arguments, of which resource are logged.

smarter.apps.llmtool.receivers.skill.handle_skill_plugin_retrieval_failed(sender, plugin, url, error, **kwargs)[source]

Handle SkillPlugin retrieval failed signal.

Logs it at WARNING.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • url (str) – The URL.

  • error (str) – Why it failed.

smarter.apps.llmtool.receivers.skill.handle_skill_plugin_retrieval_started(sender, plugin, url, **kwargs)[source]

Handle SkillPlugin retrieval started signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • url (str) – The URL.

smarter.apps.llmtool.receivers.skill.handle_skill_plugin_retrieved(sender, plugin, url, **kwargs)[source]

Handle SkillPlugin retrieved signal.

Logs it at INFO.

Parameters:
  • sender – The class that sent the signal.

  • plugin (PluginBase) – The plugin.

  • url (str) – The URL.

  • kwargs – The signal’s other arguments, of which skill_name, resource_count, duration are logged.

Django models

Django signal receivers of the llmtool Django models.

smarter.apps.llmtool.receivers.models.handle_plugin_data_api_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginDataApi.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_data_api_saved(sender, instance, created, **kwargs)[source]

Handle plugin data API saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

smarter.apps.llmtool.receivers.models.handle_plugin_data_saved(sender, instance, created, **kwargs)[source]

Handle plugin data saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

smarter.apps.llmtool.receivers.models.handle_plugin_data_sql_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginDataSql.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_data_sql_saved(sender, instance, created, **kwargs)[source]

Handle plugin data SQL saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

smarter.apps.llmtool.receivers.models.handle_plugin_data_static_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginDataStatic.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_data_websearch_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginDataWebsearch.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_data_websearch_saved(sender, instance, created, **kwargs)[source]

Handle plugin data websearch saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

smarter.apps.llmtool.receivers.models.handle_plugin_meta_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginMeta.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_meta_saved(sender, instance, created, **kwargs)[source]

Handle plugin meta saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

smarter.apps.llmtool.receivers.models.handle_plugin_prompt_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginPrompt.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_prompt_saved(sender, instance, created, **kwargs)[source]

Handle plugin prompt saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

smarter.apps.llmtool.receivers.models.handle_plugin_selector_history_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginSelectorHistory.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_selector_history_saved(sender, instance, created, **kwargs)[source]

Handle plugin selector history saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

smarter.apps.llmtool.receivers.models.handle_plugin_selector_pre_delete(sender, instance, **kwargs)[source]

Handle pre-delete signal for PluginSelector.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

smarter.apps.llmtool.receivers.models.handle_plugin_selector_saved(sender, instance, created, **kwargs)[source]

Handle plugin selector saved signal.

Logs it at INFO.

Parameters:
  • sender – The model class.

  • instance – The row.

  • created – True if the row was created, False if it was updated.

Utilities

Helpers of the llmtool signal receivers.

smarter.apps.llmtool.receivers.utils.response_characters(response)[source]

Return the length of a tool call’s response, as JSON, or of a string response.

Return type:

int