Documentation
¶
Overview ¶
Package tool is part of the GoFastr harness.
See docs/harness-architecture.md for the architecture this package implements.
Package tool defines the Tool abstraction, the tool registry, and supporting types. Built-in tools live in tool/builtins/; MCP tools are bridged through mcpclient/source.go; plugins register tools via the Plugin.Register hook.
The Tool signature is locked from v0.1:
Run(ctx, call, sink) (*ToolResult, error)
so streaming tools, cancellation, and middleware share one shape (see docs/harness-architecture.md § Extensibility → Tool middleware).
Index ¶
- Constants
- Variables
- func SessionFromContext(ctx context.Context) (ids.SessionID, bool)
- func SpawnDepthFromContext(ctx context.Context) int
- func WithRegistry(ctx context.Context, r *Registry) context.Context
- func WithSession(ctx context.Context, s ids.SessionID) context.Context
- func WithSpawnDepth(ctx context.Context, depth int) context.Context
- func WithSpawner(ctx context.Context, s Spawner) context.Context
- type EventSink
- type Handler
- type Middleware
- type Registry
- type Spawner
- type Tool
- type ToolCall
- type ToolResult
- type ToolSource
Constants ¶
const MaxSpawnDepth = 2
MaxSpawnDepth is the hard ceiling on sub-agent recursion. A depth of 2 means: top-level agent can spawn sub-agents (depth 1), and those sub-agents may NOT spawn further sub-agents (depth 2 would be blocked). Adjust if you intentionally need deeper trees.
Variables ¶
var ErrToolUnknown = errors.New("tool: unknown")
ErrToolUnknown is returned by Lookup when the tool is not registered.
Functions ¶
func SessionFromContext ¶
SessionFromContext extracts the session ID set by WithSession. Returns (zero, false) when no session is attached — tools that REQUIRE the session should error in that case.
func SpawnDepthFromContext ¶
SpawnDepthFromContext returns the current sub-agent depth (0 = top level). Defaults to 0 when no depth has been set.
func WithRegistry ¶
WithRegistry attaches the active tool registry to the dispatch ctx.
func WithSession ¶
WithSession returns ctx with the session ID attached. Engines call this before dispatching tools.
func WithSpawnDepth ¶
WithSpawnDepth attaches a sub-agent depth counter to ctx.
Types ¶
type EventSink ¶
type EventSink interface {
// EmitProgress publishes a ToolCallProgress event for the
// current ToolCall. The partial string is informational; the
// model never sees these directly — surfaces render them.
EmitProgress(partial string)
// EmitEvent publishes an arbitrary engine event. Used sparingly
// for tools that legitimately need to surface non-progress
// information (e.g., a tool that detects a sub-agent spawn).
EmitEvent(e control.Event)
}
EventSink lets middleware and tools emit ToolCallProgress events (and other side-channel signals) without holding a reference to the engine bus directly. The dispatcher provides the implementation.
type Handler ¶
Handler is the curried form a middleware receives. Calling Handler invokes the rest of the chain (or the tool itself if no middleware remains).
func Chain ¶
func Chain(base Handler, ms ...Middleware) Handler
Chain composes a Handler from a base handler and a sequence of middleware. Middleware are wrapped in registration order — the first middleware listed sees the request first.
type Middleware ¶
type Middleware func(ctx context.Context, call ToolCall, sink EventSink, next Handler) (*ToolResult, error)
Middleware wraps a Handler to add behavior (permission, sandbox, timeout, redaction, etc.). Composed in order at registration time.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the in-memory catalog of tools available to the engine. Multiple ToolSources can register; their tools are merged by name, with later registrations rejected on collision (to make shadowing explicit rather than silent).
func RegistryFromContext ¶
RegistryFromContext extracts the Registry attached by WithRegistry.
func (*Registry) List ¶
List returns all tools, sorted by name. Callers should treat the result as a snapshot; the registry may change after this returns.
func (*Registry) Register ¶
func (r *Registry) Register(ctx context.Context, src ToolSource) error
Register adds a ToolSource and ingests its current tool set. Returns an error on duplicate source name or duplicate tool name across sources.
type Spawner ¶
type Spawner interface {
Spawn(ctx context.Context, systemHint string, userPrompt string) (string, error)
}
Spawner lets a tool launch a fresh sub-agent inside the current session. The engine implements this — sub-agents share the parent's Provider, Model, Tools, and middleware, but get a fresh History. The Spawn call blocks until the sub-agent finishes and returns the final assistant text.
type Tool ¶
type Tool interface {
// Name returns the canonical tool name (e.g., "Read", "Bash").
Name() string
// Description is the natural-language description surfaced to
// the model in tool_use catalogs.
Description() string
// InputSchema returns the JSON Schema bytes describing the
// tool's argument shape.
InputSchema() []byte
// Mutating declares whether this tool's invocation has
// observable side effects. The persistence layer uses this for
// the intent/outcome ledger: mutating tools fsync their intent
// before spawning so crash-mid-call can be detected.
//
// Read-only tools (Read, Glob, Ls, Grep, WebFetch): false.
// Anything that touches the filesystem, runs commands, or
// performs an HTTP write: true.
Mutating() bool
// Run executes the tool. The sink lets the tool emit streaming
// progress (ToolCallProgress events) before the final result.
// Middleware (redaction, timeout, sandbox) wraps Run and
// receives the same sink for transparent observation.
Run(ctx context.Context, call ToolCall, sink EventSink) (*ToolResult, error)
}
type ToolCall ¶
type ToolCall struct {
ID ids.CallID // unique per turn; matches ToolUse.ID
Name string // tool name to invoke
Input json.RawMessage // argument JSON, validated against Tool.InputSchema()
}
ToolCall is an invocation of a tool by the model or by a plugin.
type ToolResult ¶
type ToolResult struct {
Content []control.ContentBlock // typically a single text block
IsError bool
}
ToolResult is the outcome of a tool call, fed back to the model.
type ToolSource ¶
type ToolSource interface {
// Name identifies the source for logging + the catalog ("builtin",
// "mcp:kiln", "plugin:foo").
Name() string
// Tools returns the current snapshot of tools this source
// exposes. Sources that hot-reload (MCP server reconnects, skill
// changes) should re-call Registry.Replace on change.
Tools(ctx context.Context) ([]Tool, error)
}
ToolSource produces tools to register with the engine. Built-ins, MCP-bridged tools, and plugin-contributed tools all implement this.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package builtins is part of the GoFastr harness.
|
Package builtins is part of the GoFastr harness. |
|
Package pack is part of the GoFastr harness.
|
Package pack is part of the GoFastr harness. |
|
Package permission is part of the GoFastr harness.
|
Package permission is part of the GoFastr harness. |