tools

package
v1.12.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MPL-2.0 Imports: 3 Imported by: 3 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Tools []Tool
)

ToolContext keeps the registry of all tools.

Functions

func AddTool

func AddTool(t Tool)

AddTool registers a new tool in the global context.

func RegisterTool

func RegisterTool(
	provider Provider,
	name string,
	description string,
	tags []string,
	inputs *ToolInputOutputSchema,
	outputs *ToolInputOutputSchema,
	handler ToolHandler,
)

RegisterTool is the Go equivalent of your @utcp_tool decorator. Call this from an init() function in the same package as your handler.

Types

type Tool

type Tool struct {
	Name                string                `json:"name"`
	Description         string                `json:"description"`
	Inputs              ToolInputOutputSchema `json:"inputs"`
	Outputs             ToolInputOutputSchema `json:"outputs"`
	Tags                []string              `json:"tags"`
	AverageResponseSize *int                  `json:"average_response_size,omitempty"`
	Provider            Provider              `json:"tool_provider"`
	Handler             ToolHandler           `json:"-"`
}

Tool holds the metadata for a single UTCP tool.

func GetTools

func GetTools() []Tool

GetTools returns all registered tools.

type ToolHandler

type ToolHandler func(ctx context.Context, inputs map[string]interface{}) (any, error)

ToolHandler is the signature your Go tool functions must satisfy. The first argument is your execution context (if any), here we use a generic map. You can replace `map[string]interface{}` with a concrete struct or interface as needed.

type ToolInputOutputSchema

type ToolInputOutputSchema struct {
	Type        string                 `json:"type"`                 // e.g. "object", "array", "string"
	Properties  map[string]interface{} `json:"properties,omitempty"` // field schemas
	Required    []string               `json:"required,omitempty"`
	Description string                 `json:"description,omitempty"`
	Title       string                 `json:"title,omitempty"`
	Items       map[string]interface{} `json:"items,omitempty"` // for arrays
	Enum        []interface{}          `json:"enum,omitempty"`
	Minimum     *float64               `json:"minimum,omitempty"`
	Maximum     *float64               `json:"maximum,omitempty"`
	Format      string                 `json:"format,omitempty"` // e.g. "date-time"
}

ToolInputOutputSchema mirrors your JSON schema description.

type ToolProvider

type ToolProvider interface {
	Type() string
	Name() string
}

ProviderUnion is your existing Go interface/union for providers.

type ToolSearchStrategy

type ToolSearchStrategy interface {
	// SearchTools returns up to `limit` tools matching `query`.
	// A limit of 0 means “no limit” (return all matches).
	//
	// ctx carries deadlines, cancellation signals, and other request-scoped values.
	SearchTools(ctx context.Context, query string, limit int) ([]Tool, error)
}

ToolSearchStrategy is an interface for any component that knows how to search for tools based on a query.

Jump to

Keyboard shortcuts

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