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 ¶
const ( ExecutionModeAuto = ports.ExecutionModeAuto ExecutionModeParallel = ports.ExecutionModeParallel ExecutionModeSequential = ports.ExecutionModeSequential ExecutionModeExclusive = ports.ExecutionModeExclusive )
Variables ¶
var ( ErrToolInputInvalid = ports.ErrToolInputInvalid ErrToolSchemaInvalid = ports.ErrToolSchemaInvalid ErrToolExecutionFailed = errors.New("tool execution failed") ErrToolTimeout = errors.New("tool timeout") )
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 Execution ¶
type Execution = ports.ToolExecution
type ExecutionMode ¶
type ExecutionMode = ports.ExecutionMode
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
func NewExecutor ¶
type Middleware ¶
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
type Result ¶
type Result = ports.ToolResult
type Schema ¶
type Schema = ports.ToolSchema