tools

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package tools provides a FunctionRegistry that can register and execute ordinary functions *and* methods on structs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecTool

func ExecTool(funcName string, args map[string]any) (any, error)

Types

type FS added in v0.1.6

type FS struct {
	WD string
}

func (*FS) ToolGetCurrentWorkingDirectory added in v0.1.6

func (fs *FS) ToolGetCurrentWorkingDirectory() (string, error)

ToolGetCurrentWorkingDirectory returns the current working directory(or so called project directory). It's typically use for when it's asked to do operations regarding local filesystem, file operations, statistics, etc.

func (*FS) ToolGrepText added in v0.1.6

func (fs *FS) ToolGrepText(text string, includeHiddenFiles bool, caseSensitive bool, dir string) (string, error)

ToolGrepText returns ripgrep output for given text in the given dir

text: pattern to search includeHiddenFiles: bool flag to determine if hidden files are included or not. rg option `-.` is used when enabled caseSensitive: bool flag to determine if search is performed dace sensitive or not. rg option `-sis used when enabled dir: relative directory path to CWD, to perform ripgrep in `CWD/dir`.

func (*FS) ToolReadFile added in v0.1.6

func (fs *FS) ToolReadFile(filePath string) (string, error)

ToolReadFile returns the entire contents of the file at the given path. The path is treated as relative to the current working directory.

filePath: relative path to the CWD

func (*FS) ToolTree added in v0.1.6

func (fs *FS) ToolTree(dir string, maxDepth int) (string, error)

ToolTree returns an ASCII tree representation of the directory tree rooted at dir (relative to CWD).

dir: relative path to the CWD. maxDepth: positive integer value represents how many level of nested directories included in tree

type Function

type Function struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

type FunctionDefinition

type FunctionDefinition struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Parameters  ToolFunctionParameters `json:"parameters"`
}

type FunctionInfo

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

FunctionInfo stores everything needed to execute a registered function/method.

type FunctionRegistry

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

FunctionRegistry keeps a map of registered functions/methods.

func NewFunctionRegistry

func NewFunctionRegistry() *FunctionRegistry

NewFunctionRegistry returns an empty registry.

func (*FunctionRegistry) ExecFunc

func (fr *FunctionRegistry) ExecFunc(funcName string, args map[string]any) (any, error)

ExecFunc executes a registered function/method with named parameters. Methods receive their receiver automatically.

func (*FunctionRegistry) RegisterFunction

func (fr *FunctionRegistry) RegisterFunction(name string, fn any) error

RegisterFunction registers a standalone function.

func (*FunctionRegistry) RegisterMethods added in v0.1.6

func (fr *FunctionRegistry) RegisterMethods(instance any) ([]string, error)

RegisterMethods registers every exported method on 'instance'. Works for both value and pointer receivers.

type ParamInfo

type ParamInfo struct {
	TypeName    string
	Description string
}

ParamInfo holds JSON-schema style information for one parameter.

type Property

type Property struct {
	Type        string `json:"type,omitempty"`
	Description string `json:"description,omitempty"`
}

type Tool

type Tool struct {
	Type     string             `json:"type"` // always = "function"
	Function FunctionDefinition `json:"function"`
}

func ConstructToolStruct

func ConstructToolStruct(toolName string) Tool

func GetFsTools

func GetFsTools(path string) ([]Tool, error)

func RegisterMethods added in v0.1.8

func RegisterMethods(inst any) ([]Tool, error)

func RegisterTool added in v0.1.5

func RegisterTool(funcName string, fn any) (Tool, error)

type ToolCall

type ToolCall struct {
	Id       string   `json:"id"`
	Type     string   `json:"type"`
	Function Function `json:"function"`
}

type ToolFunctionParameters

type ToolFunctionParameters struct {
	Type       string              `json:"type"` // object
	Properties map[string]Property `json:"properties"`
	Required   []string            `json:"required"`
}

Jump to

Keyboard shortcuts

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