AS AgentScopeAPI 手册 / API Reference

AgentSkill

public class AgentSkill
源码Source 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.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。Skill name (must not be null or empty)
descriptionString描述(类型 `String`)。Skill description (must not be null or empty)
skillContentString技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty)
resourcesMap<String, String>resources(类型 `Map`)。Supporting resources referenced by the skill (can be null)
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if name, description, or skillContent is null or empty
源码Source io/agentscope/core/skill/AgentSkill.java:94–97

AgentSkill

public AgentSkill(String name, String description, String skillContent, Map<String, String> resources, String source)

初始化 AgentSkill 实例。

Creates an AgentSkill with explicit parameters and custom source.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。Skill name (must not be null or empty)
descriptionString描述(类型 `String`)。Skill description (must not be null or empty)
skillContentString技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty)
resourcesMap<String, String>resources(类型 `Map`)。Supporting resources referenced by the skill (can be null)
sourceString来源(类型 `String`)。Source identifier for the skill (null defaults to "custom")
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if name, description, or skillContent is null or empty
源码Source io/agentscope/core/skill/AgentSkill.java:112–119

AgentSkill

public AgentSkill(Map<String, Object> metadata, String skillContent, Map<String, String> resources, String source)

初始化 AgentSkill 实例。

Creates an AgentSkill with explicit metadata.

参数Parameters
名称Name类型Type说明Description
metadataMap<String, Object>元数据(类型 `Map`)。Skill metadata including required `name` and `description`
skillContentString技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty)
resourcesMap<String, String>resources(类型 `Map`)。Supporting resources referenced by the skill (can be null)
sourceString来源(类型 `String`)。Source identifier for the skill (null defaults to "custom")
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if metadata is invalid or skillContent is null or empty
源码Source io/agentscope/core/skill/AgentSkill.java:133–139

AgentSkill

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.

参数Parameters
名称Name类型Type说明Description
metadataMap<String, Object>元数据(类型 `Map`)。Skill metadata including required `name` and `description`
skillContentString技能内容(类型 `String`)。The skill implementation or instructions (must not be null or empty)
resourcesMap<String, String>resources(类型 `Map`)。Supporting resources referenced by the skill (can be null)
sourceString来源(类型 `String`)。Source identifier for the skill (null defaults to "custom")
originDirPath来源目录(类型 `Path`)。Absolute path to the skill's source directory, or `null` if not filesystem-backed (e.g. classpath / remote / synthetic). Stored as-is.
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if metadata is invalid or skillContent is null or empty
源码Source io/agentscope/core/skill/AgentSkill.java:152–173

方法详情Method Detail

getName

public String getName()

获取技能名称。

Gets the skill name.

返回Returns String
返回字符串结果。The skill name (never null)
源码Source io/agentscope/core/skill/AgentSkill.java:180–182

getDescription

public String getDescription()

获取 getDescription。

Gets the skill description.

返回Returns String
返回字符串结果。The skill description (never null)
源码Source io/agentscope/core/skill/AgentSkill.java:189–191

getMetadata

public Map<String, Object> getMetadata()

获取技能元数据。

Gets the skill metadata.

返回Returns Map<String, Object>
返回映射。The immutable metadata map (never null, may be empty except required fields)
源码Source io/agentscope/core/skill/AgentSkill.java:198–200

getMetadataValue

public Object getMetadataValue(String key)

获取元数据值通过密钥。

Gets a metadata value by key.

参数Parameters
名称Name类型Type说明Description
keyString元数据密钥。The metadata key
返回Returns Object
返回对象。The metadata value, or null if not found
源码Source io/agentscope/core/skill/AgentSkill.java:208–210

getSkillContent

public String getSkillContent()

获取技能内容。

Gets the skill content.

返回Returns String
返回字符串结果。The skill content (never null)
源码Source io/agentscope/core/skill/AgentSkill.java:219–221

getSource

public String getSource()

获取来源。

Gets the skill source identifier.

返回Returns String
返回字符串结果。The source identifier (never null)
源码Source io/agentscope/core/skill/AgentSkill.java:228–230

getResources

public Map<String, String> getResources()

获取 getResources。

Gets the skill resources.

返回Returns Map<String, String>
返回映射。The resources map (never null, may be empty)
源码Source io/agentscope/core/skill/AgentSkill.java:237–239

getResource

public String getResource(String resourcePath)

获取资源内容通过路径。

Gets the resource content by path.

参数Parameters
名称Name类型Type说明Description
resourcePathString资源路径。The resource path
返回Returns String
返回字符串结果。The resource content, or null if not found
源码Source io/agentscope/core/skill/AgentSkill.java:247–249

getResourcePaths

public Set<String> getResourcePaths()

获取 getResourcePaths。

Gets all resource paths for this skill.

返回Returns Set<String>
返回设置。Unmodifiable set of resource paths
源码Source io/agentscope/core/skill/AgentSkill.java:256–258

getSkillId

public String getSkillId()

获取技能标识。

Gets a unique identifier for this skill.

返回Returns String
返回字符串结果。Unique skill identifier (never null)
源码Source io/agentscope/core/skill/AgentSkill.java:267–269

getOriginDir

public Optional<Path> getOriginDir()

获取来源目录。

Returns the absolute path to this skill's on-disk source directory, when available.

返回Returns Optional<Path>
返回可选。the origin directory, empty when the skill is not filesystem-backed
源码Source io/agentscope/core/skill/AgentSkill.java:278–280

toBuilder

public Builder toBuilder()

创建构建器已初始化使用此技能's 值。

Creates a builder initialized with this skill's values.

返回Returns Builder
一种新的构建器实例。A new builder instance
源码Source io/agentscope/core/skill/AgentSkill.java:289–291

builder

public static Builder builder()
static

返回构建器实例。

Creates a new builder for creating a skill from scratch.

返回Returns Builder
返回当前实例,以支持链式调用。A new builder instance with empty fields
源码Source io/agentscope/core/skill/AgentSkill.java:298–300

toString

public String toString()

返回 toString 结果。

Returns a string representation of this skill.

返回Returns String
返回字符串结果。String representation including name, description, and source
源码Source io/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();
`
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.