skill

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsTool

func AsTool(exe ExecutableSkill, runner WorkflowRunner) (tool.Tool, error)

AsTool 把 ExecutableSkill 转成 tool.Tool。

  • ToolSkill → ToolSkill 自身就是 tool.Tool(Name() 返回 skill 名,其余委托给底层工具)
  • WorkflowSkill → 包成 SubWorkflowTool(内部走 WorkflowRunner)
  • AgentSkill → S4 前不支持执行,返回 error

func DefaultRoots

func DefaultRoots() []string

DefaultRoots 返回 Flux 的默认 skill 搜索路径。

func Export

func Export(spec *SkillSpec, skillDir string, workflow []byte) error

Export 把 SkillSpec 写出为 SKILL.md(+ 可选 workflow.yaml)到 skillDir/<spec.Name>/ 下。 workflow 是可选的工作流定义(YAML/JSON 字节),不为空时写为 workflow.yaml。

这是动态 DAG → 固化 Skill 闭环的落点:

agent 跑通后调用 Export(spec, dir, workflow) → 下次直接 Load("generate_video")。

func LoadAndRegister

func LoadAndRegister(ctx context.Context, loader *Loader, resolver *Resolver, reg *Registry) ([]string, error)

LoadAndRegister 从 Loader 加载所有 skill 并经 Resolver 注册进 Registry。 解析失败的 skill 跳过(不阻塞其他)。

func NewSubWorkflowTool

func NewSubWorkflowTool(spec *SkillSpec, def tool.ToolDefinition, runner WorkflowRunner) tool.Tool

NewSubWorkflowTool 把 WorkflowSkill 包成 tool.Tool。 def 提供 InputSchema(来自 SKILL.md),让 planner 知道调这个 skill 该传什么参数。

func RegisterAsTools

func RegisterAsTools(skillReg *Registry, toolReg *tool.Registry, runner WorkflowRunner) error

RegisterAsTools 把 skill.Registry 里的所有 ExecutableSkill 转成 tool.Tool, 注册进 tool.Registry。planner 经 MCP tools/list 看到的就是统一菜单。

S5 的唯一边界:不扩展 runtime、不在 MCP 层引入执行语义。 Skill 内部的 Tool/Workflow/Agent 对 MCP 不可见——MCP 只看到 ToolDefinition。

func RenderSKILLMD

func RenderSKILLMD(spec *SkillSpec) ([]byte, error)

RenderSKILLMD 把 SkillSpec 渲染成 SKILL.md 字节(YAML frontmatter + markdown body)。

func WalkSkills

func WalkSkills(root string) ([]string, error)

WalkSkills 遍历目录,找出所有包含 SKILL.md 的子目录。

Types

type AgentSkill

type AgentSkill struct {
	Def tool.ToolDefinition
}

func (*AgentSkill) Definition

func (s *AgentSkill) Definition() tool.ToolDefinition

type ExecutableSkill

type ExecutableSkill interface {
	Definition() tool.ToolDefinition
}

ExecutableSkill 是 SkillSpec 解析后的"可执行体"。 三种实现:ToolSkill(叶子工具)/ WorkflowSkill(引擎 DAG)/ AgentSkill(动态规划)。

对外只暴露 Definition()—— planner 永远只看 ToolDefinition, 不关心底层是 tool、workflow 还是 agent。

type Implementation

type Implementation string

Implementation 区分 SKILL.md 的底层执行方式。

const (
	ImplTool     Implementation = "tool"
	ImplWorkflow Implementation = "workflow"
	ImplAgent    Implementation = "agent"
)

type InputSpec

type InputSpec struct {
	Type        string `yaml:"type"`
	Description string `yaml:"description,omitempty"`
	Required    bool   `yaml:"required,omitempty"`
}

InputSpec 定义一个输入参数(从 SKILL.md frontmatter 的 inputs 段解析)。

type Loader

type Loader struct {
	// Roots 是搜索 skill 的根目录列表,按优先级排列。
	// 典型值:{projectSkills, userSkills}。
	Roots []string
}

Loader 从目录加载 SKILL.md 文件,产出 SkillSpec。

func NewLoader

func NewLoader(roots ...string) *Loader

NewLoader 创建 Loader。roots 按优先级排列(前 > 后)。

func (*Loader) List

func (l *Loader) List() ([]*SkillSpec, error)

List 列出所有 roots 中的 skill 目录(含有 SKILL.md 的目录)。

func (*Loader) Load

func (l *Loader) Load(name string) (*SkillSpec, error)

Load 在 roots 中按优先级查找名为 name 的 skill 并解析。

func (*Loader) Visit

func (l *Loader) Visit(fn func(*SkillSpec) error) error

Visit 遍历所有 roots,对每个找到的 skill 调用 fn。

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func NewRegistryWith

func NewRegistryWith(exe ExecutableSkill) *Registry

NewRegistryWith 从已有的 ExecutableSkill 创建 Registry(便捷方法)。

func (*Registry) Get

func (r *Registry) Get(name string) (ExecutableSkill, bool)

func (*Registry) List

func (r *Registry) List() []ExecutableSkill

func (*Registry) Register

func (r *Registry) Register(name string, s ExecutableSkill)

type Resolver

type Resolver struct {
	Tools ToolFactory
}

Resolver 把 SkillSpec 解析成 ExecutableSkill。

func NewResolver

func NewResolver(tools ToolFactory) *Resolver

func (*Resolver) Resolve

func (r *Resolver) Resolve(spec *SkillSpec) (ExecutableSkill, error)

Resolve 把 SkillSpec 转成 ExecutableSkill。

type SaveAsSkillTool

type SaveAsSkillTool struct {
	SkillDir string            // skills/ 的根目录
	OnSave   func(name string) // 可选:保存成功后的回调(比如重新注册到 registry)
}

SaveAsSkillTool 是一个 tool.Tool——agent 在跑通一个动态 DAG 后调用它, 把 DAG + 元数据保存为 skills/<name>/SKILL.md + workflow.yaml。

这是 Skill 进化闭环的触发点:

agent 执行成功 → 调用 save_as_skill → Export → Loader → Resolver → RegisterAsTools → 下次直接用。

参数:name(skill 名)、description、workflow_yaml(DAG 的 YAML 定义)。

func NewSaveAsSkillTool

func NewSaveAsSkillTool(skillDir string) *SaveAsSkillTool

func (*SaveAsSkillTool) Description

func (t *SaveAsSkillTool) Description() string

func (*SaveAsSkillTool) Execute

func (t *SaveAsSkillTool) Execute(_ context.Context, input map[string]any, _ tool.ToolEmitter) (*tool.Result, error)

func (*SaveAsSkillTool) InputSchema

func (t *SaveAsSkillTool) InputSchema() tool.DataSchema

func (*SaveAsSkillTool) Mode

func (*SaveAsSkillTool) Name

func (t *SaveAsSkillTool) Name() string

func (*SaveAsSkillTool) OutputSchema

func (t *SaveAsSkillTool) OutputSchema() tool.DataSchema

type SkillSpec

type SkillSpec struct {
	Name           string         `yaml:"name"`
	Description    string         `yaml:"description"`
	Implementation Implementation `yaml:"implementation"`
	// 实现专项字段
	Tool     string `yaml:"tool,omitempty"`     // ImplTool
	Workflow string `yaml:"workflow,omitempty"` // ImplWorkflow: workflow.yaml 路径(相对 skill 目录)
	Goal     string `yaml:"goal,omitempty"`     // ImplAgent

	// Inputs 声明此 skill 的输入参数(JSON Schema properties)。
	// Planner 据此决定调该 skill 时该传什么——不再靠自然语言猜。
	Inputs map[string]InputSpec `yaml:"inputs,omitempty"`

	// Dir 是 SKILL.md 所在目录的绝对路径,由 Loader 填充。
	Dir string `yaml:"-"`

	// Body 是 frontmatter 后面的 Markdown 正文(Agent 阅读用)。
	Body string `yaml:"-"`
}

SkillSpec 是 SKILL.md 解析后的结构化表示。 前置元数据(YAML frontmatter)→ 前置字段;正文 → Body。

func LoadDir

func LoadDir(dir string) (*SkillSpec, error)

LoadDir 解析指定目录下的 SKILL.md。

func Parse

func Parse(dir string, content []byte) (*SkillSpec, error)

Parse 解析单个 SKILL.md 的完整内容。

func (*SkillSpec) DefaultSpec

func (s *SkillSpec) DefaultSpec()

DefaultSpec 为缺失的必填字段填默认值。

type ToolFactory

type ToolFactory func(toolName string) (tool.Tool, error)

ToolFactory:根据 skill 引用的 tool 名查找 tool.Tool。

type ToolSkill

type ToolSkill struct {
	SkillName string    // skill 名(来自 SKILL.md)
	Tool      tool.Tool // 底层工具
}

ToolSkill 包装一个现有的 tool.Tool,但以 skill 名暴露(Name() 返回 skill 名而非工具名)。 其余方法(Description/InputSchema/Execute/Mode)全部委托给底层工具。 这样 planner 看到的是 "list_files" 而不是底下的 "shell"。

func (*ToolSkill) Definition

func (s *ToolSkill) Definition() tool.ToolDefinition

func (*ToolSkill) Description

func (s *ToolSkill) Description() string

func (*ToolSkill) Execute

func (s *ToolSkill) Execute(ctx context.Context, input map[string]any, emitter tool.ToolEmitter) (*tool.Result, error)

func (*ToolSkill) InputSchema

func (s *ToolSkill) InputSchema() tool.DataSchema

func (*ToolSkill) Mode

func (s *ToolSkill) Mode() tool.ExecutionMode

func (*ToolSkill) Name

func (s *ToolSkill) Name() string

func (*ToolSkill) OutputSchema

func (s *ToolSkill) OutputSchema() tool.DataSchema

type WorkflowRunner

type WorkflowRunner func(ctx context.Context, spec *SkillSpec, input map[string]any) (*tool.Result, error)

WorkflowRunner 是 workflow 执行的注入点(S2b → 回调,S3 → 真实 engine)。

type WorkflowSkill

type WorkflowSkill struct {
	Def         tool.ToolDefinition
	WorkflowRef string // 路径(相对 Dir)或 DB id 等引用——执行时再编译
	Dir         string // SKILL.md 所在目录(运行时拼接完整路径)
}

WorkflowSkill 不持有已编译的 runtime.Plan,而是持引用(路径/DB id)。 原因:skill 是能力引用,不是已编译执行体。未来 workflow 可能来自 DB(workflow_versions)、OSSURL、Git repo 的 workflow.yaml——引用解耦加载。

func (*WorkflowSkill) Definition

func (s *WorkflowSkill) Definition() tool.ToolDefinition

Jump to

Keyboard shortcuts

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