Documentation
¶
Overview ¶
Package tool defines the fat-tool abstraction the agent exposes to the model: one tool per domain, each taking an (action, params) pair. It also holds the shared helpers — argument validation, parameter coercion, and the typed ToolError used for host-level failures.
Index ¶
- func Bool(p map[string]any, key string) bool
- func Int(p map[string]any, key string, def int) int
- func Str(p map[string]any, key string) string
- type Action
- type Approver
- type Args
- type Domain
- type DomainSpec
- type MCPCallFunc
- type MCPListFunc
- type MCPSchemaFunc
- type Param
- type Registry
- type Result
- type SkillSource
- type Snapshotter
- type SpawnFunc
- type Tool
- func NewAgent(spawn, spawnBg SpawnFunc) Tool
- func NewCalc() Tool
- func NewFile(p *policy.Engine, ap Approver, snap Snapshotter) Tool
- func NewGit(p *policy.Engine, ap Approver) Tool
- func NewHelp(kb *knowledge.KB, usage func(domain string) string) Tool
- func NewMCP(list MCPListFunc, call MCPCallFunc, schema MCPSchemaFunc) Tool
- func NewRun(p *policy.Engine, ap Approver, defaultTimeout time.Duration) Tool
- func NewSkill(src SkillSource) Tool
- func NewWeb(hc *http.Client, offline bool) Tool
- type ToolError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool reads a boolean param, tolerating the string and numeric forms weak models emit ("true"/"yes"/"1", or a non-zero number) instead of a real JSON bool. Missing or unrecognized → false.
Types ¶
type Action ¶
type Action struct {
Name string
Note string // optional one-line note appended to the generated help
Mutates bool // changes state (write/run/git) — blocked in plan mode
Params []Param
Run func(ctx context.Context, a Args) Result
}
Action is one operation: its declared params and its handler. The handler runs only after the required params have been validated.
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
Args is a typed accessor over the (already validated) params handed to a handler.
type Domain ¶
type Domain struct {
// contains filtered or unexported fields
}
Domain is the universal tool object (MCP-style): standard methods — schema/help (Description), action list, and dispatch (Call) — generated from a declarative spec. Adding a tool or action is data, not a switch statement, and the schema can't fall out of sync with the handlers.
func NewDomain ¶
func NewDomain(spec DomainSpec) *Domain
NewDomain builds a Domain from its spec. *Domain implements Tool.
func (*Domain) Call ¶
Call validates the action's required params (from its declaration) and then runs the handler. The registry already guarantees the action exists.
func (*Domain) Description ¶
Description is generated from the action declarations.
type DomainSpec ¶
type DomainSpec struct {
Name string
Summary string
Details string // optional extra lines after the action list
NotHere string
Actions []Action
}
DomainSpec declares a fat tool: a name, a one-line summary, optional extra details, a "NOT here" routing note, and its actions.
type MCPCallFunc ¶ added in v0.10.0
type MCPCallFunc func(ctx context.Context, server, tool string, args map[string]any) (string, error)
MCPListFunc returns a human-readable catalog of the configured MCP servers and their tools (the host owns the connections). MCPCallFunc invokes one tool; MCPSchemaFunc returns a tool's input schema on demand. The host gates calls with approval.
type MCPListFunc ¶ added in v0.10.0
MCPListFunc returns a human-readable catalog of the configured MCP servers and their tools (the host owns the connections). MCPCallFunc invokes one tool; MCPSchemaFunc returns a tool's input schema on demand. The host gates calls with approval.
type MCPSchemaFunc ¶ added in v0.10.0
MCPListFunc returns a human-readable catalog of the configured MCP servers and their tools (the host owns the connections). MCPCallFunc invokes one tool; MCPSchemaFunc returns a tool's input schema on demand. The host gates calls with approval.
type Param ¶
type Param struct {
Name string
Type string // str | int | bool | number | list
Required bool
Default string // shown in the generated help when set (e.g. "." or "15")
}
Param declares one action parameter. It is the single source for BOTH the schema shown to the model and the required-arg validation, so help and behaviour can never drift apart.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the active tools and routes calls, applying cross-tool action correction so a misrouted action returns a hint naming the right tool.
func NewRegistry ¶
NewRegistry indexes tools by name and their actions by owning tool(s).
func (*Registry) Dispatch ¶
Dispatch routes (name, action) to its tool. Unknown tool, or an action owned by a different tool, returns a self-correcting Result the model can act on.
func (*Registry) Mutates ¶
Mutates reports whether (name, action) changes state — the gate plan mode uses.
func (*Registry) OpenAITools ¶
OpenAITools renders the catalog as OpenAI function definitions — one function per tool, with the action enum and a freeform params object. Kept tiny on purpose so small models prefill it fast.
type Result ¶
type Result struct {
Content string
IsError bool
Err error
Diff string // optional unified diff to display (set by file edits)
}
Result is a tool's outcome as the model sees it. Content is always model- facing text. IsError marks a failure the model should react to. Err is set only for host/infra failures (a *ToolError) so the host can log the typed cause while the model still just reads Content.
type SkillSource ¶
SkillSource is the read-only view of the skill store the model is allowed to touch: see the catalog of enabled skills and load one's full instructions. Installing and toggling skills is a human action (the /skills command), so it is deliberately NOT reachable from here.
type Snapshotter ¶ added in v0.12.0
type Snapshotter func(absPath string)
Snapshotter is called with the absolute path of a file about to be modified, BEFORE the change, so a checkpoint can capture its prior content (for /rewind).
type SpawnFunc ¶ added in v0.6.0
SpawnFunc runs a delegated task on a sub-agent — a fresh LLM session for the named profile (which carries the provider+model), in a given directory — and returns its final answer. The host provides it because it owns the profiles, provider resolution, approval, and the agent build. It errors on an unknown profile, a missing key, a bad directory, or a denied spawn.
type Tool ¶
type Tool interface {
Name() string
Description() string
Actions() []string
Call(ctx context.Context, action string, params map[string]any) Result
// Mutates reports whether an action changes state (writes a file, runs a
// command, alters git). Plan mode blocks these; read-only actions stay open.
Mutates(action string) bool
}
Tool is one fat domain tool.
func NewAgent ¶ added in v0.6.0
NewAgent is the `agent` fat tool: delegate a self-contained task to one of the configured profiles (each a model the user curated) — a second opinion, or another model's strength (e.g. reviewing the same code across models), optionally in another directory. Sub-agents can't spawn their own sub-agents (the host gives them a catalog without this tool). Issue several calls in one turn to fan a task out across profiles; they run in parallel.
spawnBg is the fire-and-forget variant: it starts the task as a detached background job and returns an immediate acknowledgement; the host delivers the job's result to the model at the start of a later turn.
func NewCalc ¶
func NewCalc() Tool
NewCalc returns the calc tool: safe arithmetic evaluation, so small models don't have to do unreliable mental math.
func NewFile ¶
func NewFile(p *policy.Engine, ap Approver, snap Snapshotter) Tool
NewFile returns the file tool, gated by the policy engine and (for "ask" decisions) the approver. snap (may be nil) is notified before each file change.
func NewGit ¶
NewGit returns the git tool. It runs git directly (argv, no shell) in the workspace; read-only actions run freely, mutating ones ask for approval.
func NewHelp ¶
NewHelp returns the help tool: an explicit escape hatch the model can call to see a domain's REAL usage (its current schema) plus the lessons learned for it. usage is the live contract lookup (e.g. Registry.Usage); it may be nil.
func NewMCP ¶ added in v0.10.0
func NewMCP(list MCPListFunc, call MCPCallFunc, schema MCPSchemaFunc) Tool
NewMCP is the `mcp` proxy fat tool: ONE tool that fronts every configured MCP server, so the prompt catalog doesn't balloon with each server's schemas. The model calls list to discover tools, schema to see a tool's inputs, and call to run one. Only present when at least one MCP server is configured.
func NewRun ¶
NewRun returns the run tool: a single `shell` action gated by the policy engine, executed with a timeout and a jail-confined working directory. The default timeout comes from config (run.timeout_seconds); 0 falls back to 60s.
func NewSkill ¶
func NewSkill(src SkillSource) Tool
NewSkill exposes enabled skills to the model. It is only registered when at least one skill is enabled, so it costs nothing in the catalog otherwise.