AS AgentScopeAPI 手册 / API Reference

MysqlSkillRepository

public class MysqlSkillRepository implements AgentSkillRepository
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:121–1308

MySQL 技能仓库,负责持久化与读取数据。位于 io.agentscope.core.skill.repository.mysql 包,实现 AgentSkillRepository。核心成员包括 getSkill、getAllSkillNames、getAllSkills、save、delete、skillExists。

MySQL database-based implementation of AgentSkillRepository.

This implementation stores skills in MySQL database tables with the following structure:

  • Skills table: stores core lookup fields (name, description), skill content, source, and optionally the full metadata tree in metadata_json

  • Resources table: stores skill resources (id, resource_path, resource_content)

Table schema for newly created tables (createIfNotExist=true):


CREATE TABLE IF NOT EXISTS agentscope_skills (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
description TEXT NOT NULL,
skill_content LONGTEXT NOT NULL,
source VARCHAR(255) NOT NULL,
metadata_json LONGTEXT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS agentscope_skill_resources (
id BIGINT NOT NULL,
resource_path VARCHAR(500) NOT NULL,
resource_content LONGTEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id, resource_path),
FOREIGN KEY (id) REFERENCES agentscope_skills(id) ON DELETE CASCADE
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Compatibility behavior:

  • New tables created by this repository include metadata_json

  • Existing tables are not auto-migrated with ALTER TABLE

  • When metadata_json exists, full skill metadata is persisted and restored

  • When metadata_json does not exist, the repository falls back to the legacy schema and only round-trips name and description

Features:

  • Automatic database/table creation when createIfNotExist=true

  • Runtime compatibility detection for legacy and new schemas

  • Full CRUD operations for skills and their resources

  • SQL injection prevention through parameterized queries

  • Transaction support for atomic operations

  • UTF-8 (utf8mb4) character set support for internationalization

Example usage:

`// Using simple constructor with default database/table names
DataSource dataSource = createDataSource();
MysqlSkillRepository repo = new MysqlSkillRepository(dataSource, true, true);

// Using Builder for custom configuration
MysqlSkillRepository repo = MysqlSkillRepository.builder(dataSource)
.databaseName("my_database")
.skillsTableName("my_skills")
.resourcesTableName("my_resources")
.createIfNotExist(true)
.writeable(true)
.build();

// Save a skill
AgentSkill skill = new AgentSkill("my-skill", "Description", "Content", resources);
repo.save(List.of(skill), false);

// Get a skill
AgentSkill loaded = repo.getSkill("my-skill");
`

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
Builder for creating MysqlSkillRepository instances with custom configuration.

构造器摘要Constructor Summary

构造器Constructor说明Description
public MysqlSkillRepository(DataSource dataSource, boolean createIfNotExist, boolean writeable)
初始化 `MysqlSkillRepository` 实例。
Create a MysqlSkillRepository with default database and table names.

方法摘要Method Summary

方法Method说明Description
public AgentSkill getSkill(String name)
获取技能。
Returns the skill.
public List<String> getAllSkillNames()
获取 `getAllSkillNames`。
Returns the all skill names.
public List<AgentSkill> getAllSkills()
获取所有技能。
Returns the all skills.
public boolean save(List<AgentSkill> skills, boolean force)
保存数据到持久化存储。
Performs the save operation.
public boolean delete(String skillName)
删除数据。
Performs the delete operation.
public boolean skillExists(String skillName)
设置该参数。
Performs the skill exists operation.
public AgentSkillRepositoryInfo getRepositoryInfo()
获取仓库信息。
Returns the repository info.
public String getSource()
获取来源。
Returns the source.
public void setWriteable(boolean writeable)
设置 `setWriteable`。
Sets the writeable.
public boolean isWriteable()
判断是否 `isWriteable`。
Returns whether the writeable.
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
public String getDatabaseName()
获取数据库名称。
Get the database name used for storing skills.
public String getSkillsTableName()
获取 `getSkillsTableName`。
Get the skills table name.
public String getResourcesTableName()
获取 `getResourcesTableName`。
Get the resources table name.
public DataSource getDataSource()
获取数据来源。
Get the DataSource used for database connections.
public int clearAllSkills()
清空所有技能。
Clear all skills from the database (for testing or cleanup).
public static Builder builder(DataSource dataSource)
static
创建用于MysqlSkillRepository的构建器。
Create a new Builder for MysqlSkillRepository.

构造器详情Constructor Detail

MysqlSkillRepository

public MysqlSkillRepository(DataSource dataSource, boolean createIfNotExist, boolean writeable)

初始化 MysqlSkillRepository 实例。

Create a MysqlSkillRepository with default database and table names.

参数Parameters
名称Name类型Type说明Description
dataSourceDataSource数据来源(类型 `DataSource`)。DataSource for database connections
createIfNotExistboolean创建 If 不 Exist(类型 `boolean`)。If true, auto-create the database and tables for new deployments; if false, require existing schema. Existing tables are not auto-migrated to add `metadata_json`
writeablebooleanwriteable(类型 `boolean`)。Whether the repository supports write operations
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if dataSource is null
  • IllegalStateException 可能抛出 `IllegalStateException`。if createIfNotExist is false and database/tables do not exist
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:174–183

方法详情Method Detail

getSkill

public AgentSkill getSkill(String name)

获取技能。

Returns the skill.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。The name.
返回Returns AgentSkill
返回AgentSkill。Returns agent skill.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:441–499

getAllSkillNames

public List<String> getAllSkillNames()

获取 getAllSkillNames。

Returns the all skill names.

返回Returns List<String>
返回列出。Returns list.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:501–521

getAllSkills

public List<AgentSkill> getAllSkills()

获取所有技能。

Returns the all skills.

返回Returns List<AgentSkill>
返回列出。Returns list.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:523–597

save

public boolean save(List<AgentSkill> skills, boolean force)

保存数据到持久化存储。

Performs the save operation.

参数Parameters
名称Name类型Type说明Description
skillsList<AgentSkill>技能(类型 `List`)。The skills.
forcebooleanforce(类型 `boolean`)。The force.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:599–682

delete

public boolean delete(String skillName)

删除数据。

Performs the delete operation.

参数Parameters
名称Name类型Type说明Description
skillNameString技能名称(类型 `String`)。The skill name.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:802–834

skillExists

public boolean skillExists(String skillName)

设置该参数。

Performs the skill exists operation.

参数Parameters
名称Name类型Type说明Description
skillNameString技能名称(类型 `String`)。The skill name.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:858–869

getRepositoryInfo

public AgentSkillRepositoryInfo getRepositoryInfo()

获取仓库信息。

Returns the repository info.

返回Returns AgentSkillRepositoryInfo
返回AgentSkillRepositoryInfo。Returns agent skill repository info.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:891–895

getSource

public String getSource()

获取来源。

Returns the source.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:897–900

setWriteable

public void setWriteable(boolean writeable)

设置 setWriteable。

Sets the writeable.

参数Parameters
名称Name类型Type说明Description
writeablebooleanwriteable(类型 `boolean`)。The writeable.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:902–905

isWriteable

public boolean isWriteable()

判断是否 isWriteable。

Returns whether the writeable.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:907–910

close

public void close()

关闭连接并释放相关资源。

Releases resources and connections.

源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:912–916

getDatabaseName

public String getDatabaseName()

获取数据库名称。

Get the database name used for storing skills.

返回Returns String
数据库名称。the database name
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:923–925

getSkillsTableName

public String getSkillsTableName()

获取 getSkillsTableName。

Get the skills table name.

返回Returns String
返回字符串结果。the skills table name
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:932–934

getResourcesTableName

public String getResourcesTableName()

获取 getResourcesTableName。

Get the resources table name.

返回Returns String
返回字符串结果。the resources table name
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:941–943

getDataSource

public DataSource getDataSource()

获取数据来源。

Get the DataSource used for database connections.

返回Returns DataSource
DataSource 实例。the DataSource instance
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:950–952

clearAllSkills

public int clearAllSkills()

清空所有技能。

Clear all skills from the database (for testing or cleanup).

返回Returns int
技能已删除的数量。the number of skills deleted
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:1057–1089

builder

public static Builder builder(DataSource dataSource)
static

创建用于MysqlSkillRepository的构建器。

Create a new Builder for MysqlSkillRepository.

参数Parameters
名称Name类型Type说明Description
dataSourceDataSource数据来源(类型 `DataSource`)。DataSource for database connections (required)
返回Returns Builder
一种新的构建器实例。a new Builder instance
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if dataSource is null
源码Source io/agentscope/core/skill/repository/mysql/MysqlSkillRepository.java:1199–1201

嵌套类详情Nested Class Detail

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.skill.repository.mysql 包。核心成员包括 databaseName、skillsTableName、resourcesTableName、createIfNotExist、writeable、build。

Builder for creating MysqlSkillRepository instances with custom configuration.

This builder provides a fluent API for configuring all aspects of the repository, including database name, table names, and behavior options.

基于官方固定版本源码静态生成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.