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 ¶
- type Category
- type ErrExecutionFailed
- type ErrInvalidInput
- type ErrOutputTooLarge
- type ErrPermissionDenied
- type ErrTimeout
- type ErrToolConflict
- type ErrToolNotFound
- type ExecutionContext
- type ExecutionOption
- func WithAllowedPaths(paths []string) ExecutionOption
- func WithDryRun(dryRun bool) ExecutionOption
- func WithEnvironment(env map[string]string) ExecutionOption
- func WithMaxOutputSize(size int64) ExecutionOption
- func WithTimeout(timeout time.Duration) ExecutionOption
- func WithWorkingDirectory(dir string) ExecutionOption
- type PropertyDef
- type Registry
- func (r *Registry) Execute(ctx context.Context, toolName string, input map[string]interface{}, ...) (*Result, error)
- func (r *Registry) Get(name string) (Tool, error)
- func (r *Registry) List() []Tool
- func (r *Registry) ListByCategory(category Category) []Tool
- func (r *Registry) Register(tool Tool) error
- func (r *Registry) Schemas() map[string]ToolSchema
- func (r *Registry) Unregister(name string) error
- type Result
- type Tool
- type ToolSchema
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrExecutionFailed ¶
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 ¶
ErrInvalidInput is returned when tool input validation fails.
func (*ErrInvalidInput) Error ¶
func (e *ErrInvalidInput) Error() string
type ErrOutputTooLarge ¶
ErrOutputTooLarge is returned when tool output exceeds the maximum allowed size.
func (*ErrOutputTooLarge) Error ¶
func (e *ErrOutputTooLarge) Error() string
type ErrPermissionDenied ¶
ErrPermissionDenied is returned when a tool operation is not permitted.
func (*ErrPermissionDenied) Error ¶
func (e *ErrPermissionDenied) Error() string
type ErrTimeout ¶
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 (*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 ¶
Get retrieves a tool by name. Returns ErrToolNotFound if the tool is not registered.
func (*Registry) ListByCategory ¶
ListByCategory returns all tools in a specific category.
func (*Registry) Register ¶
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 ¶
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.