AgentClassSkill<TSelf> Class

Definition

Abstract base class for defining skills as C# classes that bundle all components together.

public abstract class AgentClassSkill<TSelf> : Microsoft.Agents.AI.AgentSkill where TSelf : AgentClassSkill<TSelf>
type AgentClassSkill<'Self (requires 'Self :> AgentClassSkill<'Self>)> = class
    inherit AgentSkill
Public MustInherit Class AgentClassSkill(Of TSelf)
Inherits AgentSkill

Type Parameters

TSelf

The concrete skill type. This type parameter is annotated with DynamicallyAccessedMembersAttribute to ensure that the IL trimmer and Native AOT compiler preserve the members needed for attribute-based discovery.

Inheritance
AgentClassSkill<TSelf>

Examples

// Attribute-based approach (recommended, AOT-compatible):
public class PdfFormatterSkill : AgentClassSkill<PdfFormatterSkill>
{
    public override AgentSkillFrontmatter Frontmatter { get; } = new("pdf-formatter", "Format documents as PDF.");
    protected override string Instructions => "Use this skill to format documents...";

    [AgentSkillResource("template")]
    public string Template => "Use this template...";

    [AgentSkillScript("format-pdf")]
    private static string FormatPdf(string content) => content;
}

// Explicit override approach (AOT-compatible):
public class ExplicitPdfFormatterSkill : AgentClassSkill<ExplicitPdfFormatterSkill>
{
    private IReadOnlyList<AgentSkillResource>? _resources;
    private IReadOnlyList<AgentSkillScript>? _scripts;

    public override AgentSkillFrontmatter Frontmatter { get; } = new("pdf-formatter", "Format documents as PDF.");
    protected override string Instructions => "Use this skill to format documents...";

    public override IReadOnlyList<AgentSkillResource>? Resources => this._resources ??=
    [
        CreateResource("template", "Use this template..."),
    ];

    public override IReadOnlyList<AgentSkillScript>? Scripts => this._scripts ??=
    [
        CreateScript("format-pdf", FormatPdf),
    ];

    private static string FormatPdf(string content) => content;
}

Remarks

Inherit from this class to create a self-contained skill definition. Override the abstract properties to provide name, description, and instructions.

Scripts and resources can be defined in two ways:

Multi-level inheritance limitation: Discovery reflects only on TSelf, so if a further-derived subclass adds new attributed members, they will not be discovered unless that subclass also uses the CRTP pattern (e.g., class SpecialSkill : AgentClassSkill<SpecialSkill>).

Constructors

Name Description
AgentClassSkill<TSelf>(Func<Nullable<JsonElement>,AIFunctionArguments>)

Initializes a new instance of the AgentClassSkill<TSelf> class.

Properties

Name Description
Frontmatter

Gets the frontmatter metadata for this skill.

(Inherited from AgentSkill)
Instructions

Gets the raw instructions text for this skill.

Resources

Gets the resources associated with this skill, or null if none.

Scripts

Gets the scripts associated with this skill, or null if none.

SerializerOptions

Gets the JsonSerializerOptions used to marshal parameters and return values for scripts and resources.

Methods

Name Description
CreateResource(String, Delegate, String, JsonSerializerOptions)

Creates a skill resource backed by a delegate that produces a dynamic value.

CreateResource(String, Object, String)

Creates a skill resource backed by a static value.

CreateScript(String, Delegate, String, JsonSerializerOptions)

Creates a skill script backed by a delegate.

GetContentAsync(CancellationToken)

Gets the full skill content.

GetResourceAsync(String, CancellationToken)

Gets a resource owned by this skill by name.

GetScriptAsync(String, CancellationToken)

Gets a script owned by this skill by name.

Applies to