ToolsContainer
Last updated
Last updated
A tool container is essentially a class that houses the methods representing the tools (referred to as plugins in Semantic Kernel). This class does not need to extend any other class; it can simply be a Plain Old CLR Object (POCO) or extend any other class within an application.
However, if your tools class extends the class, it gains additional integration and context when used by an adapter. If you need to extend a pre-existing class in your code and still require this additional contextual integration, you can implement the IToolsContainer
interface instead of inheriting from ToolsContainer
.
Inheriting from ToolsContainer
provides the following additional features to your code:
Automatic service injection
Reference to the current
Reference to the utilizing the tools
collection to replace the placeholders in the tools' prompts
The Parameters collection is a particularly interesting feature, as it allows the tool to set the values of placeholders in its own prompts. This enables more dynamic tool implementations.
Below is the description of the . You will notice two placeholders that remain unresolved until the class instance is created and initialized. If the description were merely fixed text in a [Description] attribute, it would offer limited flexibility.
When inheriting from the ToolsContainer or implementing IToolsContainer, you have the flexibility to set parameters at any time before sending a request to the AI. You can do this as follows:
It can also replace parameters that are not directly related to the tool, as well as parameters used in the tool's description and all the arguments of the methods within the tools container.