tool

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 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 Definition

type Definition struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Parameters  map[string]any `json:"parameters"` // JSON Schema
	Permission  Permission     `json:"permission"`
	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 and approval.

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.

Jump to

Keyboard shortcuts

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