类 AgentSkill
java.lang.Object
io.agentscope.core.skill.AgentSkill
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();
- 另请参阅:
-
嵌套类概要
嵌套类 -
构造器概要
构造器构造器说明Creates an AgentSkill with explicit parameters.AgentSkill(String name, String description, String skillContent, Map<String, String> resources, String source) Creates an AgentSkill with explicit parameters and custom source.AgentSkill(Map<String, Object> metadata, String skillContent, Map<String, String> resources, String source) Creates an AgentSkill with explicit metadata. -
方法概要
修饰符和类型方法说明static AgentSkill.Builderbuilder()Creates a new builder for creating a skill from scratch.Gets the skill description.Gets the skill metadata.getMetadataValue(String key) Gets a metadata value by key.getName()Gets the skill name.getResource(String resourcePath) Gets the resource content by path.Gets all resource paths for this skill.Gets the skill resources.Gets the skill content.Gets a unique identifier for this skill.Gets the skill source identifier.Creates a builder initialized with this skill's values.toString()Returns a string representation of this skill.
-
构造器详细资料
-
AgentSkill
public AgentSkill(String name, String description, String skillContent, Map<String, String> resources) Creates an AgentSkill with explicit parameters.Use this constructor when you want to create a skill directly without parsing markdown. Uses "custom" as the default source.
- 参数:
name- Skill name (must not be null or empty)description- Skill description (must not be null or empty)skillContent- The skill implementation or instructions (must not be null or empty)resources- Supporting resources referenced by the skill (can be null)- 抛出:
IllegalArgumentException- if name, description, or skillContent is null or empty
-
AgentSkill
public AgentSkill(String name, String description, String skillContent, Map<String, String> resources, String source) Creates an AgentSkill with explicit parameters and custom source.Use this constructor when you want to create a skill directly without parsing markdown. The source parameter indicates where the skill originated from.
- 参数:
name- Skill name (must not be null or empty)description- Skill description (must not be null or empty)skillContent- The skill implementation or instructions (must not be null or empty)resources- Supporting resources referenced by the skill (can be null)source- Source identifier for the skill (null defaults to "custom")- 抛出:
IllegalArgumentException- if name, description, or skillContent is null or empty
-
AgentSkill
public AgentSkill(Map<String, Object> metadata, String skillContent, Map<String, String> resources, String source) Creates an AgentSkill with explicit metadata.The metadata must include non-empty string values for
nameanddescription. The metadata map is copied and stored as immutable.- 参数:
metadata- Skill metadata including requirednameanddescriptionskillContent- The skill implementation or instructions (must not be null or empty)resources- Supporting resources referenced by the skill (can be null)source- Source identifier for the skill (null defaults to "custom")- 抛出:
IllegalArgumentException- if metadata is invalid or skillContent is null or empty
-
-
方法详细资料
-
getName
Gets the skill name.- 返回:
- The skill name (never null)
-
getDescription
Gets the skill description.- 返回:
- The skill description (never null)
-
getMetadata
Gets the skill metadata.- 返回:
- The immutable metadata map (never null, may be empty except required fields)
-
getMetadataValue
Gets a metadata value by key.- 参数:
key- The metadata key- 返回:
- The metadata value, or null if not found
-
getSkillContent
Gets the skill content.This contains the actual skill implementation or instructions.
- 返回:
- The skill content (never null)
-
getSource
Gets the skill source identifier.- 返回:
- The source identifier (never null)
-
getResources
Gets the skill resources.- 返回:
- The resources map (never null, may be empty)
-
getResource
Gets the resource content by path.- 参数:
resourcePath- The resource path- 返回:
- The resource content, or null if not found
-
getResourcePaths
Gets all resource paths for this skill.- 返回:
- Unmodifiable set of resource paths
-
getSkillId
Gets a unique identifier for this skill.The ID is composed of name and source: "name_source".
- 返回:
- Unique skill identifier (never null)
-
toBuilder
Creates a builder initialized with this skill's values.This is useful for creating modified versions of existing skills.
- 返回:
- A new builder instance
-
builder
Creates a new builder for creating a skill from scratch.- 返回:
- A new builder instance with empty fields
-
toString
Returns a string representation of this skill.
-