类 ClasspathSkillRepository
java.lang.Object
io.agentscope.core.skill.repository.ClasspathSkillRepository
- 所有已实现的接口:
AgentSkillRepository,AutoCloseable
ClasspathSkillRepository - Loads skills from classpath resources and JAR files.
This repository bridges the gap between JAR resources and file system based skill loading by:
- Creating a virtual file system for resources within JAR files
- Obtaining Path objects for skill directories
- 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(String resourcePath) Creates a repository for loading skills from resources.protectedClasspathSkillRepository(String resourcePath, ClassLoader classLoader) Creates a repository for loading skills from resources using a specific ClassLoader.ClasspathSkillRepository(String resourcePath, String source) Creates a repository for loading skills from resources with a custom source.protectedClasspathSkillRepository(String resourcePath, String source, ClassLoader classLoader) Creates a repository for loading skills from resources using a specific ClassLoader. -
方法概要
修饰符和类型方法说明voidclose()Closes the file system (if in JAR environment).booleanDeletes a skill by its skill name.Gets all skill names available in the repository.Gets all skills available in the repository.Gets metadata about this repository.Gets a skill by name.Gets the source identifier of this repository.booleanChecks if running in a JAR environment.booleanChecks if the repository supports write operations.booleansave(List<AgentSkill> skills, boolean force) Saves or updates a skill in the repository.voidsetWriteable(boolean writeable) Sets the writeable flag for this repository.booleanskillExists(String skillName) Checks if a skill exists in the repository.
-
构造器详细资料
-
ClasspathSkillRepository
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
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
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
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
Gets all skill names available in the repository.- 指定者:
getAllSkillNames在接口中AgentSkillRepository- 返回:
- A sorted list of skill names
- 抛出:
IllegalStateException- if the repository has been closed
-
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
从接口复制的说明:AgentSkillRepositorySaves 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 saveforce- Whether to force save even if the skill already exists- 返回:
trueif save succeeded,falseotherwise
-
delete
从接口复制的说明:AgentSkillRepositoryDeletes a skill by its skill name.- 指定者:
delete在接口中AgentSkillRepository- 参数:
skillName- The skill name (never null)- 返回:
trueif deletion succeeded,falseif skill not found
-
skillExists
从接口复制的说明:AgentSkillRepositoryChecks if a skill exists in the repository.- 指定者:
skillExists在接口中AgentSkillRepository- 参数:
skillName- The skill name (never null)- 返回:
trueif the skill exists,falseotherwise
-
getRepositoryInfo
从接口复制的说明:AgentSkillRepositoryGets metadata about this repository.The information includes repository type, location, and other metadata.
- 指定者:
getRepositoryInfo在接口中AgentSkillRepository- 返回:
- Repository information (never null)
-
getSource
从接口复制的说明:AgentSkillRepositoryGets 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) 从接口复制的说明:AgentSkillRepositorySets the writeable flag for this repository.- 指定者:
setWriteable在接口中AgentSkillRepository- 参数:
writeable- Whether the repository supports write operations
-
isWriteable
public boolean isWriteable()从接口复制的说明:AgentSkillRepositoryChecks if the repository supports write operations.- 指定者:
isWriteable在接口中AgentSkillRepository- 返回:
trueif writable,falseotherwise
-
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
-