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 Require(params map[string]any, keys ...string) error
- func Str(p map[string]any, key string) string
- type Action
- type Approver
- type Args
- type Domain
- type DomainSpec
- type Param
- type Registry
- type Result
- type SkillSource
- type SpawnFunc
- type Tool
- func NewAgent(spawn SpawnFunc) Tool
- func NewCalc() Tool
- func NewFile(p *policy.Engine, ap Approver) Tool
- func NewGit(p *policy.Engine, ap Approver) Tool
- func NewHelp(kb *knowledge.KB, usage func(domain string) string) Tool
- func NewRun(p *policy.Engine, ap Approver, defaultTimeout time.Duration) Tool
- func NewSkill(src SkillSource) Tool
- func NewWeb(hc *http.Client) 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 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 SpawnFunc ¶ added in v0.6.0
SpawnFunc runs a scoped task on a sub-agent (a fresh agent loop on another model/provider) and returns its final answer. The host provides it because it owns config, provider resolution, approval, and the agent build. It returns an error for an unknown profile/provider, a missing key, 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 a different model/provider and get its answer back — a second opinion, or another model's strength (e.g. reviewing the same code across models). Sub-agents can't spawn their own sub-agents (the host gives them a catalog without this tool).
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 ¶
NewFile returns the file tool, gated by the policy engine and (for "ask" decisions) the approver.
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 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.