tools

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package tools defines the tool seam and the built-in arsenal. New tools implement Tool and register in one line; the user curates the set via config (tools.disabled). Packages with heavier dependencies (memory, mcp, cron) define their tools locally and register them at the composition root.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolArg

func BoolArg(args map[string]any, key string, def bool) bool

func DetectSystemManager

func DetectSystemManager() string

DetectSystemManager returns the system package manager available on this machine ("" when none of the supported ones is installed). The wizard uses it to name the exact packages a distribution needs.

func FloatArg

func FloatArg(args map[string]any, key string, def float64) float64

func IntArg

func IntArg(args map[string]any, key string, def int) int

func SchemaStrings added in v0.3.0

func SchemaStrings(raw any) []string

SchemaStrings reads a schema's string list (required, enum) from either a JSON-decoded []any or a hand-written Go []string, so a tool cannot silently lose validation by writing its schema in the other shape.

func StringArg

func StringArg(args map[string]any, key string) string

func ValidateArgs

func ValidateArgs(schema, args map[string]any) error

ValidateArgs checks required fields, primitive types, and string enums against a JSON schema fragment. It is intentionally minimal: enough to catch the common LLM mistakes (missing field, wrong type, invented enum value) with messages the model can act on without another round trip.

func WithToolContext

func WithToolContext(ctx context.Context, tc ToolContext) context.Context

Types

type ExecTool

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

func NewExecTool

func NewExecTool(guard *PathGuard, timeout time.Duration, enableDeny bool, customDeny []string) (*ExecTool, error)

func (*ExecTool) Description

func (t *ExecTool) Description() string

func (*ExecTool) Execute

func (t *ExecTool) Execute(ctx context.Context, args map[string]any) *Result

func (*ExecTool) Name

func (t *ExecTool) Name() string

func (*ExecTool) Parameters

func (t *ExecTool) Parameters() map[string]any

type PathGuard

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

PathGuard enforces the workspace restriction for file access. It is a guardrail against accidents and prompt-injected mischief, not a sandbox.

func NewPathGuard

func NewPathGuard(workspace string, restrict, allowReadOutside bool, allowPaths []string) *PathGuard

func (*PathGuard) CheckRead

func (g *PathGuard) CheckRead(path string) (string, error)

CheckRead resolves and authorizes a read.

func (*PathGuard) CheckWrite

func (g *PathGuard) CheckWrite(path string) (string, error)

CheckWrite resolves and authorizes a write.

func (*PathGuard) Resolve

func (g *PathGuard) Resolve(path string) (string, error)

Resolve makes a path absolute (relative paths are workspace-relative) and normalizes symlinks in the existing portion so links cannot escape.

func (*PathGuard) Workspace

func (g *PathGuard) Workspace() string

type PkgInstallTool

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

PkgInstallTool installs software so the agent can extend its own environment (e.g. `pip install smrti`, MCP servers, CLI utilities).

func NewPkgInstallTool

func NewPkgInstallTool() *PkgInstallTool

func (*PkgInstallTool) Description

func (t *PkgInstallTool) Description() string

func (*PkgInstallTool) Execute

func (t *PkgInstallTool) Execute(ctx context.Context, args map[string]any) *Result

func (*PkgInstallTool) Name

func (t *PkgInstallTool) Name() string

func (*PkgInstallTool) Parameters

func (t *PkgInstallTool) Parameters() map[string]any

type Registry

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

Registry holds the active tool arsenal. It applies the user's disabled list, validates arguments against each tool's JSON schema, recovers tool panics, and filters secrets out of tool output.

func NewRegistry

func NewRegistry(enabled func(string) bool, filter func(string) string) *Registry

func (*Registry) Definitions

func (r *Registry) Definitions() []provider.ToolDefinition

Definitions returns the schema list sent to the LLM, sorted for stable prompts (stability helps provider-side prompt caching).

func (*Registry) Execute

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

Execute runs a tool call end to end. It never panics and never returns nil.

func (*Registry) Get

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

func (*Registry) Names

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

func (*Registry) Register

func (r *Registry) Register(ts ...Tool)

Register adds a tool unless the user disabled it. Registering the same name twice replaces the earlier tool (later registrations win).

func (*Registry) Unregister

func (r *Registry) Unregister(names ...string)

Unregister removes tools by name (used when an MCP server goes away).

type Result

type Result struct {
	ForLLM  string // fed back into the model (secret-filtered by the registry)
	ForUser string // optional direct user-visible note
	IsError bool
	// Images are shown to the model alongside ForLLM (an annotated
	// screenshot from screen_view, say). The agent loop attaches them to
	// the in-flight turn only: pruned once newer frames arrive, never
	// persisted to session history.
	Images []provider.ImagePart
}

Result separates what the LLM sees from what the user sees.

func Errorf

func Errorf(f string, a ...any) *Result

func Text

func Text(s string) *Result

func Textf

func Textf(f string, a ...any) *Result

type Tool

type Tool interface {
	Name() string
	Description() string
	Parameters() map[string]any // JSON Schema
	Execute(ctx context.Context, args map[string]any) *Result
}

Tool is the single seam every capability implements.

func NewConfigTools

func NewConfigTools(cfg *config.Config) []Tool

NewConfigTools lets the agent inspect and modify its own configuration. Both tools operate on the config FILE (the live in-memory config is immutable while running): reads are secret-redacted, writes are schema-validated, persisted atomically, and apply on restart.

func NewFSTools

func NewFSTools(guard *PathGuard) []Tool

NewFSTools returns the file tools bound to one path guard.

func NewWebTools

func NewWebTools() []Tool

NewWebTools returns web_fetch and web_search (DuckDuckGo HTML, no API key).

type ToolContext

type ToolContext struct {
	Channel    string
	ChatID     string
	SessionKey string
}

ToolContext carries request-scoped routing data to tools that need it (e.g. cron capturing the channel a job was created from).

func ToolContextFrom

func ToolContextFrom(ctx context.Context) ToolContext

Jump to

Keyboard shortcuts

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