// Copyright (c) Microsoft. All rights reserved. using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Shared.DiagnosticIds; using Microsoft.Shared.Diagnostics; namespace Microsoft.Agents.AI; /// /// An discovered from a filesystem directory backed by a SKILL.md file. /// [Experimental(DiagnosticIds.Experiments.AgentsAIExperiments)] public sealed class AgentFileSkill : AgentSkill { private readonly IReadOnlyList _resources; private readonly IReadOnlyList _scripts; private readonly string _originalContent; private string? _content; /// /// Initializes a new instance of the class. /// /// The parsed frontmatter metadata for this skill. /// The full raw SKILL.md file content including YAML frontmatter. /// Absolute path to the directory containing this skill. /// Resources discovered for this skill. /// Scripts discovered for this skill. internal AgentFileSkill( AgentSkillFrontmatter frontmatter, string content, string path, IReadOnlyList? resources = null, IReadOnlyList? scripts = null) { this.Frontmatter = Throw.IfNull(frontmatter); this._originalContent = Throw.IfNull(content); this.Path = Throw.IfNullOrWhitespace(path); this._resources = resources ?? []; this._scripts = scripts ?? []; } /// public override AgentSkillFrontmatter Frontmatter { get; } /// /// /// Returns the raw SKILL.md content. When the skill has scripts, a /// <scripts><script name="..."><parameters_schema>...</parameters_schema></script></scripts> /// block is appended with a per-script entry describing the expected argument format. /// The result is cached after the first access. /// public override string Content { get => this._content ??= this._scripts is { Count: > 0 } ? this._originalContent + AgentInlineSkillContentBuilder.BuildScriptsBlock(this._scripts) : this._originalContent; } /// /// Gets the directory path where the skill was discovered. /// public string Path { get; } /// public override IReadOnlyList Resources => this._resources; /// public override IReadOnlyList Scripts => this._scripts; }