Toolkit
The extension tools that a prompt offers the LLM.
ExtensionToolkit turns an LLMClient’s extensions into what an OpenAI-compatible
chat completion needs:
tools: one function tool per extension tool, named
ext_<slug>_<tool name>, with the tool’s description and its arguments model’s JSON schema;tool calls:
ExtensionToolkit.call()validates the LLM’s arguments, runs the tool with a timeout, and returns its result. Errors are returned to the LLM as{"error": ...}, so that it can recover, rather than failing the prompt.
An extension that is disabled, not available to the LLMClient’s account, or whose code does
not load, is skipped and reported in ExtensionToolkit.errors, so that one broken
extension does not fail the prompt.
- class smarter.apps.llmtool.extension.toolkit.ExtensionFunction(name, extension, loaded, tool)[source]
Bases:
objectA function tool offered to the LLM, and the extension tool it calls.
- __init__(name, extension, loaded, tool)
- loaded: LoadedExtension
- tool: type[SmarterExtensionTool]
- class smarter.apps.llmtool.extension.toolkit.ExtensionToolkit(extensions, account=None, user_profile=None, llmclient=None)[source]
Bases:
objectThe extension tools and tool call dispatch of one prompt.
- Parameters:
Example usage:
toolkit = ExtensionToolkit(LLMClientExtensions.extensions_for(llmclient), account=account).load() tools.extend(toolkit.tools) ... if toolkit.is_extension_function(tool_call.function.name): result = toolkit.call(tool_call.function.name, arguments)
- call(function_name, arguments=None)[source]
Run a tool call, and return its result for the LLM.
Errors, including invalid arguments, an exception and a timeout, are returned as
{"error": "..."}, so that the LLM can recover.
- function_name(slug, tool_name)[source]
Return a unique OpenAI function name for one of an extension’s tools.
The name is
ext_<slug>_<tool name>, with the slug’s hyphens replaced by underscores, and at most 64 characters long. If two tools would have the same name, a short hash is appended.
- is_extension_function(function_name)[source]
Return whether a function name is one of this toolkit’s tools.
- Return type: