Module 5 — Plugins: exposing .NET code to the model
Prompt & Tool Design for .NET Teams · Part 2 — Semantic Kernel in .NET · Module 5 of 12
In Semantic Kernel (SK), a “plugin” is a class with a couple of attributes on it. That’s the entire trick. The tool contract you argued over in Module 3 becomes an ordinary C# method, and the description you wrote becomes the thing the model actually reads.
Objective
Turn the tool contract from Module 3 into a real, callable C# function the model can invoke.
Read (~8 min)
- The Semantic Kernel plugins concept.
- The MS Learn module Create plugins for Semantic Kernel (learning path APL-2005) — skim the C# units.
Lab (~22 min)
Implement your Module 3 contract as a plugin. Our running example is a comic finder — it returns a programming comic from sites like xkcd, CommitStrip, MonkeyUser, Geek & Poke, or Work Chronicles:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System.ComponentModel;
using Microsoft.SemanticKernel;
public class ComicPlugin
{
[KernelFunction("find_comic")]
[Description("Finds a programming or tech comic for a given topic. "
+ "Use when the user wants a comic, a laugh, or a cartoon about a software concept.")]
public Task<string> FindComicAsync(
[Description("Topic or keyword, e.g. \"git\" or \"deadlines\"")] string topic)
=> Task.FromResult(
$$"""
{"topic":"","title":"Git","url":"https://xkcd.com/1597/","source":"xkcd"}
""");
}
Register it with the kernel:
1
kernel.Plugins.AddFromType<ComicPlugin>();
Stub the data — a hard-coded comic link is fine. Wiring up a real comic search is a solved problem and, frankly, a productivity hazard; the contract is the point. (Note the $$"""...""" raw interpolated string: doubled braces escape the literal JSON, and the single `` is the value. It saves you a fight with backslashes.)
Done when
The [Description] attributes are word-for-word the descriptions you peer-reviewed in Module 3, and your reviewer signs off on them a second time. If the wording drifted, the model is now reading something nobody reviewed.