tools

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBinary

func IsBinary(data string) bool

IsBinary reports whether data appears to be binary (non-text) content. It samples up to the first 8KB and checks for a high ratio of non-UTF-8 bytes or null bytes, which are reliable indicators of binary data.

func SplitLines

func SplitLines(text string) []string

SplitLines splits text into lines preserving newline suffixes. Trims the trailing empty element that strings.SplitAfter produces.

Types

type Definition

type Definition = ai.ToolDefinition

Definition is a callable tool definition exposed to a model.

type Registry

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

Registry holds named tools and provides lookup + definitions.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty tool registry. Tools are registered externally via Register().

func (*Registry) BuiltinNames

func (r *Registry) BuiltinNames() []string

BuiltinNames returns the names of all currently registered tools.

func (*Registry) Close

func (r *Registry) Close() error

Close shuts down any tools that expose a Close method.

func (*Registry) Definitions

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

Definitions returns all tool definitions for passing to the LLM.

func (*Registry) Execute

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

Execute runs the named tool with given arguments.

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has reports whether the registry contains a tool with the given name.

func (*Registry) Register

func (r *Registry) Register(t Tool)

Register adds a tool to the registry.

type Tool

type Tool interface {
	Definition() Definition
	Execute(ctx context.Context, args map[string]any) (string, error)
}

Tool is a tool that can be executed by the Go runner.

type TruncationResult

type TruncationResult struct {
	Content     string
	OutputLines int
}

TruncationResult holds the truncated output and metadata.

func TruncateHead

func TruncateHead(output string) TruncationResult

TruncateHead keeps the first N lines / bytes (whichever limit is hit first). Suitable for file reads and search results where the beginning matters most.

func TruncateTail

func TruncateTail(output string) TruncationResult

TruncateTail keeps the last N lines / bytes (whichever limit is hit first). Suitable for command output and logs where the end matters most.

Jump to

Keyboard shortcuts

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