skill

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package skill defines the core interfaces for skills and tools.

A Skill is a named collection of related tools. Skills can be:

  • Built natively in Go
  • Imported from MCP servers
  • Generated from OpenAPI specifications

Skills are the primary abstraction in omniskill, enabling "define once, deploy everywhere" across MCP, compiled Go, and other formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParameterToSchema

func ParameterToSchema(p Parameter) map[string]any

ParameterToSchema converts a Parameter to JSON Schema format.

func ParametersToJSONSchema

func ParametersToJSONSchema(params map[string]Parameter) map[string]any

ParametersToJSONSchema converts a parameter map to JSON Schema format.

Types

type BaseSkill

type BaseSkill struct {
	SkillName        string
	SkillDescription string
	SkillTools       []Tool
}

BaseSkill provides a minimal Skill implementation that can be embedded. It implements all Skill methods with sensible defaults.

func (*BaseSkill) Close

func (s *BaseSkill) Close() error

Close is a no-op by default.

func (*BaseSkill) Description

func (s *BaseSkill) Description() string

Description returns the skill description.

func (*BaseSkill) Init

func (s *BaseSkill) Init(ctx context.Context) error

Init is a no-op by default.

func (*BaseSkill) Name

func (s *BaseSkill) Name() string

Name returns the skill name.

func (*BaseSkill) Tools

func (s *BaseSkill) Tools() []Tool

Tools returns the skill's tools.

type CommandResult added in v0.8.0

type CommandResult struct {
	// Stdout contains the standard output.
	Stdout string `json:"stdout"`

	// Stderr contains the standard error.
	Stderr string `json:"stderr"`

	// ExitCode is the command's exit code.
	ExitCode int `json:"exit_code"`
}

CommandResult contains the output of a command execution.

func (CommandResult) String added in v0.8.0

func (r CommandResult) String() string

String returns the stdout if successful, or stderr if failed.

type CommandTool added in v0.8.0

type CommandTool struct {
	// ToolName is the tool identifier.
	ToolName string

	// ToolDescription describes what the tool does.
	ToolDescription string

	// Command is the executable name or path.
	Command string

	// Args are the command arguments. Use {{paramName}} for parameter substitution.
	Args []string

	// ToolParameters defines the tool's input parameters.
	ToolParameters map[string]Parameter

	// WorkingDir is the working directory for command execution.
	// If empty, uses the current directory.
	WorkingDir string

	// Timeout is the maximum execution time. Zero means no timeout.
	Timeout time.Duration

	// Env contains additional environment variables.
	Env []string
}

CommandTool wraps a CLI command as a Tool.

CommandTool enables SKILL.md-defined commands to be exposed as standard Tools, bridging the gap between markdown-based skill definitions and the structured Tool interface.

Example:

tool := &CommandTool{
    ToolName:        "search",
    ToolDescription: "Search the archive",
    Command:         "notcrawl",
    Args:            []string{"search", "{{query}}"},
    ToolParameters: map[string]Parameter{
        "query": {Type: "string", Description: "Search query", Required: true},
    },
}

func NewCommandTool added in v0.8.0

func NewCommandTool(name, description, command string, args []string, params map[string]Parameter) *CommandTool

NewCommandTool creates a CommandTool with common defaults.

func (*CommandTool) Call added in v0.8.0

func (t *CommandTool) Call(ctx context.Context, params map[string]any) (any, error)

Call executes the command with the given parameters.

func (*CommandTool) Description added in v0.8.0

func (t *CommandTool) Description() string

Description returns the tool description.

func (*CommandTool) Name added in v0.8.0

func (t *CommandTool) Name() string

Name returns the tool name.

func (*CommandTool) Parameters added in v0.8.0

func (t *CommandTool) Parameters() map[string]Parameter

Parameters returns the tool parameters.

type FuncTool

type FuncTool struct {
	ToolName        string
	ToolDescription string
	ToolParameters  map[string]Parameter
	Handler         ToolFunc
}

FuncTool wraps a function as a Tool. This is useful for creating simple tools without implementing the full interface.

func NewTool

func NewTool(name, description string, params map[string]Parameter, handler ToolFunc) *FuncTool

NewTool creates a new FuncTool with the given properties.

func (*FuncTool) Call

func (t *FuncTool) Call(ctx context.Context, params map[string]any) (any, error)

Call executes the tool handler.

func (*FuncTool) Description

func (t *FuncTool) Description() string

Description returns the tool description.

func (*FuncTool) Name

func (t *FuncTool) Name() string

Name returns the tool name.

func (*FuncTool) Parameters

func (t *FuncTool) Parameters() map[string]Parameter

Parameters returns the tool parameters.

func (*FuncTool) ToJSONSchema

func (t *FuncTool) ToJSONSchema() map[string]any

ToJSONSchema converts the tool's parameters to JSON Schema format compatible with OpenAI/Anthropic function calling.

type Parameter

type Parameter struct {
	// Type is the JSON Schema type: "string", "number", "integer", "boolean", "object", "array".
	Type string `json:"type"`

	// Description explains what the parameter is for.
	Description string `json:"description,omitempty"`

	// Required indicates whether the parameter must be provided.
	Required bool `json:"required,omitempty"`

	// Enum lists the allowed values for this parameter.
	Enum []any `json:"enum,omitempty"`

	// Default is the default value if not provided.
	Default any `json:"default,omitempty"`

	// Items describes array element type (when Type is "array").
	Items *Parameter `json:"items,omitempty"`

	// Properties describes object properties (when Type is "object").
	Properties map[string]Parameter `json:"properties,omitempty"`
}

Parameter describes a tool parameter.

Parameters follow JSON Schema conventions for describing input types.

type Skill

type Skill interface {
	// Name returns the skill identifier (e.g., "github", "weather").
	// Names should be lowercase, alphanumeric with underscores.
	Name() string

	// Description returns a human-readable description of what the skill does.
	Description() string

	// Tools returns the tools provided by this skill.
	// This may be called multiple times and should return consistent results
	// after Init() completes.
	Tools() []Tool

	// Init initializes the skill before use.
	// Called once when the skill is registered. Use this to establish
	// connections, load configuration, or perform other setup.
	Init(ctx context.Context) error

	// Close releases any resources held by the skill.
	// Called when the skill is unregistered or the application shuts down.
	Close() error
}

Skill represents a named collection of related tools.

Skills encapsulate a logical grouping of functionality (e.g., "github", "weather", "database") and provide lifecycle management via Init/Close.

Example implementation:

type WeatherSkill struct {
    apiKey string
    client *http.Client
}

func (s *WeatherSkill) Name() string        { return "weather" }
func (s *WeatherSkill) Description() string { return "Weather forecasts and conditions" }
func (s *WeatherSkill) Tools() []Tool       { return []Tool{s.getCurrentWeather(), s.getForecast()} }
func (s *WeatherSkill) Init(ctx context.Context) error { s.client = &http.Client{}; return nil }
func (s *WeatherSkill) Close() error        { return nil }

type Tool

type Tool interface {
	// Name returns the tool identifier (e.g., "get_current_weather").
	// Names should be lowercase, alphanumeric with underscores.
	Name() string

	// Description returns a human-readable description of what the tool does.
	// This is used by AI models to understand when to use the tool.
	Description() string

	// Parameters returns the JSON Schema-like parameter definitions.
	// The map keys are parameter names.
	Parameters() map[string]Parameter

	// Call executes the tool with the given parameters.
	// Parameters have already been validated against the schema.
	// Returns the tool output or an error.
	Call(ctx context.Context, params map[string]any) (any, error)
}

Tool represents a single callable function within a skill.

Tools are the atomic unit of functionality. Each tool has:

  • A unique name within its skill
  • A description for AI models to understand its purpose
  • Parameters describing its inputs
  • A handler that executes the tool logic

Example implementation:

type GetWeatherTool struct{}

func (t *GetWeatherTool) Name() string        { return "get_current_weather" }
func (t *GetWeatherTool) Description() string { return "Get the current weather for a location" }
func (t *GetWeatherTool) Parameters() map[string]Parameter {
    return map[string]Parameter{
        "location": {Type: "string", Description: "City name", Required: true},
        "units":    {Type: "string", Description: "Temperature units", Enum: []any{"celsius", "fahrenheit"}},
    }
}
func (t *GetWeatherTool) Call(ctx context.Context, params map[string]any) (any, error) {
    location := params["location"].(string)
    // ... fetch weather ...
    return map[string]any{"temperature": 72, "condition": "sunny"}, nil
}

type ToolFunc

type ToolFunc func(ctx context.Context, params map[string]any) (any, error)

ToolFunc is a function type that can be used as a tool handler.

Jump to

Keyboard shortcuts

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