AgentSkill
public class AgentSkill
io/agentscope/core/skill/AgentSkill.java:68–536智能体技能,让智能体以受控方式调用外部能力。位于 io.agentscope.core.skill 包。核心成员包括 getName、getDescription、getMetadata、getMetadataValue、getSkillContent、getSource。
Represents an agent skill that can be loaded and used by agents.
A skill consists of:
-
Name and description - identifying the skill
-
Skill content - the actual skill implementation or instructions
-
Resources - supporting files or data referenced by the skill
-
Version and source - tracking skill origin and versioning
Creation options:
-
From markdown with YAML frontmatter - metadata extracted automatically
-
From explicit parameters - direct construction with all fields
-
From builder - for creating modified versions of existing skills
Usage examples:
`// From markdown with frontmatter (use SkillUtil)
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);
// Direct construction
AgentSkill skill2 = new AgentSkill("my_skill", "Does something", "Content here", resources);
// Create modified version using builder
AgentSkill modified = skill.toBuilder()
.description("Updated description")
.skillContent("Modified instructions")
.addResource("config.json", "{\"key\": \"value\"}")
.build();
`
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 Builder for creating AgentSkill instances. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public AgentSkill(String name, String description, String skillContent, Map<String, String> resources) | 初始化 `AgentSkill` 实例。 Creates an AgentSkill with explicit parameters. |
public AgentSkill(String name, String description, String skillContent, Map<String, String> resources, String source) | 初始化 `AgentSkill` 实例。 Creates an AgentSkill with explicit parameters and custom source. |
public AgentSkill(Map<String, Object> metadata, String skillContent, Map<String, String> resources, String source) | 初始化 `AgentSkill` 实例。 Creates an AgentSkill with explicit metadata. |
public AgentSkill(Map<String, Object> metadata, String skillContent, Map<String, String> resources, String source, Path originDir) | 初始化 `AgentSkill` 实例。 Creates an AgentSkill with explicit metadata and an on-disk origin directory. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String getName() | 获取技能名称。 Gets the skill name. |
public String getDescription() | 获取 `getDescription`。 Gets the skill description. |
public Map<String, Object> getMetadata() | 获取技能元数据。 Gets the skill metadata. |
public Object getMetadataValue(String key) | 获取元数据值通过密钥。 Gets a metadata value by key. |
public String getSkillContent() | 获取技能内容。 Gets the skill content. |
public String getSource() | 获取来源。 Gets the skill source identifier. |
public Map<String, String> getResources() | 获取 `getResources`。 Gets the skill resources. |
public String getResource(String resourcePath) | 获取资源内容通过路径。 Gets the resource content by path. |
public Set<String> getResourcePaths() | 获取 `getResourcePaths`。 Gets all resource paths for this skill. |
public String getSkillId() | 获取技能标识。 Gets a unique identifier for this skill. |
public Optional<Path> getOriginDir() | 获取来源目录。 Returns the absolute path to this skill's on-disk source directory, when available. |
public Builder toBuilder() | 创建构建器已初始化使用此技能's 值。 Creates a builder initialized with this skill's values. |
public static Builder builder()static | 返回构建器实例。 Creates a new builder for creating a skill from scratch. |
public String toString() | 返回 `toString` 结果。 Returns a string representation of this skill. |
构造器详情Constructor Detail
AgentSkill
public AgentSkill(String name, String description, String skillContent, Map<String, String> resources)
初始化 AgentSkill 实例。
Creates an AgentSkill with explicit parameters.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。Skill name (must not be null or empty) |
description | String | 描述(类型 `String`)。Skill description (must not be null or empty) |
skillContent | String | 技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty) |
resources | Map<String, String> | resources(类型 `Map`)。Supporting resources referenced by the skill (can be null) |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if name, description, or skillContent is null or empty
io/agentscope/core/skill/AgentSkill.java:94–97AgentSkill
public AgentSkill(String name, String description, String skillContent, Map<String, String> resources, String source)
初始化 AgentSkill 实例。
Creates an AgentSkill with explicit parameters and custom source.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。Skill name (must not be null or empty) |
description | String | 描述(类型 `String`)。Skill description (must not be null or empty) |
skillContent | String | 技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty) |
resources | Map<String, String> | resources(类型 `Map`)。Supporting resources referenced by the skill (can be null) |
source | String | 来源(类型 `String`)。Source identifier for the skill (null defaults to "custom") |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if name, description, or skillContent is null or empty
io/agentscope/core/skill/AgentSkill.java:112–119AgentSkill
public AgentSkill(Map<String, Object> metadata, String skillContent, Map<String, String> resources, String source)
初始化 AgentSkill 实例。
Creates an AgentSkill with explicit metadata.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
metadata | Map<String, Object> | 元数据(类型 `Map`)。Skill metadata including required `name` and `description` |
skillContent | String | 技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty) |
resources | Map<String, String> | resources(类型 `Map`)。Supporting resources referenced by the skill (can be null) |
source | String | 来源(类型 `String`)。Source identifier for the skill (null defaults to "custom") |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if metadata is invalid or skillContent is null or empty
io/agentscope/core/skill/AgentSkill.java:133–139AgentSkill
public AgentSkill(Map<String, Object> metadata, String skillContent, Map<String, String> resources, String source, Path originDir)
初始化 AgentSkill 实例。
Creates an AgentSkill with explicit metadata and an on-disk origin directory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
metadata | Map<String, Object> | 元数据(类型 `Map`)。Skill metadata including required `name` and `description` |
skillContent | String | 技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty) |
resources | Map<String, String> | resources(类型 `Map`)。Supporting resources referenced by the skill (can be null) |
source | String | 来源(类型 `String`)。Source identifier for the skill (null defaults to "custom") |
originDir | Path | 来源目录(类型 `Path`)。Absolute path to the skill's source directory, or `null` if not filesystem-backed (e.g. classpath / remote / synthetic). Stored as-is. |
IllegalArgumentException可能抛出 `IllegalArgumentException`。if metadata is invalid or skillContent is null or empty
io/agentscope/core/skill/AgentSkill.java:152–173方法详情Method Detail
getName
public String getName()
获取技能名称。
Gets the skill name.
Stringio/agentscope/core/skill/AgentSkill.java:180–182getDescription
public String getDescription()
获取 getDescription。
Gets the skill description.
Stringio/agentscope/core/skill/AgentSkill.java:189–191getMetadata
public Map<String, Object> getMetadata()
获取技能元数据。
Gets the skill metadata.
Map<String, Object>io/agentscope/core/skill/AgentSkill.java:198–200getMetadataValue
public Object getMetadataValue(String key)
获取元数据值通过密钥。
Gets a metadata value by key.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 元数据密钥。The metadata key |
Objectio/agentscope/core/skill/AgentSkill.java:208–210getSkillContent
public String getSkillContent()
获取技能内容。
Gets the skill content.
Stringio/agentscope/core/skill/AgentSkill.java:219–221getSource
public String getSource()
获取来源。
Gets the skill source identifier.
Stringio/agentscope/core/skill/AgentSkill.java:228–230getResources
public Map<String, String> getResources()
获取 getResources。
Gets the skill resources.
Map<String, String>io/agentscope/core/skill/AgentSkill.java:237–239getResource
public String getResource(String resourcePath)
获取资源内容通过路径。
Gets the resource content by path.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
resourcePath | String | 资源路径。The resource path |
Stringio/agentscope/core/skill/AgentSkill.java:247–249getResourcePaths
public Set<String> getResourcePaths()
获取 getResourcePaths。
Gets all resource paths for this skill.
Set<String>io/agentscope/core/skill/AgentSkill.java:256–258getSkillId
public String getSkillId()
获取技能标识。
Gets a unique identifier for this skill.
Stringio/agentscope/core/skill/AgentSkill.java:267–269getOriginDir
public Optional<Path> getOriginDir()
获取来源目录。
Returns the absolute path to this skill's on-disk source directory, when available.
Optional<Path>io/agentscope/core/skill/AgentSkill.java:278–280toBuilder
public Builder toBuilder()
创建构建器已初始化使用此技能's 值。
Creates a builder initialized with this skill's values.
Builderio/agentscope/core/skill/AgentSkill.java:289–291builder
public static Builder builder()
返回构建器实例。
Creates a new builder for creating a skill from scratch.
Builderio/agentscope/core/skill/AgentSkill.java:298–300toString
public String toString()
返回 toString 结果。
Returns a string representation of this skill.
Stringio/agentscope/core/skill/AgentSkill.java:307–316嵌套类详情Nested Class Detail
Builder
public static class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.core.skill 包。核心成员包括 name、description、metadata、putMetadata、removeMetadata、skillContent。
Builder for creating AgentSkill instances.
This builder allows selective modification of skill fields to create new skill instances based on existing ones, or to create new skills from scratch.
Usage examples:
`// Create from scratch
AgentSkill skill = AgentSkill.builder()
.name("my_skill")
.description("Does something")
.skillContent("Instructions here")
.addResource("file.txt", "content")
.build();
// Modify existing skill
AgentSkill modified = existingSkill.toBuilder()
.description("Updated description")
.addResource("new_file.txt", "new content")
.build();
`