Help us shape the future of Go! Take the 2026 Go Developer Survey

tools

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Overview

Package tools defines tool specifications, registries, middleware, and executors.

A Tool is a host-owned typed action. Keep tools focused on one operation and describe their boundary in Spec. Permission declares whether the operation is read, write, or exec so policy can approve it. ExecutionMode controls scheduling: read tools run in parallel by default, while write, exec, empty, and unknown permissions run sequentially unless explicitly marked parallel. Schema validates model-supplied JSON before the tool body runs. Timeout bounds tool and middleware execution.

Tool results separate model-visible and host-visible output. ForLLM is the observation appended to model context. ForUser is available to host and UI surfaces. Ref can point to a host-owned artifact, and Metadata can carry small structured facts about that artifact. Silent replaces a successful result's content in model context with a short acknowledgement. IsError marks a recoverable domain error the model can correct on a later turn. Return a Go error for executor failures that should abort the run. A panicking tool is reported as ErrToolExecutionFailed instead of crashing the process.

Missing tools and common executor failures return errors classifiable with errors.Is: ErrToolNotFound, ErrToolInputInvalid, ErrToolSchemaInvalid, ErrToolExecutionFailed, and ErrToolTimeout.

Index

Constants

View Source
const (
	ExecutionModeAuto       = ports.ExecutionModeAuto
	ExecutionModeParallel   = ports.ExecutionModeParallel
	ExecutionModeSequential = ports.ExecutionModeSequential
	ExecutionModeExclusive  = ports.ExecutionModeExclusive
)

Variables

View Source
var (
	ErrToolInputInvalid    = ports.ErrToolInputInvalid
	ErrToolSchemaInvalid   = ports.ErrToolSchemaInvalid
	ErrToolExecutionFailed = errors.New("tool execution failed")
	ErrToolTimeout         = errors.New("tool timeout")
)
View Source
var ErrToolNotFound = errors.New("tool not found")

Functions

func ValidateInput

func ValidateInput(schema Schema, input json.RawMessage) error

ValidateInput checks model-supplied input against a tool schema. Errors wrap ErrToolInputInvalid when the input is at fault and ErrToolSchemaInvalid when the schema itself is broken.

Types

type Call

type Call = ports.ToolCall

type Env

type Env = ports.ToolEnv

type Execution

type Execution = ports.ToolExecution

type ExecutionMode

type ExecutionMode = ports.ExecutionMode

type Executor

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

func NewExecutor

func NewExecutor(registry interface {
	MustGet(name string) (Tool, error)
}) *Executor

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, calls []Call, env Env) ([]Execution, error)

type Handler

type Handler func(ctx context.Context, input json.RawMessage, env Env) (*Result, error)

type Middleware

type Middleware func(Handler) Handler

func Chain

func Chain(middlewares ...Middleware) Middleware

func OutputMask

func OutputMask(mask func(*Result) *Result) Middleware

func SchemaValidator

func SchemaValidator(schema Schema) Middleware

type MiddlewareProvider

type MiddlewareProvider interface {
	Middleware() []Middleware
}

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Clone

func (r *Registry) Clone() *Registry

func (*Registry) Get

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

func (*Registry) MustGet

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

func (*Registry) Register

func (r *Registry) Register(tool Tool)

func (*Registry) Specs

func (r *Registry) Specs() []Spec

type Result

type Result = ports.ToolResult

type Schema

type Schema = ports.ToolSchema

type Spec

type Spec = ports.ToolSpec

type Tool

type Tool = ports.Tool

Jump to

Keyboard shortcuts

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