tools

package
v0.0.0-...-f913c9e Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package tools provides the tool system: definitions, registry, and local tool implementations.

Index

Constants

This section is empty.

Variables

View Source
var ErrDepthLimit = errors.New("too deep pointer to cast")

ErrDepthLimit is returned when pointer dereferencing exceeds the allowed depth.

View Source
var ErrNoSuchTool = errors.New("no such tool")

ErrNoSuchTool is returned when a requested tool is not found in the registry.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	Name        string
	Description string
	Schema      shared.FunctionParameters
}

Definition describes a tool's name, description, schema, and whether it requires approval.

func (Definition) Param

Param converts the definition into an OpenAI tool parameter.

type LocalTool

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

LocalTool is a tool backed by a Go function with auto-generated JSON schema.

func Local

func Local[In any, Out any](name string, handler func(ctx context.Context, args In) (Out, error)) *LocalTool

Local creates a typed tool that auto-generates its JSON schema from In.

func LocalSchema

func LocalSchema(name string, schemaInput schema.Schema, handler func(ctx context.Context, payload any) (any, error)) *LocalTool

LocalSchema creates a tool with an explicit JSON schema definition.

func (*LocalTool) Call

func (t *LocalTool) Call(ctx context.Context, raw json.RawMessage) (string, error)

Call executes the tool with the given JSON arguments.

func (*LocalTool) Definition

func (t *LocalTool) Definition() Definition

Definition returns the tool's metadata and schema.

func (*LocalTool) Description

func (t *LocalTool) Description(description string) *LocalTool

Description sets the tool's description shown to the LLM.

type Tool

type Tool interface {
	Definition() Definition
	Call(ctx context.Context, payload json.RawMessage) (string, error)
}

Tool is the interface that all callable tools must implement.

type ToolSet

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

ToolSet is a thread-safe registry of tools.

func NewToolSet

func NewToolSet(tools ...Tool) *ToolSet

NewToolSet creates a ToolSet pre-populated with the given tools.

func (*ToolSet) Add

func (t *ToolSet) Add(tools ...Tool) *ToolSet

Add registers tools in the set, replacing any with the same name.

func (*ToolSet) Call

Call invokes a tool by name from the given tool call payload.

func (*ToolSet) Concat

func (t *ToolSet) Concat(other *ToolSet) *ToolSet

Concat returns a new ToolSet merging tools from both sets.

func (*ToolSet) Get

func (t *ToolSet) Get(name string) (Tool, bool)

Get looks up a tool by name.

func (*ToolSet) Tools

func (t *ToolSet) Tools() []openai.ChatCompletionToolParam

Tools returns the sorted list of OpenAI tool parameters.

Directories

Path Synopsis
Package js provides JavaScript-based tool implementations using the goja runtime.
Package js provides JavaScript-based tool implementations using the goja runtime.

Jump to

Keyboard shortcuts

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