tools

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tools provides the tool plugin system for Forge agents. Tools are capabilities that an LLM agent can invoke during execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InputSpecToSchema

func InputSpecToSchema(spec string) json.RawMessage

InputSpecToSchema converts a skill InputSpec string (e.g. "input (string), model (string)") into a JSON Schema object. The first parameter is marked as required. Falls back to an open schema if parsing fails.

func InvalidSchemaPropertyKeys added in v0.18.1

func InvalidSchemaPropertyKeys(schema json.RawMessage) []string

InvalidSchemaPropertyKeys returns the top-level property keys of a tool input schema that violate the provider constraint, sorted for deterministic messages. Nil/unparseable schemas and schemas without properties return nil (nothing to validate — the provider accepts an empty object schema).

func RelaxedLimits added in v0.17.0

func RelaxedLimits(ctx context.Context) bool

RelaxedLimits reports whether tool-internal output caps should scale up.

func ToLLMDefinition

func ToLLMDefinition(t Tool) llm.ToolDefinition

ToLLMDefinition converts a Tool to an llm.ToolDefinition for use with LLM APIs.

func WithRelaxedLimits added in v0.17.0

func WithRelaxedLimits(ctx context.Context) context.Context

WithRelaxedLimits marks the context so tool-internal output caps scale up, letting the full output reach the compression layer.

Types

type Category

type Category string

Category classifies tools by their source/purpose.

const (
	CategoryBuiltin Category = "builtin"
	CategoryAdapter Category = "adapter"
	CategoryDev     Category = "dev"
	CategoryCustom  Category = "custom"
)

type CommandExecutor

type CommandExecutor interface {
	Run(ctx context.Context, command string, args []string, stdin []byte) (stdout string, err error)
}

CommandExecutor abstracts command execution for custom tools.

type CustomTool

type CustomTool struct {
	// contains filtered or unexported fields
}

CustomTool wraps a discovered script as a Tool implementation. It delegates execution to an injected CommandExecutor rather than calling os/exec directly, keeping this package free of OS dependencies.

func NewCustomTool

func NewCustomTool(dt DiscoveredTool, executor CommandExecutor) *CustomTool

NewCustomTool creates a tool wrapper for a discovered script. If executor is nil, Execute will return an error.

func (*CustomTool) Category

func (t *CustomTool) Category() Category

func (*CustomTool) Description

func (t *CustomTool) Description() string

func (*CustomTool) Execute

func (t *CustomTool) Execute(ctx context.Context, args json.RawMessage) (string, error)

func (*CustomTool) InputSchema

func (t *CustomTool) InputSchema() json.RawMessage

func (*CustomTool) Name

func (t *CustomTool) Name() string

func (*CustomTool) ValidateEntrypoint

func (t *CustomTool) ValidateEntrypoint(basedir string) error

ValidateEntrypoint checks that the entrypoint is safe to execute: - Not empty or absolute - Does not contain path traversal (..) - Resolves (via symlinks) to a path within basedir - Is a regular file

type DiscoveredTool

type DiscoveredTool struct {
	Name       string
	Path       string
	Language   string
	Entrypoint string
}

DiscoveredTool represents a tool found via filesystem discovery.

func DiscoverToolsFS

func DiscoverToolsFS(fsys fs.FS) []DiscoveredTool

DiscoverToolsFS scans the given fs.FS for tool scripts/modules. It looks for:

  • tool_*.py, tool_*.ts, tool_*.js files
  • */tool.py, */tool.ts, */tool.js subdirectories

type MCPSource

type MCPSource interface {
	Tool
	MCPSource() // marker — body is empty
}

MCPSource is an optional interface signalling that a tool was discovered from an MCP server. The registry uses this to permit "__" in the tool's name — that separator is reserved for the namespaced form "<server-name>__<tool-name>" so MCP tools cannot collide with builtin or adapter tool names. Tools that do NOT implement MCPSource are rejected at registration time if their name contains "__".

Implementing this is a single no-op method; see forge-core/tools/adapters/mcp_tool.go.

type NamespacedSource added in v0.18.1

type NamespacedSource interface {
	Tool
	NamespacedSource() // marker — body is empty
}

NamespacedSource is a sibling marker to MCPSource for non-MCP tools that legitimately use the "<server>__<op>" namespaced form — notably per-op API tools materialized from an admitted OpenAPI entry. Implementing it opts the tool into the "__" separator at registration (same as MCPSource) without falsely claiming to be an MCP tool.

type NetworkPolicy

type NetworkPolicy struct {
	AllowedHosts []string `json:"allowed_hosts,omitempty"`
	DenyAll      bool     `json:"deny_all,omitempty"`
}

NetworkPolicy describes network requirements for registered tools.

func GenerateNetworkPolicy

func GenerateNetworkPolicy(reg *Registry) NetworkPolicy

GenerateNetworkPolicy scans registered tools and generates a network policy.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is a thread-safe tool registry. It implements engine.ToolExecutor via Go structural typing -- no direct import of the engine package is needed.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty tool registry.

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, arguments json.RawMessage) (string, error)

Execute runs the named tool with the given arguments. This method satisfies the engine.ToolExecutor interface.

func (*Registry) Filter

func (r *Registry) Filter(allowed []string) *Registry

Filter returns a new Registry containing only tools whose names are in the allowed list. This is useful for Command to restrict which tools are available at runtime.

func (*Registry) Get

func (r *Registry) Get(name string) Tool

Get returns the tool with the given name, or nil if not found.

func (*Registry) List

func (r *Registry) List() []string

List returns the names of all registered tools, sorted alphabetically.

func (*Registry) Register

func (r *Registry) Register(t Tool) error

Register adds a tool to the registry. Returns an error if a tool with the same name is already registered.

Tool names containing "__" are reserved for MCP-discovered tools (the "<server>__<tool>" namespaced form). Non-MCP tools that try to use that separator are rejected — this prevents a builtin from accidentally shadowing an MCP tool's namespace. MCP tools must implement the MCPSource marker interface to opt in.

func (*Registry) Remove

func (r *Registry) Remove(name string)

Remove deletes a tool from the registry by name. No-op if not found.

func (*Registry) ToolDefinitions

func (r *Registry) ToolDefinitions() []llm.ToolDefinition

ToolDefinitions returns LLM tool definitions for all registered tools. This method satisfies the engine.ToolExecutor interface.

type SkillTool

type SkillTool struct {
	// contains filtered or unexported fields
}

SkillTool wraps a parsed skill entry as a Tool. Execution shape is pinned at construction time via NewSkillTool (bash + script path) or NewBinarySkillTool (external executable). Both pass the JSON input as a single positional argument so script-side and binary-side share the same `argv[1] == JSON` contract.

func NewBinarySkillTool added in v0.16.0

func NewBinarySkillTool(name, description, inputSpec, binaryPath string, executor CommandExecutor) *SkillTool

NewBinarySkillTool creates a tool wrapper for a skill backed by an external binary. The compiled `command` is the binary path (typically resolved via `exec.LookPath` by the caller); argv is `[<binary> <jsonArgs>]`. The CommandExecutor's trace-context env injection (issue #182) lets the binary's own spans nest under the parent agent's `tool.<name>` span via TRACEPARENT.

Use this when the skill IS the binary — infil, an LLM CLI, a Python or Go executable. Use NewSkillTool when the skill body is bash and gets materialized into a script file at agent startup.

func NewScriptSkillTool added in v0.18.1

func NewScriptSkillTool(name, description, inputSpec, interpreter, scriptPath string, executor CommandExecutor) *SkillTool

NewScriptSkillTool creates a tool wrapper for a skill backed by a script run under an explicit interpreter (e.g. "bash", "python3", "node"); argv is `[<interpreter> <scriptPath> <jsonArgs>]`. This is what lets a `## Tool:` entry backed by a `.py`/`.js` script register as a first-class callable tool, not just a `.sh` one (#405 D2).

func NewSkillTool

func NewSkillTool(name, description, inputSpec, scriptPath string, executor CommandExecutor) *SkillTool

NewSkillTool creates a tool wrapper for a skill backed by a shell script. The compiled `command` is `bash`; argv is `[bash <scriptPath> <jsonArgs>]`. Shorthand for NewScriptSkillTool with the "bash" interpreter.

func (*SkillTool) Category

func (t *SkillTool) Category() Category

func (*SkillTool) Description

func (t *SkillTool) Description() string

func (*SkillTool) Execute

func (t *SkillTool) Execute(ctx context.Context, args json.RawMessage) (string, error)

func (*SkillTool) InputSchema

func (t *SkillTool) InputSchema() json.RawMessage

func (*SkillTool) Name

func (t *SkillTool) Name() string

type Tool

type Tool interface {
	// Name returns the unique tool name.
	Name() string
	// Description returns a human-readable description of the tool.
	Description() string
	// Category returns the tool's category.
	Category() Category
	// InputSchema returns the JSON Schema for the tool's input parameters.
	InputSchema() json.RawMessage
	// Execute runs the tool with the given JSON arguments.
	Execute(ctx context.Context, args json.RawMessage) (string, error)
}

Tool is the interface that all tools must implement.

Directories

Path Synopsis
Package adapters provides tools that call out to external systems.
Package adapters provides tools that call out to external systems.
Package builtins provides built-in tools available to all agents.
Package builtins provides built-in tools available to all agents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL