Request Lifecycle Signals

The request lifecycle signals of a plugin’s tool call.

A tool call to a SqlPlugin, ApiPlugin, ImageSearchPlugin or SkillPlugin sends one family of smarter.apps.llmtool.signals, in this order:

  1. <family>_request_started, when the tool call begins.

  2. <family>_authenticated or <family>_authentication_failed, when the plugin’s remote service accepts or rejects its credentials. Families without credentials have neither, and a response served from the cache sends neither, since nothing was authenticated.

  3. <family>_responded, with the response, or <family>_failed, with the error.

  4. <family>_request_completed, always, with whether the request succeeded and how long it took.

PluginRequest sends them, so that each plugin sends them the same way.

Example:

with PluginRequest(SQL_PLUGIN_REQUEST_SIGNALS, sender=self.__class__, plugin=self, function_args=function_args) as request:
    ...
    request.authenticated(connection=sql_connection.name)
    ...
    request.responded(response=retval, cached=False)
smarter.apps.llmtool.plugin.request.API_PLUGIN_REQUEST_SIGNALS = PluginRequestSignals(started=<django.dispatch.dispatcher.Signal object>, responded=<django.dispatch.dispatcher.Signal object>, failed=<django.dispatch.dispatcher.Signal object>, completed=<django.dispatch.dispatcher.Signal object>, authenticated=<django.dispatch.dispatcher.Signal object>, authentication_failed=<django.dispatch.dispatcher.Signal object>)

The ApiPlugin request lifecycle signals.

smarter.apps.llmtool.plugin.request.IMAGE_SEARCH_PLUGIN_REQUEST_SIGNALS = PluginRequestSignals(started=<django.dispatch.dispatcher.Signal object>, responded=<django.dispatch.dispatcher.Signal object>, failed=<django.dispatch.dispatcher.Signal object>, completed=<django.dispatch.dispatcher.Signal object>, authenticated=<django.dispatch.dispatcher.Signal object>, authentication_failed=<django.dispatch.dispatcher.Signal object>)

The ImageSearchPlugin request lifecycle signals.

class smarter.apps.llmtool.plugin.request.PluginRequest(signals, sender, plugin, function_args=None)[source]

Bases: object

Send a plugin family’s request lifecycle signals for one tool call.

Entering the context sends started. Leaving it sends failed if an exception escapes and failed() was not already called, and then completed. Exceptions are never suppressed.

Parameters:
  • signals (PluginRequestSignals) – The plugin family’s signals.

  • sender (type) – The signals’ sender, usually the plugin’s class.

  • plugin (PluginBase) – The plugin, which every signal sends.

  • function_args (dict[str, Any] | list | str | None) – The tool call’s arguments, which started sends.

__init__(signals, sender, plugin, function_args=None)[source]
authenticated(**kwargs)[source]

Send authenticated, with the plugin and kwargs, if the family has credentials.

Return type:

None

authentication_failed(error, **kwargs)[source]

Send authentication_failed, with the plugin, the error and kwargs, if the family has credentials.

Parameters:

error (str) – What went wrong. It must not contain the credentials.

Return type:

None

cached

Set by the plugin, when its response was served from the cache.

property duration: float

The seconds since the request started.

failed(error, **kwargs)[source]

Send failed, and mark the request as failed.

Parameters:

error (str) – What went wrong. It must not contain secrets.

Return type:

None

responded(response, cached=False, **kwargs)[source]

Send responded.

Parameters:
  • response (dict[str, Any] | list | str | None) – The response that the tool call returns to the LLM.

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

Return type:

None

class smarter.apps.llmtool.plugin.request.PluginRequestSignals(started, responded, failed, completed, authenticated=None, authentication_failed=None)[source]

Bases: object

One plugin family’s request lifecycle signals.

Variables:
  • started – Sent when a tool call begins.

  • responded – Sent with the response.

  • failed – Sent with the error, if the tool call fails.

  • completed – Sent when the tool call ends, successfully or not.

  • authenticated – Sent when the remote service accepts the plugin’s credentials. None if the family has no credentials.

  • authentication_failed – Sent when the remote service rejects them. None if the family has no credentials.

__init__(started, responded, failed, completed, authenticated=None, authentication_failed=None)
authenticated: Signal | None = None
authentication_failed: Signal | None = None
completed: Signal
failed: Signal
responded: Signal
started: Signal
smarter.apps.llmtool.plugin.request.SKILL_PLUGIN_REQUEST_SIGNALS = PluginRequestSignals(started=<django.dispatch.dispatcher.Signal object>, responded=<django.dispatch.dispatcher.Signal object>, failed=<django.dispatch.dispatcher.Signal object>, completed=<django.dispatch.dispatcher.Signal object>, authenticated=None, authentication_failed=None)

The SkillPlugin request lifecycle signals.

A SkillPlugin’s tool call reads its stored skill, so it has no credentials.

smarter.apps.llmtool.plugin.request.SQL_PLUGIN_REQUEST_SIGNALS = PluginRequestSignals(started=<django.dispatch.dispatcher.Signal object>, responded=<django.dispatch.dispatcher.Signal object>, failed=<django.dispatch.dispatcher.Signal object>, completed=<django.dispatch.dispatcher.Signal object>, authenticated=<django.dispatch.dispatcher.Signal object>, authentication_failed=<django.dispatch.dispatcher.Signal object>)

The SqlPlugin request lifecycle signals.