类 AgentSkill

java.lang.Object
io.agentscope.core.skill.AgentSkill

public class AgentSkill extends Object
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();
 
另请参阅:
  • 构造器详细资料

    • 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 name and description. The metadata map is copied and stored as immutable.

      参数:
      metadata - Skill metadata including required name and description
      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 metadata is invalid or skillContent is null or empty
  • 方法详细资料

    • getName

      public String getName()
      Gets the skill name.
      返回:
      The skill name (never null)
    • getDescription

      public String getDescription()
      Gets the skill description.
      返回:
      The skill description (never null)
    • getMetadata

      public Map<String,Object> getMetadata()
      Gets the skill metadata.
      返回:
      The immutable metadata map (never null, may be empty except required fields)
    • getMetadataValue

      public Object getMetadataValue(String key)
      Gets a metadata value by key.
      参数:
      key - The metadata key
      返回:
      The metadata value, or null if not found
    • getSkillContent

      public String getSkillContent()
      Gets the skill content.

      This contains the actual skill implementation or instructions.

      返回:
      The skill content (never null)
    • getSource

      public String getSource()
      Gets the skill source identifier.
      返回:
      The source identifier (never null)
    • getResources

      public Map<String,String> getResources()
      Gets the skill resources.
      返回:
      The resources map (never null, may be empty)
    • getResource

      public String getResource(String resourcePath)
      Gets the resource content by path.
      参数:
      resourcePath - The resource path
      返回:
      The resource content, or null if not found
    • getResourcePaths

      public Set<String> getResourcePaths()
      Gets all resource paths for this skill.
      返回:
      Unmodifiable set of resource paths
    • getSkillId

      public String getSkillId()
      Gets a unique identifier for this skill.

      The ID is composed of name and source: "name_source".

      返回:
      Unique skill identifier (never null)
    • toBuilder

      public AgentSkill.Builder 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

      public static AgentSkill.Builder builder()
      Creates a new builder for creating a skill from scratch.
      返回:
      A new builder instance with empty fields
    • toString

      public String toString()
      Returns a string representation of this skill.
      覆盖:
      toString 在类中 Object
      返回:
      String representation including name, description, and source