ClasspathSkillRepository
public class ClasspathSkillRepository implements AgentSkillRepository
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:78–368Classpath 技能仓库,负责持久化与读取数据。位于 io.agentscope.core.skill.repository 包,实现 AgentSkillRepository。核心成员包括 getSkill、getAllSkillNames、getAllSkills、save、delete、skillExists。
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();
}
`
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ClasspathSkillRepository(String resourcePath) throws IOException | 初始化 `ClasspathSkillRepository` 实例。 Creates a repository for loading skills from resources. |
public ClasspathSkillRepository(String resourcePath, String source) throws IOException | 初始化 `ClasspathSkillRepository` 实例。 Creates a repository for loading skills from resources with a custom source. |
protected ClasspathSkillRepository(String resourcePath, ClassLoader classLoader) throws IOException | 初始化 `ClasspathSkillRepository` 实例。 Creates a repository for loading skills from resources using a specific ClassLoader. |
protected ClasspathSkillRepository(String resourcePath, String source, ClassLoader classLoader) throws IOException | 初始化 `ClasspathSkillRepository` 实例。 Creates a repository for loading skills from resources using a specific ClassLoader. |
方法摘要Method Summary
构造器详情Constructor Detail
ClasspathSkillRepository
public ClasspathSkillRepository(String resourcePath) throws IOException
初始化 ClasspathSkillRepository 实例。
Creates a repository for loading skills from resources.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
resourcePath | String | 资源路径(类型 `String`)。The path to the skill under resources, e.g., "writing-skills" |
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:100–102ClasspathSkillRepository
public ClasspathSkillRepository(String resourcePath, String source) throws IOException
初始化 ClasspathSkillRepository 实例。
Creates a repository for loading skills from resources with a custom source.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
resourcePath | String | 资源路径(类型 `String`)。The path to the skill under resources, e.g., "writing-skills" |
source | String | 来源(类型 `String`)。The custom source identifier (null to use default) |
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:111–113ClasspathSkillRepository
protected ClasspathSkillRepository(String resourcePath, ClassLoader classLoader) throws IOException
初始化 ClasspathSkillRepository 实例。
Creates a repository for loading skills from resources using a specific ClassLoader.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
resourcePath | String | 资源路径(类型 `String`)。The path to the skill under resources, e.g., "writing-skills" |
classLoader | ClassLoader | 类加载器(类型 `ClassLoader`)。The ClassLoader to use for loading resources |
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:122–125ClasspathSkillRepository
protected ClasspathSkillRepository(String resourcePath, String source, ClassLoader classLoader) throws IOException
初始化 ClasspathSkillRepository 实例。
Creates a repository for loading skills from resources using a specific ClassLoader.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
resourcePath | String | 资源路径(类型 `String`)。The path to the skill under resources, e.g., "writing-skills" |
source | String | 来源(类型 `String`)。The custom source identifier (null to use default) |
classLoader | ClassLoader | 类加载器(类型 `ClassLoader`)。The ClassLoader to use for loading resources |
IOException可能抛出 `IOException`。Thrown when the operation cannot be completed.
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:135–169方法详情Method Detail
getSkill
public AgentSkill getSkill(String skillName)
获取技能通过名称。
Gets a skill by name.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skillName | String | 技能名称(来自技能.md 元数据)。The skill name (from SKILL.md metadata) |
AgentSkillIllegalStateException可能抛出 `IllegalStateException`。if the repository has been closed
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:178–182getAllSkillNames
public List<String> getAllSkillNames()
获取 getAllSkillNames。
Gets all skill names available in the repository.
List<String>IllegalStateException可能抛出 `IllegalStateException`。if the repository has been closed
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:190–194getAllSkills
public List<AgentSkill> getAllSkills()
获取所有技能可用 in 仓库。
Gets all skills available in the repository.
List<AgentSkill>IllegalStateException可能抛出 `IllegalStateException`。if the repository has been closed
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:202–206save
public boolean save(List<AgentSkill> skills, boolean force)
保存数据到持久化存储。
Performs the save operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skills | List<AgentSkill> | 技能(类型 `List`)。The skills. |
force | boolean | force(类型 `boolean`)。The force. |
booleanio/agentscope/core/skill/repository/ClasspathSkillRepository.java:208–212delete
public boolean delete(String skillName)
删除数据。
Performs the delete operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skillName | String | 技能名称(类型 `String`)。The skill name. |
booleanio/agentscope/core/skill/repository/ClasspathSkillRepository.java:214–218skillExists
public boolean skillExists(String skillName)
设置该参数。
Performs the skill exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
skillName | String | 技能名称(类型 `String`)。The skill name. |
booleanio/agentscope/core/skill/repository/ClasspathSkillRepository.java:220–224getRepositoryInfo
public AgentSkillRepositoryInfo getRepositoryInfo()
获取仓库信息。
Returns the repository info.
AgentSkillRepositoryInfoio/agentscope/core/skill/repository/ClasspathSkillRepository.java:226–229getSource
public String getSource()
获取来源。
Returns the source.
Stringio/agentscope/core/skill/repository/ClasspathSkillRepository.java:231–234setWriteable
public void setWriteable(boolean writeable)
设置 setWriteable。
Sets the writeable.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
writeable | boolean | writeable(类型 `boolean`)。The writeable. |
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:260–263isWriteable
public boolean isWriteable()
判断是否 isWriteable。
Returns whether the writeable.
booleanio/agentscope/core/skill/repository/ClasspathSkillRepository.java:265–268isJarEnvironment
public boolean isJarEnvironment()
检查if 运行中,使用 JAR 环境。
Checks if running in a JAR environment.
booleanio/agentscope/core/skill/repository/ClasspathSkillRepository.java:275–277close
public void close()
关闭连接并释放相关资源。
Closes the file system (if in JAR environment).
io/agentscope/core/skill/repository/ClasspathSkillRepository.java:343–355