skill

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go Skill Discovery Library

Project Badges

A high-performance, token-efficient discovery system for LLMs.

Overview

This library provides a minimalist, SQL-based mechanism for LLMs to discover and invoke tools ("skills"). It is designed to minimize token usage in the initial system prompt by providing a compact index and allowing the LLM to query for details on demand.

Features

  • Token-Efficient Index: GetIndex() returns a highly compact string (e.g., files(read,write), net(ping)) for the initial context.
  • SQL-Based Discovery: LLMs can query the catalog view to retrieve detailed parameter schemas only when needed.
  • Idempotent Registration: Register() handles upserts and auto-provisions categories.
  • Minimalist Schema: Uses cats, skills, params tables and a catalog view.

Usage

Installation
go get github.com/tinywasm/skill
Initialization

Initialize the store with any *orm.DB connection (e.g., github.com/tinywasm/sqlite).

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/tinywasm/skill"
	"github.com/tinywasm/sqlite"
)

func main() {
	db, _ := sqlite.Open(":memory:") // or file path
	store := skill.NewStore(db)

	// Initialize schema
	// Make sure to create necessary tables and the catalog view using db.ExecSQL
}
Registering Skills
ctx := context.Background()

mySkill := skill.Skill{
    Category: "weather",
    Name:     "check",
    Info:     "Get current weather",
    Parameters: []skill.Parameter{
        {Name: "city", Type: "string", Info: "City name", Required: true},
    },
}

if err := store.Register(ctx, mySkill); err != nil {
    log.Fatal(err)
}
LLM Integration
1. Initial Context

Inject the compact index and instructions into your system prompt.

index, _ := store.GetIndex(ctx)
// index example: "weather(check), files(read,write)"

systemPrompt := fmt.Sprintf(skill.LLMInstruction, index)

The skill.LLMInstruction constant provides the standard prompt:

"Available: [INDEX]. Query catalog table for args schema. Example: SELECT args FROM catalog WHERE name='read';"

2. Skill Discovery

When the LLM needs to use a tool, it can query the catalog view or you can use Search() programmatically.

// Programmatic search
skills, _ := store.Search(ctx, "weather")
3. Execution

The LLM can query for the arguments schema directly:

SELECT args FROM catalog WHERE name='check';

Returns JSON: [{"n":"city","t":"string","r":true,"d":"City name"}]

Schema

  • cats: id, name (unique)
  • skills: id, cat_id, name (unique), info
  • params: id, skill_id, name, type, info, req
  • catalog (VIEW): cat, name, info, args (JSON array of parameters)

Documentation

Overview

Code generated by ormc; DO NOT EDIT. NOTE: Schema() and Values() must always be in the same field order. String PK: set via github.com/tinywasm/unixid before calling db.Create().

Index

Constants

View Source
const LLMInstruction = "Available: %s. Query catalog table for args schema. Example: SELECT args FROM catalog WHERE name='read';"

LLMInstruction is the prompt template for LLMs.

Variables

This section is empty.

Functions

func ReadAllcat added in v0.0.2

func ReadAllcat(qb *orm.QB) ([]*cat, error)

func ReadAllparamModel added in v0.0.2

func ReadAllparamModel(qb *orm.QB) ([]*paramModel, error)

func ReadAllskillModel added in v0.0.2

func ReadAllskillModel(qb *orm.QB) ([]*skillModel, error)

func ReadOnecat added in v0.0.2

func ReadOnecat(qb *orm.QB, model *cat) (*cat, error)

func ReadOneparamModel added in v0.0.2

func ReadOneparamModel(qb *orm.QB, model *paramModel) (*paramModel, error)

func ReadOneskillModel added in v0.0.2

func ReadOneskillModel(qb *orm.QB, model *skillModel) (*skillModel, error)

Types

type Parameter

type Parameter struct {
	Name     string `json:"n"` // Name
	Type     string `json:"t"` // Type
	Info     string `json:"d"` // Description/Info
	Required bool   `json:"r"` // Required
}

Parameter defines an argument for a Skill. JSON tags match the compact format used in the 'catalog' view to save tokens.

type Skill

type Skill struct {
	Name       string      `json:"name"`       // Matches 'name' in catalog
	Category   string      `json:"category"`   // Matches 'cat' in catalog (mapped)
	Info       string      `json:"info"`       // Matches 'info' in catalog
	Parameters []Parameter `json:"parameters"` // Matches 'args' in catalog (mapped)
}

Skill represents a tool available to the LLM.

type Store

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

Store provides access to the skill database.

func NewStore

func NewStore(db *orm.DB) *Store

NewStore creates a new Store with the given database connection.

func (*Store) GetIndex

func (s *Store) GetIndex(ctx context.Context) (string, error)

GetIndex returns a compact string representation of available skills. Format: cat1(skill1,skill2), cat2(skill3)

func (*Store) Register

func (s *Store) Register(ctx context.Context, skill Skill) error

Register adds a new skill or updates an existing one. It is idempotent, auto-creates categories, upserts the skill, and replaces parameters.

func (*Store) Search

func (s *Store) Search(ctx context.Context, query string) ([]Skill, error)

Search queries the catalog view for skills matching the query. It maps the JSON 'args' column to the Skill.Parameters field.

Jump to

Keyboard shortcuts

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