AS AgentScopeAPI 手册 / API Reference

PostgresSkillRepository

public class PostgresSkillRepository implements AgentSkillRepository
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:123–1397

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

PostgreSQL database-based implementation of AgentSkillRepository.

This implementation stores skills in PostgreSQL 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"."agentscope_skills" (
id BIGSERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
description TEXT NOT NULL,
skill_content TEXT NOT NULL,
source VARCHAR(255) NOT NULL,
metadata_json TEXT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS "agentscope"."agentscope_skill_resources" (
id BIGINT NOT NULL,
resource_path VARCHAR(500) NOT NULL,
resource_content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id, resource_path),
FOREIGN KEY (id) REFERENCES "agentscope"."agentscope_skills"(id) ON DELETE CASCADE
);

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 schema/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

  • PostgreSQL schema-based storage selected by JDBC URL plus schema configuration

Example usage:

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

// Using Builder for custom configuration
PostgresSkillRepository repo = PostgresSkillRepository.builder(dataSource)
.schemaName("my_schema")
.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 PostgresSkillRepository instances with custom configuration.

构造器摘要Constructor Summary

构造器Constructor说明Description
public PostgresSkillRepository(DataSource dataSource, boolean createIfNotExist, boolean writeable)
初始化 `PostgresSkillRepository` 实例。
Create a PostgresSkillRepository with default schema 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 getSchemaName()
获取模式名称。
Get the schema 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
创建用于PostgresSkillRepository的构建器。
Create a new Builder for PostgresSkillRepository.

构造器详情Constructor Detail

PostgresSkillRepository

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

初始化 PostgresSkillRepository 实例。

Create a PostgresSkillRepository with default schema and table names.

参数Parameters
名称Name类型Type说明Description
dataSourceDataSource数据来源(类型 `DataSource`)。DataSource for database connections
createIfNotExistboolean创建 If 不 Exist(类型 `boolean`)。If true, auto-create the schema 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 schema/tables do not exist
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:185–194

方法详情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/postgresql/PostgresSkillRepository.java:497–555

getAllSkillNames

public List<String> getAllSkillNames()

获取 getAllSkillNames。

Returns the all skill names.

返回Returns List<String>
返回列出。Returns list.
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:557–577

getAllSkills

public List<AgentSkill> getAllSkills()

获取所有技能。

Returns the all skills.

返回Returns List<AgentSkill>
返回列出。Returns list.
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:579–653

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/postgresql/PostgresSkillRepository.java:655–729

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/postgresql/PostgresSkillRepository.java:881–909

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/postgresql/PostgresSkillRepository.java:933–944

getRepositoryInfo

public AgentSkillRepositoryInfo getRepositoryInfo()

获取仓库信息。

Returns the repository info.

返回Returns AgentSkillRepositoryInfo
返回AgentSkillRepositoryInfo。Returns agent skill repository info.
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:966–970

getSource

public String getSource()

获取来源。

Returns the source.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:972–975

setWriteable

public void setWriteable(boolean writeable)

设置 setWriteable。

Sets the writeable.

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

isWriteable

public boolean isWriteable()

判断是否 isWriteable。

Returns whether the writeable.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:982–985

close

public void close()

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

Releases resources and connections.

源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:987–991

getSchemaName

public String getSchemaName()

获取模式名称。

Get the schema name used for storing skills.

返回Returns String
模式名称。the schema name
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:998–1000

getSkillsTableName

public String getSkillsTableName()

获取 getSkillsTableName。

Get the skills table name.

返回Returns String
返回字符串结果。the skills table name
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:1007–1009

getResourcesTableName

public String getResourcesTableName()

获取 getResourcesTableName。

Get the resources table name.

返回Returns String
返回字符串结果。the resources table name
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:1016–1018

getDataSource

public DataSource getDataSource()

获取数据来源。

Get the DataSource used for database connections.

返回Returns DataSource
DataSource 实例。the DataSource instance
源码Source io/agentscope/core/skill/repository/postgresql/PostgresSkillRepository.java:1025–1027

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/postgresql/PostgresSkillRepository.java:1131–1156

builder

public static Builder builder(DataSource dataSource)
static

创建用于PostgresSkillRepository的构建器。

Create a new Builder for PostgresSkillRepository.

参数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/postgresql/PostgresSkillRepository.java:1288–1290

嵌套类详情Nested Class Detail

Builder

public static class Builder

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

Builder for creating PostgresSkillRepository instances with custom configuration.

This builder provides a fluent API for configuring all aspects of the repository, including schema 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.