类 ClasspathSkillRepository

java.lang.Object
io.agentscope.core.skill.repository.ClasspathSkillRepository
所有已实现的接口:
AgentSkillRepository, AutoCloseable

public class ClasspathSkillRepository extends Object implements AgentSkillRepository
ClasspathSkillRepository - Loads skills from classpath resources and JAR files.

This repository bridges the gap between JAR resources and file system based skill loading by:

  1. Creating a virtual file system for resources within JAR files
  2. Obtaining Path objects for skill directories
  3. Delegating skill I/O to SkillFileSystemHelper

Important: Skills must be organized in a parent directory structure. You should pass the parent directory name (not individual skill paths). This is required because the repository scans a directory for multiple skill subdirectories.

Directory Structure:

 resources/
 └── skills/              ← Pass "skills" to repository
     ├── skill-a/
     │   └── SKILL.md
     ├── skill-b/
     │   └── SKILL.md
     └── skill-c/
         └── SKILL.md
 

Usage example:


 // Load from parent directory containing multiple skills
 try (ClasspathSkillRepository repository = new ClasspathSkillRepository("skills")) {
     // Get all available skill names
     List<String> skillNames = repository.getAllSkillNames();

     // Load a specific skill
     AgentSkill skillA = repository.getSkill("skill-a");

     // Load all skills at once
     List<AgentSkill> allSkills = repository.getAllSkills();
 }
 
  • 构造器详细资料

    • ClasspathSkillRepository

      public ClasspathSkillRepository(String resourcePath) throws IOException
      Creates a repository for loading skills from resources.
      参数:
      resourcePath - The path to the skill under resources, e.g., "writing-skills"
      抛出:
      IOException - if initialization fails
    • ClasspathSkillRepository

      public ClasspathSkillRepository(String resourcePath, String source) throws IOException
      Creates a repository for loading skills from resources with a custom source.
      参数:
      resourcePath - The path to the skill under resources, e.g., "writing-skills"
      source - The custom source identifier (null to use default)
      抛出:
      IOException - if initialization fails
    • ClasspathSkillRepository

      protected ClasspathSkillRepository(String resourcePath, ClassLoader classLoader) throws IOException
      Creates a repository for loading skills from resources using a specific ClassLoader.
      参数:
      resourcePath - The path to the skill under resources, e.g., "writing-skills"
      classLoader - The ClassLoader to use for loading resources
      抛出:
      IOException - if initialization fails
    • ClasspathSkillRepository

      protected ClasspathSkillRepository(String resourcePath, String source, ClassLoader classLoader) throws IOException
      Creates a repository for loading skills from resources using a specific ClassLoader.
      参数:
      resourcePath - The path to the skill under resources, e.g., "writing-skills"
      source - The custom source identifier (null to use default)
      classLoader - The ClassLoader to use for loading resources
      抛出:
      IOException - if initialization fails
  • 方法详细资料

    • getSkill

      public AgentSkill getSkill(String skillName)
      Gets a skill by name.
      指定者:
      getSkill 在接口中 AgentSkillRepository
      参数:
      skillName - The skill name (from SKILL.md metadata)
      返回:
      The loaded AgentSkill object
      抛出:
      IllegalStateException - if the repository has been closed
    • getAllSkillNames

      public List<String> getAllSkillNames()
      Gets all skill names available in the repository.
      指定者:
      getAllSkillNames 在接口中 AgentSkillRepository
      返回:
      A sorted list of skill names
      抛出:
      IllegalStateException - if the repository has been closed
    • getAllSkills

      public List<AgentSkill> getAllSkills()
      Gets all skills available in the repository.
      指定者:
      getAllSkills 在接口中 AgentSkillRepository
      返回:
      A list of all loaded AgentSkill objects
      抛出:
      IllegalStateException - if the repository has been closed
    • save

      public boolean save(List<AgentSkill> skills, boolean force)
      从接口复制的说明: AgentSkillRepository
      Saves or updates a skill in the repository.

      If a skill with the same name exists, it will be updated. Otherwise, a new skill will be created.

      If the skills list is empty, return false.

      指定者:
      save 在接口中 AgentSkillRepository
      参数:
      skills - The skills to save
      force - Whether to force save even if the skill already exists
      返回:
      true if save succeeded, false otherwise
    • delete

      public boolean delete(String skillName)
      从接口复制的说明: AgentSkillRepository
      Deletes a skill by its skill name.
      指定者:
      delete 在接口中 AgentSkillRepository
      参数:
      skillName - The skill name (never null)
      返回:
      true if deletion succeeded, false if skill not found
    • skillExists

      public boolean skillExists(String skillName)
      从接口复制的说明: AgentSkillRepository
      Checks if a skill exists in the repository.
      指定者:
      skillExists 在接口中 AgentSkillRepository
      参数:
      skillName - The skill name (never null)
      返回:
      true if the skill exists, false otherwise
    • getRepositoryInfo

      public AgentSkillRepositoryInfo getRepositoryInfo()
      从接口复制的说明: AgentSkillRepository
      Gets metadata about this repository.

      The information includes repository type, location, and other metadata.

      指定者:
      getRepositoryInfo 在接口中 AgentSkillRepository
      返回:
      Repository information (never null)
    • getSource

      public String getSource()
      从接口复制的说明: AgentSkillRepository
      Gets the source identifier of this repository.

      The source follows the format repositoryType_location.

      指定者:
      getSource 在接口中 AgentSkillRepository
      返回:
      The source identifier (never null)
    • setWriteable

      public void setWriteable(boolean writeable)
      从接口复制的说明: AgentSkillRepository
      Sets the writeable flag for this repository.
      指定者:
      setWriteable 在接口中 AgentSkillRepository
      参数:
      writeable - Whether the repository supports write operations
    • isWriteable

      public boolean isWriteable()
      从接口复制的说明: AgentSkillRepository
      Checks if the repository supports write operations.
      指定者:
      isWriteable 在接口中 AgentSkillRepository
      返回:
      true if writable, false otherwise
    • isJarEnvironment

      public boolean isJarEnvironment()
      Checks if running in a JAR environment.
      返回:
      true if running from JAR, false if in development environment
    • close

      public void close()
      Closes the file system (if in JAR environment).

      This method is idempotent - it can be safely called multiple times. Designed for use with try-with-resources.

      指定者:
      close 在接口中 AgentSkillRepository
      指定者:
      close 在接口中 AutoCloseable