Documentation
¶
Overview ¶
Package tools provides the tool system: definitions, registry, and local tool implementations.
Index ¶
- Variables
- type Definition
- type LocalTool
- type Tool
- type ToolSet
- func (t *ToolSet) Add(tools ...Tool) *ToolSet
- func (t *ToolSet) Call(ctx context.Context, payload openai.ChatCompletionMessageToolCallParam) (string, error)
- func (t *ToolSet) Concat(other *ToolSet) *ToolSet
- func (t *ToolSet) Get(name string) (Tool, bool)
- func (t *ToolSet) Tools() []openai.ChatCompletionToolParam
Constants ¶
This section is empty.
Variables ¶
var ErrDepthLimit = errors.New("too deep pointer to cast")
ErrDepthLimit is returned when pointer dereferencing exceeds the allowed depth.
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 ¶
func (d Definition) Param() openai.ChatCompletionToolParam
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) Definition ¶
func (t *LocalTool) Definition() Definition
Definition returns the tool's metadata and schema.
func (*LocalTool) Description ¶
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 ¶
NewToolSet creates a ToolSet pre-populated with the given tools.
func (*ToolSet) Call ¶
func (t *ToolSet) Call(ctx context.Context, payload openai.ChatCompletionMessageToolCallParam) (string, error)
Call invokes a tool by name from the given tool call payload.
func (*ToolSet) Tools ¶
func (t *ToolSet) Tools() []openai.ChatCompletionToolParam
Tools returns the sorted list of OpenAI tool parameters.