Large Language Models (LLMs) are brilliant reasoning engines, but they live in a box. They can’t restart a server, check disk space, or query your internal APIs—unless you give them Plugins.
In this post, we’ll move beyond the basic “Hello World” examples and build a practical System Administration Plugin using Semantic Kernel.
The “Brain in a Jar” Problem#
Imagine hiring a brilliant sysadmin who is locked in a room with no computer. They can tell you how to fix a server, but they can’t actually do it.
Plugins bridge this gap. They act as the “hands” of the AI, allowing it to:
- Read State: Fetch real-time data (e.g., “Is the database healthy?”).
- Take Action: Execute commands (e.g., “Restart the IIS service”).
- Offload Logic: Perform deterministic calculations that LLMs often get wrong.
Building a “SysAdmin” Plugin#
Let’s build a plugin that allows an AI agent to monitor and manage servers. We’ll define two functions: one to check disk space and another to restart services.
1. Define the Plugin Class#
The core of a plugin is a standard C# class. We use the [KernelFunction] attribute to expose methods to the AI, and [Description] to tell the AI when and how to use them.
| |
2. Register and Run the Kernel#
Now we need to register this plugin with the Kernel and let the AI use it. Notice how we don’t explicitly call the functions; the AI decides to call them based on our prompt.
Prerequisites:
| |
The Code:
| |
Expected Output#
When you run this, the interaction happens in a loop (handled by AutoInvokeKernelFunctions):
- AI Thought: “I need to check disk space for DB-01.” -> Calls
GetDiskSpace("DB-01"). - Plugin Output: “5% free (CRITICAL)”.
- AI Thought: “The user said if it’s critical, restart ‘LogArchiver’.” -> Calls
RestartService("LogArchiver", "DB-01"). - Plugin Output: “Service ‘LogArchiver’ on ‘DB-01’ has been successfully restarted.”
- AI Final Response: “I checked DB-01 and found disk space was critical (5% free). As requested, I have restarted the ‘LogArchiver’ service.”
Best Practices for Plugins#
- Descriptive Names: The
[Description]attribute is your API documentation for the AI. Be verbose. If a parameter format matters (e.g., “YYYY-MM-DD”), say so in the description. - Keep it Deterministic: Plugins should ideally be reliable tools. If a plugin fails, ensure it returns a clear error message string so the AI can understand what went wrong and tell the user.
- Security First: Never expose dangerous functions (like
DeleteDatabase) without a “human in the loop” confirmation step. You can implement this by having the plugin return a “Confirmation required” message instead of executing immediately.
Pro Tip: Testing Your Plugins#
Because plugins are just C# classes, you can (and should) write standard unit tests for them! You don’t need the AI to test the logic inside GetDiskSpace. Test the deterministic code deterministically, and trust the Kernel to handle the routing.
By structuring your code as plugins, you transform your application from a text generator into an intelligent automation platform.
Further Reading#
- Semantic Kernel on GitHub - The official repository with examples
- Creating Semantic Kernel Plugins - Official documentation
- Function Calling in OpenAI - Understanding the underlying mechanism
