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 ¶
- func BoolArg(args map[string]any, key string, def bool) bool
- func DetectSystemManager() string
- func FloatArg(args map[string]any, key string, def float64) float64
- func IntArg(args map[string]any, key string, def int) int
- func SchemaStrings(raw any) []string
- func StringArg(args map[string]any, key string) string
- func ValidateArgs(schema, args map[string]any) error
- func WithToolContext(ctx context.Context, tc ToolContext) context.Context
- type ExecTool
- type PathGuard
- type PkgInstallTool
- type Registry
- func (r *Registry) Definitions() []provider.ToolDefinition
- func (r *Registry) Execute(ctx context.Context, name string, args map[string]any) (result *Result)
- func (r *Registry) Get(name string) (Tool, bool)
- func (r *Registry) Names() []string
- func (r *Registry) Register(ts ...Tool)
- func (r *Registry) Unregister(names ...string)
- type Result
- type Tool
- type ToolContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 SchemaStrings ¶ added in v0.3.0
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 ValidateArgs ¶
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 (*ExecTool) Description ¶
func (*ExecTool) Parameters ¶
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 (*PathGuard) CheckWrite ¶
CheckWrite resolves and authorizes a write.
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) 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 (*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 ¶
Execute runs a tool call end to end. It never panics and never returns nil.
func (*Registry) Register ¶
Register adds a tool unless the user disabled it. Registering the same name twice replaces the earlier tool (later registrations win).
func (*Registry) Unregister ¶
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.
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 ¶
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 ¶
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 ¶
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