tools

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculatorTool

func CalculatorTool() protocol.Tool

CalculatorTool returns a calculator tool definition.

func MakeTool

func MakeTool(name, description string, params map[string]interface{}) protocol.Tool

MakeTool creates a simple tool definition.

func SearchTool

func SearchTool() protocol.Tool

SearchTool returns a web search tool definition.

func WeatherTool

func WeatherTool() protocol.Tool

WeatherTool returns a weather lookup tool definition.

Types

type FunctionCall

type FunctionCall = protocol.FunctionCall

FunctionCall represents a function call with name and arguments. Deprecated: Use protocol.FunctionCall instead.

type JSONToolCallParser

type JSONToolCallParser struct{}

JSONToolCallParser parses tool calls from JSON-formatted responses.

func (*JSONToolCallParser) Parse

func (p *JSONToolCallParser) Parse(ctx context.Context, response *protocol.ChatResponse) ([]ToolCall, error)

Parse extracts tool calls from JSON-formatted responses.

type ReActToolCallParser

type ReActToolCallParser struct{}

ReActToolCallParser parses tool calls from ReAct-style responses.

func (*ReActToolCallParser) Parse

func (p *ReActToolCallParser) Parse(ctx context.Context, response *protocol.ChatResponse) ([]ToolCall, error)

Parse extracts tool calls from ReAct-style responses.

type SimpleToolExecutor

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

SimpleToolExecutor is a basic tool executor using a map of functions.

func NewSimpleToolExecutor

func NewSimpleToolExecutor() *SimpleToolExecutor

NewSimpleToolExecutor creates a new simple tool executor.

func (*SimpleToolExecutor) Execute

func (e *SimpleToolExecutor) Execute(ctx context.Context, toolName string, args json.RawMessage) (string, error)

Execute runs a tool by name.

func (*SimpleToolExecutor) GetTools

func (e *SimpleToolExecutor) GetTools() []protocol.Tool

GetTools returns all registered tools.

func (*SimpleToolExecutor) RegisterTool

func (e *SimpleToolExecutor) RegisterTool(tool protocol.Tool, fn func(json.RawMessage) (string, error))

RegisterTool registers a tool with its implementation.

type ToolCall

type ToolCall = protocol.ToolCall

ToolCall represents a tool invocation by the model. Deprecated: Use protocol.ToolCall instead.

type ToolCallExtractor

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

ToolCallExtractor extracts tool calls from model responses using various strategies.

func NewToolCallExtractor

func NewToolCallExtractor() *ToolCallExtractor

NewToolCallExtractor creates a new tool call extractor.

func (*ToolCallExtractor) AddParser

func (e *ToolCallExtractor) AddParser(parser ToolCallParser) *ToolCallExtractor

AddParser adds a parser to the extractor.

func (*ToolCallExtractor) Extract

func (e *ToolCallExtractor) Extract(ctx context.Context, response *protocol.ChatResponse) ([]ToolCall, error)

Extract tries all parsers to extract tool calls.

type ToolCallParser

type ToolCallParser interface {
	Parse(ctx context.Context, response *protocol.ChatResponse) ([]ToolCall, error)
}

ToolCallParser extracts tool calls from model responses.

type ToolChain

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

ToolChain manages tool calling in a conversation.

func NewToolChain

func NewToolChain(model protocol.ChatModel, executor ToolExecutor) *ToolChain

NewToolChain creates a new tool chain.

func (*ToolChain) ExecuteWithTools

func (tc *ToolChain) ExecuteWithTools(ctx context.Context, req protocol.ChatRequest) (*protocol.ChatResponse, error)

ExecuteWithTools runs a chat request with tool support.

func (*ToolChain) MaxRounds

func (tc *ToolChain) MaxRounds() int

MaxRounds returns the configured maximum tool calling rounds.

func (*ToolChain) WithMaxRounds

func (tc *ToolChain) WithMaxRounds(maxRounds int) *ToolChain

WithMaxRounds sets the maximum number of tool calling rounds.

type ToolExecutor

type ToolExecutor interface {
	Execute(ctx context.Context, toolName string, args json.RawMessage) (string, error)
	GetTools() []protocol.Tool
}

ToolExecutor executes tools and returns results.

type ToolResult

type ToolResult struct {
	ToolCallID string `json:"tool_call_id"`
	Content    string `json:"content"`
	IsError    bool   `json:"is_error,omitempty"`
}

ToolResult represents the result of a tool execution.

Jump to

Keyboard shortcuts

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