Documentation
¶
Overview ¶
Package skill provides skills: focused instructions for the model, optionally with resource files.
To save context, the system prompt only lists the skill catalog (names and summaries); when the model needs a skill it loads its full instructions with a tool, then reads its resource files as needed. A Source decides where skills come from: this package provides a local directory, an fs.FS and memory, and a database or remote service can implement the same interface. NewToolset turns a source into a toolset for an Agent.
Index ¶
Constants ¶
const ( // LoadToolName is the name of the tool that loads skill instructions; ReadResourceToolName is the name of the tool that reads skill resource files. LoadToolName = "load_skill" ReadResourceToolName = "read_skill_resource" )
Variables ¶
var ErrNotFound = errors.New("skill: not found")
ErrNotFound means the requested skill or resource does not exist or is not visible now.
Functions ¶
func NewToolset ¶
NewToolset wraps a skill source as a toolset; add it to Agent.Toolsets to use it.
It appends the skill catalog to the system prompt and provides two tools: load_skill loads a skill's full instructions and resource list, and read_skill_resource reads one of the resource files. When the source has no visible skills, it provides no tools and no instructions.
Types ¶
type Skill ¶
type Skill struct {
Name string
Description string
// Instructions are the skill's full instructions, which only enter the context after the model loads the skill.
Instructions string
// Resources are the paths of the skill's resource files (relative to the skill root, separated by /); read their content with ReadResource.
Resources []string
}
Skill is the complete content of a skill.
type Source ¶
type Source interface {
// List returns the skill catalog the model may currently see. It is called once at the start of each run.
List(ctx context.Context) ([]Info, error)
// Load returns the complete content of a skill, or ErrNotFound when it does not exist or is not visible.
Load(ctx context.Context, name string) (Skill, error)
// ReadResource reads one resource file of a skill, or returns ErrNotFound when it does not exist.
ReadResource(ctx context.Context, name, path string) ([]byte, error)
}
Source is where skills come from. The business layer can implement it to apply permissions, publishing state or scenario filters, or to read from a database or object storage. Its methods may be called concurrently.
func FS ¶
FS returns a source that reads skills from an fs.FS, compatible with go:embed.
Every directory under root that contains a SKILL.md is a skill, and directories may be nested into groups. The frontmatter at the top of SKILL.md gives name and description (the directory name when there is no name), the rest is the skill's instructions, and the other files in the directory are its resources. Files are read again on every call, so changes take effect on the next run.