类 SkillUtil

java.lang.Object
io.agentscope.core.skill.util.SkillUtil

public class SkillUtil extends Object
Utility class for creating AgentSkill instances.

This class provides factory methods to create AgentSkill objects from various sources, particularly from markdown content with YAML frontmatter.

Usage example:


 // Create skill from markdown with default source
 String skillMd = "---\nname: my_skill\ndescription: Does something\n---\nContent here";
 Map<String, String> resources = Map.of("file1.txt", "content1");
 AgentSkill skill = SkillUtil.createFrom(skillMd, resources);

 // Create skill from markdown with custom source
 AgentSkill skill2 = SkillUtil.createFrom(skillMd, resources, "github");
 
  • 方法详细资料

    • createFrom

      public static AgentSkill createFrom(String skillMd, Map<String,String> resources)
      Creates an AgentSkill from markdown with YAML frontmatter.

      Parses the markdown to extract metadata (name, description) from YAML frontmatter and content. Uses "custom" as the default source.

      参数:
      skillMd - Markdown content with YAML frontmatter containing name and description
      resources - Supporting resources referenced by the skill (can be null)
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if name or description is missing, or if content is empty
    • createFrom

      public static AgentSkill createFrom(String skillMd, Map<String,String> resources, String source)
      Creates an AgentSkill from markdown with YAML frontmatter and custom source.

      Parses the markdown to extract metadata (name, description) from YAML frontmatter and content. The source parameter indicates where the skill originated from.

      参数:
      skillMd - Markdown content with YAML frontmatter containing name and description
      resources - Supporting resources referenced by the skill (can be null)
      source - Source identifier for the skill (null defaults to "custom")
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if name or description is missing, or if content is empty
    • createFromZip

      public static AgentSkill createFromZip(byte[] zipBytes)
      Creates an AgentSkill from a skill package zip.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipBytes - Zip content as bytes
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipBytes is null/empty, if no SKILL.md is found, or if zip entries are invalid
    • createFromZip

      public static AgentSkill createFromZip(Path zipPath)
      Creates an AgentSkill from a skill package zip file path.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipPath - Zip file path
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipPath is null
      RuntimeException - if the zip file cannot be read
    • createFromZip

      public static AgentSkill createFromZip(Path zipPath, Charset charset)
      Creates an AgentSkill from a skill package zip file path using the given charset.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipPath - Zip file path
      charset - Charset used to decode zip entry names and file contents (null defaults to UTF-8). Use this when the zip was created with a non-UTF-8 charset such as GBK/GB18030 and the default overload fails during zip entry decoding with errors like malformed input
      返回:
      Created AgentSkill instance
    • createFromZip

      public static AgentSkill createFromZip(InputStream zipStream)
      Creates an AgentSkill from a skill package zip input stream.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipStream - Zip content stream
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipStream is null
    • createFromZip

      public static AgentSkill createFromZip(byte[] zipBytes, String source)
      Creates an AgentSkill from a skill package zip with custom source.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipBytes - Zip content as bytes
      source - Source identifier for the skill (null defaults to "custom")
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipBytes is null/empty, if no SKILL.md is found, or if zip entries are invalid
    • createFromZip

      public static AgentSkill createFromZip(byte[] zipBytes, String source, Charset charset)
      Creates an AgentSkill from a skill package zip with custom source and charset.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipBytes - Zip content as bytes
      source - Source identifier for the skill (null defaults to "custom")
      charset - Charset used to decode zip entry names and file contents (null defaults to UTF-8). Use this when the zip was created with a non-UTF-8 charset such as GBK/GB18030 and the default overload fails during zip entry decoding with errors like malformed input
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipBytes is null/empty, if no SKILL.md is found, or if zip entries are invalid
    • createFromZip

      public static AgentSkill createFromZip(Path zipPath, String source)
      Creates an AgentSkill from a skill package zip file path with custom source.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipPath - Zip file path
      source - Source identifier for the skill (null defaults to "custom")
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipPath is null
      RuntimeException - if the zip file cannot be read
    • createFromZip

      public static AgentSkill createFromZip(Path zipPath, String source, Charset charset)
      Creates an AgentSkill from a skill package zip file path with custom source and charset.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipPath - Zip file path
      source - Source identifier for the skill (null defaults to "custom")
      charset - Charset used to decode zip entry names and file contents (null defaults to UTF-8). Use this when the zip was created with a non-UTF-8 charset such as GBK/GB18030 and the default overload fails during zip entry decoding with errors like malformed input
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipPath is null
      RuntimeException - if the zip file cannot be read
    • createFromZip

      public static AgentSkill createFromZip(InputStream zipStream, String source)
      Creates an AgentSkill from a skill package zip input stream with custom source.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipStream - Zip content stream
      source - Source identifier for the skill (null defaults to "custom")
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipStream is null
      RuntimeException - if the zip content cannot be read
    • createFromZip

      public static AgentSkill createFromZip(InputStream zipStream, String source, Charset charset)
      Creates an AgentSkill from a skill package zip input stream with custom source and charset.

      The package must contain a "SKILL.md" entry and any optional resource files. The .skill and .zip extensions are aliases for the same package format.

      参数:
      zipStream - Zip content stream
      source - Source identifier for the skill (null defaults to "custom")
      charset - Charset used to decode zip entry names and file contents (null defaults to UTF-8). Use this when the zip was created with a non-UTF-8 charset such as GBK/GB18030 and the default overload fails during zip entry decoding with errors like malformed input
      返回:
      Created AgentSkill instance
      抛出:
      IllegalArgumentException - if zipStream is null
      RuntimeException - if the zip content cannot be read