Documentation
¶
Index ¶
- func CalculatorTool() protocol.Tool
- func MakeTool(name, description string, params map[string]interface{}) protocol.Tool
- func SearchTool() protocol.Tool
- func WeatherTool() protocol.Tool
- type FunctionCall
- type JSONToolCallParser
- type ReActToolCallParser
- type SimpleToolExecutor
- type ToolCall
- type ToolCallExtractor
- type ToolCallParser
- type ToolChain
- type ToolExecutor
- type ToolResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculatorTool ¶
CalculatorTool returns a calculator tool definition.
func WeatherTool ¶
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 ¶
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) WithMaxRounds ¶
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.