tool

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tool holds the registry of actions the agent may take. Every tool declares a capability class so the policy layer can gate whole categories without knowing individual tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp added in v0.2.5

func Clamp(s string, max int, advice string) string

Clamp bounds an oversized text result by keeping the head and the tail and eliding the middle on line boundaries. A long result front-loads its frame (the command, the first error) and back-loads its verdict (the assertion, the summary line), so a head-only cut throws away the verdict and a tail-only cut throws away the frame; keeping both ends preserves the signal at the same token budget. Three quarters of max goes to the head, the rest to the tail, and both cut points back off to line boundaries so the elision never splits a line. The note in the middle names how many bytes were dropped; advice, when non-empty, is appended to the note to tell the model how to see the elided part (it should start with "; ").

Types

type Class

type Class string

Class is what a tool is allowed to touch, from the policy engine's point of view. One class per tool, the strongest thing it does.

const (
	ClassRead  Class = "read"  // reads local state
	ClassNet   Class = "net"   // talks to the network
	ClassWrite Class = "write" // mutates local state
	ClassExec  Class = "exec"  // runs arbitrary code
)

type Registry

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

Registry is an ordered set of tools. The zero value and the nil pointer are both empty, usable registries.

func NewRegistry

func NewRegistry(tools ...Tool) *Registry

NewRegistry builds a registry from tools, keeping order.

func (*Registry) Add

func (r *Registry) Add(t Tool)

Add appends a tool, replacing any existing tool of the same name.

func (*Registry) Defs

func (r *Registry) Defs() []provider.Tool

Defs renders the registry the way a model request wants it.

func (*Registry) Get

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

Get looks a tool up by name.

type Tool

type Tool struct {
	Name        string
	Description string
	Class       Class
	Schema      json.RawMessage
	Run         func(ctx context.Context, input json.RawMessage) (string, error)
}

Tool is one callable action.

Jump to

Keyboard shortcuts

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