Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Microsoft Semantic kernel Native Plugin Definition

From Leeroopedia
Knowledge Sources
Domains AI_Orchestration, Plugin_Architecture, Function_Calling
Last Updated 2026-02-11 19:00 GMT

Overview

Declarative function exposure through attribute-based metadata enables AI models to discover and invoke native methods as callable tools.

Description

Native Plugin Definition is the principle of transforming ordinary class methods into AI-discoverable functions through declarative metadata annotations. Instead of requiring developers to write boilerplate registration code or schema definitions, the framework uses attributes applied directly to classes, methods, and parameters to automatically generate the function metadata that AI models need to understand what tools are available and how to call them.

The core mechanism relies on two primary attributes: [KernelFunction] marks a method as eligible for exposure to the AI model, and [Description("...")] provides human-readable (and AI-readable) descriptions of classes, methods, and parameters. Together, these attributes form a complete declarative contract that the framework uses to generate JSON schema descriptions for the AI model's function calling interface.

This attribute-driven approach provides several key benefits. First, the function's code and its AI-facing contract live in the same location, reducing the risk of documentation drift. Second, the framework can use reflection to automatically discover all annotated methods at registration time, eliminating manual mapping. Third, parameter types (including enums, arrays, and complex objects) are automatically serialized into JSON schema representations, allowing the AI model to understand the shape of expected inputs.

The principle extends to enum types and complex parameters as well. Enum values decorated with [Description] attributes provide the AI model with semantic context about each possible value, enabling more accurate tool use. Array parameters allow the model to pass collections of values in a single invocation.

Usage

Use native plugin definition whenever you need to expose C# functionality to an AI model for function calling. This applies to any scenario where the AI should be able to autonomously decide to call your code, from simple utility functions (time, math) to complex business operations (creating records, querying databases, calling external services). Each plugin class should represent a cohesive group of related functions, and every exposed method should have clear descriptions on both the method and its parameters to maximize the AI model's ability to select and invoke functions correctly.

Theoretical Basis

Native Plugin Definition implements the Adapter Pattern combined with the Metadata-Driven Configuration pattern. The adapter aspect transforms arbitrary C# methods into a standardized function-calling interface that AI models can consume. The metadata-driven aspect uses declarative attributes rather than imperative code to define the adaptation rules.

Formal model:

Given a class C with methods m1, m2, ..., mn, the framework applies a discovery function D that filters methods based on attribute presence:

D(C) = { mi | mi in methods(C) AND has_attribute(mi, [KernelFunction]) }

For each discovered method mi, a schema generation function S produces a JSON schema from the method's signature and attribute metadata:

S(mi) = {
  name: attribute_name(mi) ?? method_name(mi),
  description: description_attribute(mi),
  parameters: [ { name: pj, type: json_type(pj), description: description_attribute(pj) } for pj in params(mi) ]
}

The key invariants are:

  • Completeness: Every method annotated with [KernelFunction] is included; no un-annotated methods are exposed.
  • Description quality: The quality of [Description] attributes directly impacts the AI model's ability to select the correct function and supply correct arguments.
  • Type fidelity: C# types are mapped to JSON schema types preserving semantic meaning (enums become string enums with descriptions, arrays become JSON arrays, etc.).
  • Uniqueness: All [KernelFunction] methods within a plugin must have unique names; method overloading is not supported.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment