tools

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package tools provides an extensible tool execution framework for LLM assistants.

Package tools provides an extensible tool execution framework for LLM assistants.

Package tools provides an extensible tool execution framework for LLM assistants.

Package tools provides an extensible tool execution framework for LLM assistants.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category represents the category of a tool.

const (
	CategoryFilesystem Category = "filesystem"
	CategoryNetwork    Category = "network"
	CategorySystem     Category = "system"
	CategoryDatabase   Category = "database"
	CategoryText       Category = "text"
)

type ErrExecutionFailed

type ErrExecutionFailed struct {
	ToolName string
	Reason   string
	Cause    error
}

ErrExecutionFailed is returned when tool execution fails.

func (*ErrExecutionFailed) Error

func (e *ErrExecutionFailed) Error() string

func (*ErrExecutionFailed) Unwrap

func (e *ErrExecutionFailed) Unwrap() error

type ErrInvalidInput

type ErrInvalidInput struct {
	ToolName string
	Field    string
	Reason   string
}

ErrInvalidInput is returned when tool input validation fails.

func (*ErrInvalidInput) Error

func (e *ErrInvalidInput) Error() string

type ErrOutputTooLarge

type ErrOutputTooLarge struct {
	ToolName   string
	OutputSize int64
	MaxSize    int64
}

ErrOutputTooLarge is returned when tool output exceeds the maximum allowed size.

func (*ErrOutputTooLarge) Error

func (e *ErrOutputTooLarge) Error() string

type ErrPermissionDenied

type ErrPermissionDenied struct {
	ToolName  string
	Operation string
	Resource  string
	Reason    string
}

ErrPermissionDenied is returned when a tool operation is not permitted.

func (*ErrPermissionDenied) Error

func (e *ErrPermissionDenied) Error() string

type ErrTimeout

type ErrTimeout struct {
	ToolName string
	Duration string
}

ErrTimeout is returned when tool execution exceeds the timeout.

func (*ErrTimeout) Error

func (e *ErrTimeout) Error() string

type ErrToolConflict

type ErrToolConflict struct {
	ToolName string
}

ErrToolConflict is returned when attempting to register a tool with a name that already exists.

func (*ErrToolConflict) Error

func (e *ErrToolConflict) Error() string

type ErrToolNotFound

type ErrToolNotFound struct {
	ToolName string
}

ErrToolNotFound is returned when a requested tool is not registered.

func (*ErrToolNotFound) Error

func (e *ErrToolNotFound) Error() string

type ExecutionContext

type ExecutionContext struct {
	Timeout          time.Duration
	WorkingDirectory string
	Environment      map[string]string
	AllowedPaths     []string // For sandboxing file operations
	MaxOutputSize    int64    // Maximum output size in bytes
	DryRun           bool     // If true, don't actually execute, just validate
}

ExecutionContext contains settings for tool execution.

func NewExecutionContext

func NewExecutionContext(opts ...ExecutionOption) *ExecutionContext

NewExecutionContext creates a new ExecutionContext with default values.

type ExecutionOption

type ExecutionOption func(*ExecutionContext)

ExecutionOption is a function that configures an ExecutionContext.

func WithAllowedPaths

func WithAllowedPaths(paths []string) ExecutionOption

WithAllowedPaths sets the allowed paths for file operations (sandboxing).

func WithDryRun

func WithDryRun(dryRun bool) ExecutionOption

WithDryRun enables or disables dry-run mode.

func WithEnvironment

func WithEnvironment(env map[string]string) ExecutionOption

WithEnvironment sets environment variables for execution.

func WithMaxOutputSize

func WithMaxOutputSize(size int64) ExecutionOption

WithMaxOutputSize sets the maximum output size in bytes.

func WithTimeout

func WithTimeout(timeout time.Duration) ExecutionOption

WithTimeout sets the execution timeout.

func WithWorkingDirectory

func WithWorkingDirectory(dir string) ExecutionOption

WithWorkingDirectory sets the working directory for execution.

type PropertyDef

type PropertyDef struct {
	Type        string      `json:"type"`
	Description string      `json:"description"`
	Enum        []string    `json:"enum,omitempty"`
	Default     interface{} `json:"default,omitempty"`
	MinLength   *int        `json:"minLength,omitempty"`
	MaxLength   *int        `json:"maxLength,omitempty"`
	Pattern     string      `json:"pattern,omitempty"`
}

PropertyDef defines a property in the tool schema.

type Registry

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

Registry manages tool registration and execution with thread safety.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new Registry instance.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, toolName string, input map[string]interface{}, execCtx *ExecutionContext) (*Result, error)

Execute executes a tool with the provided input and execution context. This method handles validation, timeout enforcement, and error handling.

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, error)

Get retrieves a tool by name. Returns ErrToolNotFound if the tool is not registered.

func (*Registry) List

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

List returns all registered tools.

func (*Registry) ListByCategory

func (r *Registry) ListByCategory(category Category) []Tool

ListByCategory returns all tools in a specific category.

func (*Registry) Register

func (r *Registry) Register(tool Tool) error

Register registers a new tool in the registry. Returns ErrToolConflict if a tool with the same name is already registered.

func (*Registry) Schemas

func (r *Registry) Schemas() map[string]ToolSchema

Schemas returns a map of tool names to their schemas.

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a tool from the registry. Returns ErrToolNotFound if the tool is not registered.

type Result

type Result struct {
	Success  bool                   `json:"success"`
	Output   string                 `json:"output"`
	Error    error                  `json:"error,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Result represents the result of a tool execution.

type Tool

type Tool interface {
	// Name returns the unique name of the tool.
	Name() string

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

	// Schema returns the JSON schema for the tool's input parameters.
	Schema() ToolSchema

	// Execute runs the tool with the provided input and returns the result.
	Execute(ctx context.Context, input map[string]interface{}) (*Result, error)

	// Category returns the category this tool belongs to.
	Category() Category

	// RequiresConfirmation returns true if this tool requires user confirmation before execution.
	RequiresConfirmation() bool
}

Tool defines the interface that all tools must implement.

type ToolSchema

type ToolSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]PropertyDef `json:"properties"`
	Required   []string               `json:"required,omitempty"`
}

ToolSchema defines the JSON schema for tool input validation.

type Validator

type Validator struct{}

Validator validates tool input against JSON schemas.

func NewValidator

func NewValidator() *Validator

NewValidator creates a new Validator instance.

func (*Validator) Validate

func (v *Validator) Validate(schema ToolSchema, input map[string]interface{}) error

Validate validates the input against the provided schema.

Directories

Path Synopsis
Package builtin provides built-in tools for the tool execution framework.
Package builtin provides built-in tools for the tool execution framework.

Jump to

Keyboard shortcuts

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