Documentation
¶
Overview ¶
Package tool defines the shared contract every built-in tool implements: a Definition advertised to the model and an Execute that runs a single invocation and returns a uniform Result.
The contract decouples a tool's logic from the harness: implementations hold their own dependencies (sandbox, skill registry, LSP manager, ...) captured at construction, and toolexec dispatches to them generically without knowing tool-specific details. Result carries both the text sent back to the model and the metadata the TUI needs to render the event, so neither concern leaks into the tool packages or the dispatch loop.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Previewer ¶ added in v0.2.1
type Previewer interface {
Preview(req message.ToolUseRequest) (variant, subject string)
}
Previewer is an optional interface a Tool may implement to describe an invocation from the raw request, before Execute runs. Variant and Subject populate the start ToolEvent so the TUI can render the catalog sentence immediately. Outcome-dependent tools should preview the pre-execution subject; their completion line may differ and still show.
type Result ¶
type Result struct {
// ModelOutput is the tool_result body returned to the model.
ModelOutput string
// Display is the text shown in the TUI history. When empty, the harness
// falls back to ModelOutput. Set it only when the model-facing text
// differs from what the user should see — e.g. a one-line preview of a
// long body, or a colored diff.
Display string
// Variant labels the sub-action: the skill name, the editor command, the
// LSP action, etc. May be empty when not meaningful.
Variant string
// Subject labels the target the action operates on: a file path, an
// argument string, a shell command. May be empty.
Subject string
// IsError marks the invocation as failed. Surfaced to both the model
// (is_error on the tool result) and the TUI. Tool errors are recoverable:
// they never abort the agentic loop.
IsError bool
// Usage carries pre-costed usage (TotalCost already computed against
// the subagent's own model schedule) for tools that spawn nested
// subagent conversations, such as research_codebase and review_ticket.
// It stays the zero value for ordinary tools that never spawn a
// subagent, so the parent session has nothing extra to fold in.
Usage usage.SessionUsage
}
Result is the uniform outcome of a tool invocation.
type Tool ¶
type Tool interface {
Definition() tooldef.Definition
Execute(ctx context.Context, req message.ToolUseRequest) Result
}
Tool is the contract every built-in tool implements. Definition is the static, model-facing advertisement (it needs no runtime state, so callers can advertise a tool without constructing its dependencies). Execute runs one invocation against the dependencies the implementation captured at construction.
Source Files
¶
- tool.go