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.
Source discovery is cached by default, while filters run for each invocation. Sources and filters receive agent and session identity in SourceContext. Scripts accept JSON values through Script.Run. Providers support opt-in source ownership and explicit cleanup; see ContextProvider.Close.
AggregatingSource, CachingSource, FilteringSource, and DeduplicatingSource can also be composed independently of a provider.
Index ¶
- func AllToolsAutoApprovalRule(_ context.Context, ruleContext *toolapproval.ToolAutoApprovalRuleContext) (bool, error)
- func ReadOnlyToolsAutoApprovalRule(_ context.Context, ruleContext *toolapproval.ToolAutoApprovalRuleContext) (bool, error)
- func ValidateCompatibility(compatibility string) error
- func ValidateDescription(description string) error
- func ValidateName(name string) error
- type AggregatingSource
- type CachingSource
- type CachingSourceConfig
- type ContextProvider
- type ContextProviderOptions
- type DeduplicatingSource
- type FilteringSource
- type Frontmatter
- type Resource
- type Script
- type ScriptRunner
- type Skill
- type Source
- type SourceContext
- type SourceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllToolsAutoApprovalRule ¶ added in v0.1.1
func AllToolsAutoApprovalRule(_ context.Context, ruleContext *toolapproval.ToolAutoApprovalRuleContext) (bool, error)
AllToolsAutoApprovalRule auto-approves all skill tools.
Add this function to toolapproval.Config.AutoApprovalRules to automatically approve load_skill, read_skill_resource, and run_skill_script. Warning: only use this rule when skill scripts are trusted, because it auto-approves script execution.
func ReadOnlyToolsAutoApprovalRule ¶ added in v0.1.1
func ReadOnlyToolsAutoApprovalRule(_ context.Context, ruleContext *toolapproval.ToolAutoApprovalRuleContext) (bool, error)
ReadOnlyToolsAutoApprovalRule auto-approves read-only skill tools.
Add this function to toolapproval.Config.AutoApprovalRules to automatically approve load_skill and read_skill_resource while continuing to prompt for run_skill_script and non-skill tools.
func ValidateCompatibility ¶ added in v0.3.0
ValidateCompatibility validates an optional compatibility value. An empty value is valid; otherwise it must be at most 500 UTF-16 code units.
func ValidateDescription ¶ added in v0.3.0
ValidateDescription validates a skill description. It must be non-blank and at most 1024 UTF-16 code units.
func ValidateName ¶ added in v0.3.0
ValidateName validates a skill name. It must be non-blank, at most 64 characters, and use only lowercase letters, digits, and single interior hyphens.
Types ¶
type AggregatingSource ¶ added in v0.3.0
type AggregatingSource struct {
// contains filtered or unexported fields
}
AggregatingSource concatenates its child sources in registration order, preserving each child's skill order without filtering or deduplication.
func NewAggregatingSource ¶ added in v0.3.0
func NewAggregatingSource(sources ...Source) *AggregatingSource
NewAggregatingSource creates an aggregate and takes responsibility for closing children that implement io.Closer. It copies the registration slice. It panics if a child is nil.
func (*AggregatingSource) Close ¶ added in v0.3.0
func (s *AggregatingSource) Close() error
Close idempotently closes child closers and returns all cleanup errors. Do not overlap Close with Skills calls.
func (*AggregatingSource) Skills ¶ added in v0.3.0
func (s *AggregatingSource) Skills(ctx context.Context, sourceContext SourceContext) ([]*Skill, error)
Skills loads children sequentially and stops at the first error.
type CachingSource ¶ added in v0.3.0
type CachingSource struct {
// contains filtered or unexported fields
}
CachingSource caches successful skill lists, coordinating one active fetch per key. A fetch uses its initiating caller's context. Failed or cancelled fetches are not cached; waiting callers may retry with their own contexts. Returned slices and skills are shared with the cache and must be read-only.
func NewCachingSource ¶ added in v0.3.0
func NewCachingSource(source Source, config CachingSourceConfig) *CachingSource
NewCachingSource creates a cache and takes responsibility for closing source if it implements io.Closer. Configuration is captured at construction. It panics if source is nil.
func (*CachingSource) Close ¶ added in v0.3.0
func (s *CachingSource) Close() error
Close idempotently closes the wrapped source if it implements io.Closer. It does not cancel in-flight calls. Do not overlap Close with Skills calls.
func (*CachingSource) Skills ¶ added in v0.3.0
func (s *CachingSource) Skills(ctx context.Context, sourceContext SourceContext) ([]*Skill, error)
Skills returns a fresh cached result or loads one using the current source context. Empty successful results are cached as well.
type CachingSourceConfig ¶ added in v0.3.0
type CachingSourceConfig struct {
// CacheIsolationKeySelector chooses a stable, low-cardinality cache bucket.
// Nil, or a nil returned key, uses the shared bucket. An explicit empty key
// is distinct from that shared bucket.
CacheIsolationKeySelector func(context.Context, SourceContext) *string
// RefreshInterval limits how long a successful result remains fresh.
// Nil never expires. Zero or negative values reload on every call.
RefreshInterval *time.Duration
}
CachingSourceConfig configures NewCachingSource.
type ContextProvider ¶ added in v0.3.0
type ContextProvider struct {
// contains filtered or unexported fields
}
ContextProvider supplies skill instructions and tools to an agent. Create it with NewContextProvider and call ContextProvider.Close when finished.
func NewContextProvider ¶
func NewContextProvider(opts ContextProviderOptions) *ContextProvider
NewContextProvider creates a skills context provider from the configured in-memory skills and sources. Sources are borrowed unless opts.OwnsSources is true.
func (*ContextProvider) Close ¶ added in v0.3.0
func (p *ContextProvider) Close() error
Close prevents subsequent invocations and tool calls and releases owned sources implementing io.Closer. It is idempotent, including on an error. Do not overlap Close with invocations or tool calls; it does not cancel operations already in flight.
func (*ContextProvider) Invoked ¶ added in v0.3.0
func (p *ContextProvider) Invoked(ctx context.Context, invoked agent.InvokedContext) error
Invoked completes a skills-provider invocation without retaining conversation history.
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.
// It receives the current agent/session context and is evaluated on every
// invocation after source caching and before deduplication.
SkillFilter func(context.Context, *Skill, SourceContext) 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
// OwnsSources transfers responsibility for closing sources that implement
// [io.Closer] to the provider. The default is false.
OwnsSources bool
// 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 reloads sources on every invocation. Instructions and
// tools are always assembled per invocation, after filtering.
DisableCaching bool
// CacheIsolationKeySelector selects the cache bucket for an invocation.
// A nil selector, or a nil key returned by the selector, uses the shared
// cache bucket. Keys should be stable and low-cardinality.
CacheIsolationKeySelector func(context.Context, SourceContext) *string
// RefreshInterval controls how long a cached result remains fresh. A nil
// interval never expires the cache. A zero or negative interval refreshes
// on every invocation.
RefreshInterval *time.Duration
// 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 DeduplicatingSource ¶ added in v0.3.0
type DeduplicatingSource struct {
// contains filtered or unexported fields
}
DeduplicatingSource keeps the first occurrence of each case-insensitive skill name, preserving source order and logging duplicates.
func NewDeduplicatingSource ¶ added in v0.3.0
func NewDeduplicatingSource(source Source, logger *slog.Logger) *DeduplicatingSource
NewDeduplicatingSource creates a deduplicator and takes responsibility for closing the wrapped source if it implements io.Closer. Nil logger discards diagnostics. It panics if source is nil.
func (*DeduplicatingSource) Close ¶ added in v0.3.0
func (s *DeduplicatingSource) Close() error
Close idempotently closes the wrapped source if it implements io.Closer. Do not overlap Close with Skills calls.
func (*DeduplicatingSource) Skills ¶ added in v0.3.0
func (s *DeduplicatingSource) Skills(ctx context.Context, sourceContext SourceContext) ([]*Skill, error)
Skills returns the first skill for each name without modifying the inner list.
type FilteringSource ¶ added in v0.3.0
type FilteringSource struct {
// contains filtered or unexported fields
}
FilteringSource evaluates its predicate on every call, preserving the order of included skills. Place it outside a cache for invocation-specific filtering.
func NewFilteringSource ¶ added in v0.3.0
func NewFilteringSource(source Source, filter func(context.Context, *Skill, SourceContext) bool, logger *slog.Logger) *FilteringSource
NewFilteringSource creates a filter and takes responsibility for closing the wrapped source if it implements io.Closer. Nil logger discards diagnostics. It panics if source or filter is nil.
func (*FilteringSource) Close ¶ added in v0.3.0
func (s *FilteringSource) Close() error
Close idempotently closes the wrapped source if it implements io.Closer. Do not overlap Close with Skills calls.
func (*FilteringSource) Skills ¶ added in v0.3.0
func (s *FilteringSource) Skills(ctx context.Context, sourceContext SourceContext) ([]*Skill, error)
Skills loads the inner source and evaluates the predicate with the current agent and session, without modifying the source's slice.
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. Description and compatibility limits count UTF-16 code units.
type Resource ¶
type Resource struct {
Name string
Description string
// Read loads the resource. Its error is propagated to the tool caller,
// allowing invocation middleware to apply its error-detail policy.
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, json.RawMessage) (any, error)
AdditionalProperties map[string]any
}
Script is executable skill functionality that can be run on demand.
Arguments passed to Script.Run are JSON values. Scripts decode and validate their own input format, such as a named JSON object or a positional string array. Missing arguments are nil; an explicit JSON null is preserved.
type ScriptRunner ¶
ScriptRunner runs a file-backed script with JSON arguments. It receives the owning skill and script metadata, including the backing filesystem. The runner is responsible for decoding and validating its argument format.
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.
// Errors, including cancellation, propagate to the load_skill caller.
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, SourceContext) ([]*Skill, error)
}
Source provides skills from a specific origin.
The source context identifies the initiating agent and invocation session. Sources that vary by session must disable caching or use an appropriate ContextProviderOptions.CacheIsolationKeySelector. The provider borrows sources unless ContextProviderOptions.OwnsSources is set. Sources return valid, non-nil skills. Returned slices and skills must be treated as read-only unless the source explicitly transfers ownership.
func NewInMemorySource ¶
NewInMemorySource creates a skills source backed by the provided in-memory skills.
type SourceContext ¶ added in v0.3.0
SourceContext identifies the agent and session requesting skills. Session is nil when the invocation has no session. Agent is set during agent.Agent.Run and may be nil when a provider or source is called directly. Treat the context as read-only; session state remains application-managed.
type SourceFunc ¶
type SourceFunc func(context.Context, SourceContext) ([]*Skill, error)
SourceFunc wraps a function to be used as a Source.
func (SourceFunc) Skills ¶
func (f SourceFunc) Skills(ctx context.Context, sourceContext SourceContext) ([]*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. |