skills

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package skills provides domain knowledge bases ("skills") an agent can load on demand. A skill bundles instructional content with named resources and runnable scripts, surfaced to the agent as tools through a context provider.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContextProvider

func NewContextProvider(opts ContextProviderOptions) agent.ContextProvider

NewContextProvider creates a skills context provider from the configured in-memory skills and sources.

Types

type ContextProviderOptions

type ContextProviderOptions struct {
	// SourceID is the identifier for the provider's source in the resulting context.
	// Defaults to "skills" if not provided.
	SourceID string

	// SkillFilter optionally filters skills loaded from inline skills and sources.
	// Returning true keeps a skill; returning false excludes it.
	SkillFilter func(*Skill) bool

	// Skills provides in-memory skills to register with the provider.
	Skills []*Skill

	// Sources provides external skill sources to register with the provider.
	Sources []Source

	// SkillsInstructionPrompt is a custom system prompt template.
	// When nil, a default template is used.
	//
	// The template must contain {skills}.
	SkillsInstructionPrompt *string

	// DisableLoadSkillApproval disables approval for the load_skill tool.
	// When false (the default), invoking load_skill requires approval.
	DisableLoadSkillApproval bool

	// DisableReadSkillResourceApproval disables approval for the
	// read_skill_resource tool. When false (the default), invoking
	// read_skill_resource requires approval.
	DisableReadSkillResourceApproval bool

	// DisableRunSkillScriptApproval disables approval for the
	// run_skill_script tool. When false (the default), invoking
	// run_skill_script requires approval.
	DisableRunSkillScriptApproval bool

	// IncludeDetailedErrors includes script execution error details in the
	// run_skill_script result returned to the model.
	//
	// When false, script execution errors are returned to the caller so tool
	// invocation middleware can apply its own error-detail policy. When true,
	// the exception message is appended to the tool result so the model can
	// retry with different arguments. Only enable this for trusted skills and
	// scripts because raw error messages may contain prompt-injection content.
	IncludeDetailedErrors bool

	// DisableCaching rebuilds instructions and tools for every invocation.
	DisableCaching bool

	// DisableSourceDeduplication preserves duplicate skill names from the configured
	// skills and sources instead of removing later duplicates.
	DisableSourceDeduplication bool

	// Logger is an optional structured logger for provider diagnostics.
	Logger *slog.Logger
}

ContextProviderOptions configures a skills-backed agent.ContextProvider.

type Frontmatter

type Frontmatter struct {
	Name          string
	Description   string
	License       string
	Compatibility string
	AllowedTools  string
	Metadata      map[string]any
}

Frontmatter represents the parsed YAML frontmatter metadata from a SKILL.md file.

func (Frontmatter) Validate

func (f Frontmatter) Validate() error

Validate validates the frontmatter according to the Agent Skills specification.

type Resource

type Resource struct {
	Name                 string
	Description          string
	Read                 func(context.Context) (any, error)
	AdditionalProperties map[string]any
}

Resource is supplementary skill content that can be read on demand.

type Script

type Script struct {
	Name        string
	Description string
	// ParametersSchema is an optional JSON schema string describing the argument
	// format expected by the script. When set, file-based skills include the schema
	// in the skill's <available_scripts> block so the LLM knows how to format
	// arguments. Empty means no schema.
	ParametersSchema     string
	Run                  func(context.Context, *Skill, []string) (any, error)
	AdditionalProperties map[string]any
}

Script is executable skill functionality that can be run on demand.

Arguments passed to Script.Run are positional CLI-style string tokens, for example ["--value", "26.2", "--factor", "1.60934"]. The LLM is instructed to pass a JSON array of strings, and the run_skill_script tool forwards those strings verbatim. Code-defined scripts may parse the strings however they choose; file-based scripts pass them directly to the subprocess.

type ScriptRunner

type ScriptRunner func(context.Context, *Skill, *Script, []string) (any, error)

ScriptRunner defines the function signature for running a script.

The args slice contains positional CLI-style string tokens as sent by the LLM (for example ["--value", "26.2", "--factor", "1.60934"]).

type Skill

type Skill struct {
	Frontmatter Frontmatter
	// GetContent lazily loads the skill's instruction text. For file-based skills
	// this is the raw SKILL.md file content. For code-defined skills this may be
	// a synthesized document containing name, description, and body.
	GetContent           func(context.Context) (string, error)
	Resources            []Resource
	Scripts              []Script
	AdditionalProperties map[string]any
}

Skill describes a domain-specific capability with instructions, resources, and scripts.

type Source

type Source interface {
	Skills(context.Context) ([]*Skill, error)
}

Source provides skills from a specific origin.

func NewInMemorySource

func NewInMemorySource(skills ...*Skill) Source

NewInMemorySource creates a skills source backed by the provided in-memory skills.

type SourceFunc

type SourceFunc func(context.Context) ([]*Skill, error)

SourceFunc wraps a function to be used as a Source.

func (SourceFunc) Skills

func (f SourceFunc) Skills(ctx context.Context) ([]*Skill, error)

Directories

Path Synopsis
Package fsskills discovers and loads skills from a filesystem (an fs.FS), materializing skill directories, their resources, and file-backed scripts as skills.Skill values.
Package fsskills discovers and loads skills from a filesystem (an fs.FS), materializing skill directories, their resources, and file-backed scripts as skills.Skill values.

Jump to

Keyboard shortcuts

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