skills

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveSkillToDirectory

func SaveSkillToDirectory(skill *Skill, dir string) error

SaveSkillToDirectory 保存技能到目录

Types

type CapabilityDescriptor added in v1.0.0

type CapabilityDescriptor struct {
	Name        string
	Description string
	Category    string // "task", "query", or "stream"
	AgentID     string
	AgentName   string
	Tags        []string
	Metadata    map[string]string
}

CapabilityDescriptor describes a capability for registration in a discovery system.

type CapabilityRegistrar added in v1.0.0

type CapabilityRegistrar interface {
	RegisterCapability(ctx context.Context, descriptor *CapabilityDescriptor) error
	UnregisterCapability(ctx context.Context, agentID string, capabilityName string) error
}

CapabilityRegistrar is the interface for registering capabilities in a discovery system. Implement this interface to bridge skills with your discovery layer.

type DefaultSkillManager

type DefaultSkillManager struct {
	// contains filtered or unexported fields
}

DefaultSkillManager 默认技能管理器实现

func NewSkillManager

func NewSkillManager(config SkillManagerConfig, logger *zap.Logger) *DefaultSkillManager

NewSkillManager 创建技能管理器

func (*DefaultSkillManager) ClearCache

func (m *DefaultSkillManager) ClearCache()

ClearCache 清除缓存(卸载所有技能)

func (*DefaultSkillManager) DiscoverSkills

func (m *DefaultSkillManager) DiscoverSkills(ctx context.Context, task string) ([]*Skill, error)

DiscoverSkills 发现适合任务的技能

func (*DefaultSkillManager) GetIndexedSkillsCount

func (m *DefaultSkillManager) GetIndexedSkillsCount() int

GetIndexedSkillsCount 获取索引中的技能数量

func (*DefaultSkillManager) GetLoadedSkillsCount

func (m *DefaultSkillManager) GetLoadedSkillsCount() int

GetLoadedSkillsCount 获取已加载技能数量

func (*DefaultSkillManager) GetSkill

func (m *DefaultSkillManager) GetSkill(skillID string) (*Skill, bool)

GetSkill 获取已加载的技能

func (*DefaultSkillManager) ListSkills

func (m *DefaultSkillManager) ListSkills() []*SkillMetadata

ListSkills 列出所有技能

func (*DefaultSkillManager) LoadSkill

func (m *DefaultSkillManager) LoadSkill(ctx context.Context, skillID string) (*Skill, error)

LoadSkill 加载技能

func (*DefaultSkillManager) RefreshIndex

func (m *DefaultSkillManager) RefreshIndex() error

RefreshIndex 刷新技能索引

func (*DefaultSkillManager) RegisterSkill

func (m *DefaultSkillManager) RegisterSkill(skill *Skill) error

RegisterSkill 注册技能

func (*DefaultSkillManager) ScanDirectory

func (m *DefaultSkillManager) ScanDirectory(dir string) error

ScanDirectory 扫描目录查找技能

func (*DefaultSkillManager) SearchSkills

func (m *DefaultSkillManager) SearchSkills(query string) []*SkillMetadata

SearchSkills 搜索技能

func (*DefaultSkillManager) UnloadSkill

func (m *DefaultSkillManager) UnloadSkill(ctx context.Context, skillID string) error

UnloadSkill 卸载技能

func (*DefaultSkillManager) UnregisterSkill

func (m *DefaultSkillManager) UnregisterSkill(skillID string) error

UnregisterSkill 注销技能

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

书记官处管理技能登记和发现。

func NewRegistry

func NewRegistry(logger *zap.Logger) *Registry

NewRegistry创建了新的技能注册.

func (*Registry) Disable

func (r *Registry) Disable(skillID string) error

禁用一个技能 。

func (*Registry) Enable

func (r *Registry) Enable(skillID string) error

启用一个技能 。

func (*Registry) Export

func (r *Registry) Export() ([]byte, error)

出口所有技能定义。

func (*Registry) Get

func (r *Registry) Get(skillID string) (*SkillInstance, bool)

以身份获取技能。

func (*Registry) GetByName

func (r *Registry) GetByName(name string) (*SkillInstance, bool)

GetByName 按名称检索技能 。

func (*Registry) Import

func (r *Registry) Import(data []byte) error

进口技能定义(手提人必须单独登记).

func (*Registry) Invoke

func (r *Registry) Invoke(ctx context.Context, skillID string, input json.RawMessage) (json.RawMessage, error)

Invoke 引用一个技能。

func (*Registry) ListAll

func (r *Registry) ListAll() []*SkillInstance

ListAll 返回所有注册技能 。

func (*Registry) ListByCategory

func (r *Registry) ListByCategory(category SkillCategory) []*SkillInstance

ListByCategory 在一个类别中返回技能.

func (*Registry) Register

func (r *Registry) Register(def *SkillDefinition, handler SkillHandler) error

注册注册技能。

func (*Registry) Search

func (r *Registry) Search(query string, tags []string) []*SkillInstance

通过标签或关键词搜索搜索技能.

func (*Registry) Unregister

func (r *Registry) Unregister(skillID string) error

未注册者删除一个技能。

type Skill

type Skill struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Version     string   `json:"version"`
	Description string   `json:"description"`
	Category    string   `json:"category,omitempty"` // 技能分类
	Tags        []string `json:"tags,omitempty"`     // 标签

	// 核心内容
	Instructions string         `json:"instructions"` // 技能指令
	Tools        []string       `json:"tools"`        // 需要的工具列表
	Resources    map[string]any `json:"resources"`    // 资源(文件、数据等)
	Examples     []SkillExample `json:"examples"`     // 使用示例

	// 加载策略
	LazyLoad     bool     `json:"lazy_load"`    // 是否延迟加载
	Priority     int      `json:"priority"`     // 优先级(用于冲突解决)
	Dependencies []string `json:"dependencies"` // 依赖的其他技能

	// 元数据
	Author    string    `json:"author,omitempty"`
	License   string    `json:"license,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	// 运行时状态
	Loaded   bool      `json:"-"` // 是否已加载
	LoadedAt time.Time `json:"-"` // 加载时间
}

Skill 代表一个可加载的 Agent 技能 基于 Anthropic Agent Skills 标准设计

func LoadSkillFromDirectory

func LoadSkillFromDirectory(dir string) (*Skill, error)

LoadSkillFromDirectory 从目录加载技能

func (*Skill) Clone

func (s *Skill) Clone() *Skill

Clone 克隆技能(用于隔离修改)

func (*Skill) GetInstructions

func (s *Skill) GetInstructions() string

Get Instructions返回技能说明,以便迅速注射/增强.

func (*Skill) GetResourceAsJSON

func (s *Skill) GetResourceAsJSON(name string, target any) error

GetResourceAsJSON 获取资源作为 JSON

func (*Skill) GetResourceAsString

func (s *Skill) GetResourceAsString(name string) (string, error)

GetResourceAsString 获取资源作为字符串

func (*Skill) MatchesTask

func (s *Skill) MatchesTask(task string) float64

MatchesTask 检查技能是否匹配任务

func (*Skill) RenderInstructions

func (s *Skill) RenderInstructions(vars map[string]string) string

RenderInstructions 渲染技能指令(支持变量替换)

func (*Skill) ToToolSchema

func (s *Skill) ToToolSchema() llm.ToolSchema

ToToolSchema 将技能转换为工具 Schema(如果技能可以作为工具使用)

func (*Skill) Validate

func (s *Skill) Validate() error

Validate 验证技能配置

type SkillBuilder

type SkillBuilder struct {
	// contains filtered or unexported fields
}

SkillBuilder 技能构建器

func NewSkillBuilder

func NewSkillBuilder(id, name string) *SkillBuilder

NewSkillBuilder 创建技能构建器

func (*SkillBuilder) Build

func (b *SkillBuilder) Build() (*Skill, error)

Build 构建技能

func (*SkillBuilder) WithCategory

func (b *SkillBuilder) WithCategory(category string) *SkillBuilder

WithCategory 设置分类

func (*SkillBuilder) WithDependencies

func (b *SkillBuilder) WithDependencies(deps ...string) *SkillBuilder

WithDependencies 设置依赖

func (*SkillBuilder) WithDescription

func (b *SkillBuilder) WithDescription(desc string) *SkillBuilder

WithDescription 设置描述

func (*SkillBuilder) WithExample

func (b *SkillBuilder) WithExample(input, output, explanation string) *SkillBuilder

WithExample 添加示例

func (*SkillBuilder) WithInstructions

func (b *SkillBuilder) WithInstructions(instructions string) *SkillBuilder

WithInstructions 设置指令

func (*SkillBuilder) WithLazyLoad

func (b *SkillBuilder) WithLazyLoad(lazy bool) *SkillBuilder

WithLazyLoad 设置延迟加载

func (*SkillBuilder) WithPriority

func (b *SkillBuilder) WithPriority(priority int) *SkillBuilder

WithPriority 设置优先级

func (*SkillBuilder) WithResource

func (b *SkillBuilder) WithResource(name string, content any) *SkillBuilder

WithResource 添加资源

func (*SkillBuilder) WithTags

func (b *SkillBuilder) WithTags(tags ...string) *SkillBuilder

WithTags 设置标签

func (*SkillBuilder) WithTools

func (b *SkillBuilder) WithTools(tools ...string) *SkillBuilder

WithTools 设置工具

type SkillCategory

type SkillCategory string

技能类定义了技能类别.

const (
	CategoryReasoning     SkillCategory = "reasoning"
	CategoryCoding        SkillCategory = "coding"
	CategoryResearch      SkillCategory = "research"
	CategoryCommunication SkillCategory = "communication"
	CategoryData          SkillCategory = "data"
	CategoryAutomation    SkillCategory = "automation"
)

type SkillDefinition

type SkillDefinition struct {
	ID           string          `json:"id"`
	Name         string          `json:"name"`
	Version      string          `json:"version"`
	Category     SkillCategory   `json:"category"`
	Description  string          `json:"description"`
	InputSchema  json.RawMessage `json:"input_schema"`
	OutputSchema json.RawMessage `json:"output_schema"`
	Requirements []string        `json:"requirements,omitempty"`
	Tags         []string        `json:"tags,omitempty"`
	Author       string          `json:"author,omitempty"`
	License      string          `json:"license,omitempty"`
	Metadata     map[string]any  `json:"metadata,omitempty"`
	CreatedAt    time.Time       `json:"created_at"`
	UpdatedAt    time.Time       `json:"updated_at"`
}

SkillDefinition定义了一种标准化的技能.

type SkillDiscoveryBridge added in v1.0.0

type SkillDiscoveryBridge struct {
	// contains filtered or unexported fields
}

SkillDiscoveryBridge bridges the Skills system to a Discovery system. It converts Skills into CapabilityDescriptors and registers them via a CapabilityRegistrar.

func NewSkillDiscoveryBridge added in v1.0.0

func NewSkillDiscoveryBridge(
	skillManager SkillManager,
	registrar CapabilityRegistrar,
	agentID string,
	logger *zap.Logger,
) *SkillDiscoveryBridge

NewSkillDiscoveryBridge creates a new bridge between Skills and Discovery.

func (*SkillDiscoveryBridge) RegisterSkillAsCapability added in v1.0.0

func (b *SkillDiscoveryBridge) RegisterSkillAsCapability(ctx context.Context, skill *Skill) error

RegisterSkillAsCapability converts a Skill to a CapabilityDescriptor and registers it.

func (*SkillDiscoveryBridge) SyncAll added in v1.0.0

func (b *SkillDiscoveryBridge) SyncAll(ctx context.Context) error

SyncAll synchronizes all registered Skills to the Discovery system.

func (*SkillDiscoveryBridge) UnregisterSkill added in v1.0.0

func (b *SkillDiscoveryBridge) UnregisterSkill(ctx context.Context, skillID string) error

UnregisterSkill removes a skill's capability from the discovery system.

type SkillExample

type SkillExample struct {
	Input       string `json:"input"`
	Output      string `json:"output"`
	Explanation string `json:"explanation,omitempty"`
}

SkillExample 技能使用示例

type SkillHandler

type SkillHandler func(ctx context.Context, input json.RawMessage) (json.RawMessage, error)

SkillHandler执行一种技能.

type SkillInstance

type SkillInstance struct {
	Definition *SkillDefinition `json:"definition"`
	Handler    SkillHandler     `json:"-"`
	Enabled    bool             `json:"enabled"`
	Stats      SkillStats       `json:"stats"`
}

技能Instance是一个注册技能案例。

type SkillManager

type SkillManager interface {
	// 技能发现
	DiscoverSkills(ctx context.Context, task string) ([]*Skill, error)

	// 技能加载
	LoadSkill(ctx context.Context, skillID string) (*Skill, error)
	UnloadSkill(ctx context.Context, skillID string) error

	// 技能查询
	GetSkill(skillID string) (*Skill, bool)
	ListSkills() []*SkillMetadata
	SearchSkills(query string) []*SkillMetadata

	// 技能管理
	RegisterSkill(skill *Skill) error
	UnregisterSkill(skillID string) error

	// 技能仓库
	ScanDirectory(dir string) error
	RefreshIndex() error
}

SkillManager 技能管理器

type SkillManagerConfig

type SkillManagerConfig struct {
	AutoLoad        bool    `json:"auto_load"`         // 自动加载技能
	MaxLoadedSkills int     `json:"max_loaded_skills"` // 最大加载技能数
	MinMatchScore   float64 `json:"min_match_score"`   // 最低匹配分数
	EnableCaching   bool    `json:"enable_caching"`    // 启用缓存
	CacheTTL        int     `json:"cache_ttl"`         // 缓存 TTL(秒)
}

SkillManagerConfig 技能管理器配置

func DefaultSkillManagerConfig

func DefaultSkillManagerConfig() SkillManagerConfig

DefaultSkillManagerConfig 默认配置

type SkillManifest

type SkillManifest struct {
	Skill
	Files []string `json:"files,omitempty"` // 关联的文件列表
}

SkillManifest 技能清单文件(SKILL.json)

type SkillMetadata

type SkillMetadata struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Category    string   `json:"category"`
	Tags        []string `json:"tags"`
	Version     string   `json:"version"`
	Path        string   `json:"path"` // 技能文件路径
}

SkillMetadata 技能元数据(用于发现和索引)

type SkillStats

type SkillStats struct {
	Invocations int64         `json:"invocations"`
	Successes   int64         `json:"successes"`
	Failures    int64         `json:"failures"`
	AvgLatency  time.Duration `json:"avg_latency"`
	LastInvoked *time.Time    `json:"last_invoked,omitempty"`
}

SkillStats跟踪技能使用统计.

type SkillsExtensionAdapter added in v1.0.0

type SkillsExtensionAdapter struct {
	// contains filtered or unexported fields
}

SkillsExtensionAdapter adapts DefaultSkillManager to the types.SkillsExtension interface. This bridges the gap between the Skills system and the extension registry.

types.SkillsExtension interface:

  • LoadSkill(ctx context.Context, name string) error
  • ExecuteSkill(ctx context.Context, name string, input any) (any, error)
  • ListSkills() []string

func NewSkillsExtensionAdapter added in v1.0.0

func NewSkillsExtensionAdapter(manager *DefaultSkillManager, registry *Registry) *SkillsExtensionAdapter

NewSkillsExtensionAdapter creates a new adapter. manager is used for skill loading/discovery, registry is used for skill execution. If registry is nil, ExecuteSkill will return an error.

func (*SkillsExtensionAdapter) ExecuteSkill added in v1.0.0

func (a *SkillsExtensionAdapter) ExecuteSkill(ctx context.Context, name string, input any) (any, error)

ExecuteSkill executes a loaded skill by name. It first checks the Registry (which supports handlers), then falls back to returning the skill's instructions as output.

func (*SkillsExtensionAdapter) ListSkills added in v1.0.0

func (a *SkillsExtensionAdapter) ListSkills() []string

ListSkills returns the names of all available skills.

func (*SkillsExtensionAdapter) LoadSkill added in v1.0.0

func (a *SkillsExtensionAdapter) LoadSkill(ctx context.Context, name string) error

LoadSkill loads a skill by name. It searches the manager's index by name, then loads the matching skill.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL