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 ¶
ParameterToSchema converts a Parameter to JSON Schema format.
Types ¶
type BaseSkill ¶
BaseSkill provides a minimal Skill implementation that can be embedded. It implements all Skill methods with sensible defaults.
func (*BaseSkill) Description ¶
Description returns the skill description.
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 (*FuncTool) Description ¶
Description returns the tool description.
func (*FuncTool) Parameters ¶
Parameters returns the tool parameters.
func (*FuncTool) ToJSONSchema ¶
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
}