tool

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tool provides the tool registry with permissions and approval hooks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApprovalFunc

type ApprovalFunc func(ctx context.Context, toolName string, args map[string]any) (bool, error)

ApprovalFunc is called when a tool requires human approval. It should block until approved/denied and return true if approved.

type Approver added in v0.4.0

type Approver interface {
	RequestApproval(ctx context.Context, toolName string, args map[string]any) (bool, error)
}

Approver is the integration seam a human-in-the-loop approval service (e.g. os/approval) plugs into. An implementation blocks until a tool call is approved or denied — honoring ctx cancellation — and returns true if approved. It is intentionally identical in shape to ApprovalFunc so the control-plane approval service can be wired into the tool path without an adapter.

type Definition

type Definition struct {
	Name                 string         `json:"name"`
	Description          string         `json:"description"`
	Parameters           map[string]any `json:"parameters"` // JSON Schema
	Permission           Permission     `json:"permission"`
	RequiresConfirmation bool           `json:"requires_confirmation,omitempty"`
	RequiresUserInput    bool           `json:"requires_user_input,omitempty"`
	Handler              Handler        `json:"-"`
}

Definition describes a callable tool.

type Handler

type Handler func(ctx context.Context, args map[string]any) (any, error)

Handler is the function signature for tool execution.

type Permission

type Permission string

Permission levels for tool execution.

const (
	PermAllow           Permission = "allow"            // auto-approved
	PermRequireApproval Permission = "require_approval" // needs human approval
	PermDeny            Permission = "deny"             // blocked
)

type Registry

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

Registry manages tool definitions, permissions, and execution.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new tool registry.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, args map[string]any) (any, error)

Execute runs a tool by name, enforcing permissions, confirmation, and user input.

func (*Registry) Get added in v0.3.0

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

Get returns a tool definition by name.

func (*Registry) List

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

List returns all registered tools.

func (*Registry) Register

func (r *Registry) Register(def *Definition)

Register adds a tool definition.

func (*Registry) SetApprovalHandler

func (r *Registry) SetApprovalHandler(fn ApprovalFunc)

SetApprovalHandler sets the function called for tools requiring approval.

func (*Registry) SetApprover added in v0.4.0

func (r *Registry) SetApprover(a Approver)

SetApprover installs an Approver as the approval handler for tools whose Permission is PermRequireApproval (and for RequiresConfirmation tools). It is a convenience over SetApprovalHandler for the common case of connecting the control-plane approval service (os/approval) into the tool execution path. A nil approver clears any installed handler.

func (*Registry) SetUserInputHandler added in v0.3.0

func (r *Registry) SetUserInputHandler(fn UserInputFunc)

SetUserInputHandler sets the function called for tools requiring user input.

type Toolkit added in v0.3.0

type Toolkit struct {
	Name        string        `json:"name"`
	Description string        `json:"description"`
	Permission  Permission    `json:"permission"`
	Tools       []*Definition `json:"tools"`
	Enabled     bool          `json:"enabled"`
}

Toolkit groups related tool definitions with shared metadata.

func NewToolkit added in v0.3.0

func NewToolkit(name, description string) *Toolkit

NewToolkit creates a new toolkit with the given name.

func (*Toolkit) Add added in v0.3.0

func (tk *Toolkit) Add(def *Definition) *Toolkit

Add adds a tool definition to the toolkit.

func (*Toolkit) Disable added in v0.3.0

func (tk *Toolkit) Disable()

Disable disables the toolkit.

func (*Toolkit) Enable added in v0.3.0

func (tk *Toolkit) Enable()

Enable enables the toolkit.

func (*Toolkit) Register added in v0.3.0

func (tk *Toolkit) Register(registry *Registry)

Register registers all tools from this toolkit into the given registry. If the toolkit is disabled, no tools are registered.

func (*Toolkit) ToolNames added in v0.3.0

func (tk *Toolkit) ToolNames() []string

ToolNames returns the names of all tools in the toolkit.

func (*Toolkit) WithPermission added in v0.3.0

func (tk *Toolkit) WithPermission(p Permission) *Toolkit

WithPermission sets the default permission for all tools in the toolkit.

type UserInputFunc added in v0.3.0

type UserInputFunc func(ctx context.Context, toolName string, prompt string) (string, error)

UserInputFunc is called when a tool needs user input before executing. It should block until input is provided and return the input string.

Directories

Path Synopsis
Package builtins provides ready-to-use tool implementations.
Package builtins provides ready-to-use tool implementations.

Jump to

Keyboard shortcuts

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