tools

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Global = &Registry{tools: make(map[string]Tool)}

Functions

func CanonicalName

func CanonicalName(name string) string

CanonicalName returns the provider-safe tool name used when exposing tools to LLM APIs that reject dots in function names.

func Index

func Index(manifests []ToolManifest) string

Index renders manifests as a catalogue, one line per tool, sorted so the text is byte-identical between turns — a prefix that reorders itself cannot be cached.

func IsAgentScoped

func IsAgentScoped(name string) bool

IsAgentScoped reports whether name refers to a tool that is injected per-agent at runtime instead of being registered globally.

func Summarize

func Summarize(desc string) string

Summarize reduces a tool description to its first sentence, bounded.

Descriptions run to ten lines with worked examples — useful when the model is about to call the tool, noise when it is only deciding whether to ask for it.

Types

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Get

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

func (*Registry) List

func (r *Registry) List() []ToolManifest

func (*Registry) Register

func (r *Registry) Register(t Tool)

func (*Registry) ResolveForAgent

func (r *Registry) ResolveForAgent(names []string) (resolved []Tool, unresolved []string)

ResolveForAgent resolves the named tools from the registry. Names that are not present are returned in unresolved rather than causing a hard failure, so a single typo (or an agent-scoped tool name) no longer wipes out an agent's entire toolset. The caller decides how to report unresolved names.

type Tool

type Tool interface {
	Manifest() ToolManifest
	Execute(ctx context.Context, input map[string]any) (ToolResult, error)
}

type ToolManifest

type ToolManifest struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

type ToolResult

type ToolResult struct {
	Output  any    `json:"output"`
	Error   string `json:"error,omitempty"`
	IsError bool   `json:"is_error"`
}

func ErrorResult

func ErrorResult(err error) ToolResult

func SuccessResult

func SuccessResult(output any) ToolResult

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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