compiled

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package compiled provides interfaces for compiled Go skills.

Compiled skills are Go packages that implement the Skill interface, providing callable tools that the agent can use. Unlike markdown skills (SKILL.md files) which inject instructions into the system prompt, compiled skills register actual functions that the LLM can invoke.

Example Usage

// Import your skill package
import "example.com/myskill"

skill, _ := myskill.New(myskill.Config{...})
agent, _ := agent.New(config,
    agent.WithCompiledSkill(skill),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parameter

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

	// Description explains the parameter. Shown to the LLM.
	Description string `json:"description,omitempty"`

	// Required indicates if this parameter must be provided.
	Required bool `json:"-"`

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

	// Enum restricts values to a specific set.
	Enum []any `json:"enum,omitempty"`

	// Items defines the schema for array elements (when Type is "array").
	Items *Parameter `json:"items,omitempty"`

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

Parameter defines a tool parameter.

type Registry

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

Registry manages compiled skills.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new skill registry.

func (*Registry) All

func (r *Registry) All() []Skill

All returns all registered skills.

func (*Registry) AllTools

func (r *Registry) AllTools() []Tool

AllTools returns all tools from all registered skills.

func (*Registry) CloseAll

func (r *Registry) CloseAll() error

CloseAll closes all registered skills.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the number of registered skills.

func (*Registry) FindTool

func (r *Registry) FindTool(name string) (*Tool, Skill, bool)

FindTool finds a tool by name across all skills.

func (*Registry) Get

func (r *Registry) Get(name string) (Skill, bool)

Get returns a skill by name.

func (*Registry) InitAll

func (r *Registry) InitAll(ctx context.Context) error

InitAll initializes all registered skills.

func (*Registry) InjectStorage

func (r *Registry) InjectStorage(storage Storage)

InjectStorage injects storage into all storage-aware skills.

func (*Registry) Register

func (r *Registry) Register(s Skill) error

Register adds a skill to the registry.

func (*Registry) ToolCount

func (r *Registry) ToolCount() int

ToolCount returns the total number of tools across all skills.

type Skill

type Skill interface {
	// Name returns the skill identifier (e.g., "invest", "weather").
	Name() string

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

	// Tools returns the tools provided by this skill.
	Tools() []Tool

	// Init initializes the skill. Called once when the agent starts.
	Init(ctx context.Context) error

	// Close releases resources. Called when the agent shuts down.
	Close() error
}

Skill is the interface that compiled skills implement.

type SkillInfo

type SkillInfo struct {
	Name        string
	Description string
	ToolCount   int
	Tools       []ToolInfo
}

SkillInfo provides metadata about a skill for introspection.

func Info

func Info(s Skill) SkillInfo

Info returns metadata about the skill.

type Storage

type Storage interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
}

Storage is the storage interface that skills can use. This is a subset of the full storage.Storage interface.

type StorageAware

type StorageAware interface {
	SetStorage(s Storage)
}

StorageAware is an optional interface for skills that need storage. If a skill implements this interface, the agent will inject the storage backend after creation and before Init() is called.

type Tool

type Tool struct {
	// Name is the tool identifier (e.g., "analyze_stock").
	Name string

	// Description explains what the tool does. This is shown to the LLM.
	Description string

	// Parameters defines the tool's input parameters using JSON Schema.
	Parameters map[string]Parameter

	// Handler is the function that executes the tool.
	Handler ToolHandler
}

Tool represents a callable function that the LLM can invoke.

func (*Tool) ToJSONSchema

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

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

type ToolHandler

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

ToolHandler is the function signature for tool implementations.

type ToolInfo

type ToolInfo struct {
	Name        string
	Description string
}

ToolInfo provides metadata about a tool.

Jump to

Keyboard shortcuts

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