Skip to main content

Tool Types

Types related to tool definitions, tool calls, and tool execution.

Tool​

See Tool API Reference for complete documentation.

ToolCall​

type ToolCall struct {
ID string `json:"id"`
ToolName string `json:"toolName"`
Arguments map[string]interface{} `json:"arguments"`
}

Represents a tool call made by the model.

Fields​

FieldTypeDescription
IDstringUnique identifier for this tool call
ToolNamestringName of the tool to call
Argumentsmap[string]interfaceArguments to pass to the tool

ToolResult​

type ToolResult struct {
ToolCallID string `json:"toolCallId"`
ToolName string `json:"toolName"`
Result interface{} `json:"result"`
Error error `json:"error,omitempty"`
ProviderExecuted bool `json:"providerExecuted,omitempty"`
}

Result of executing a tool.

Fields​

FieldTypeDescription
ToolCallIDstringID of the tool call this result corresponds to
ToolNamestringName of the tool that was executed
ResultinterfaceResult of the tool execution
ErrorerrorError if execution failed
ProviderExecutedboolWhether provider executed this tool

ToolChoice​

type ToolChoice struct {
Type ToolChoiceType `json:"type"`
ToolName string `json:"toolName,omitempty"`
}

Specifies how the model should choose tools.

Fields​

FieldTypeDescription
TypeToolChoiceTypeType of tool choice
ToolNamestringSpecific tool name (for ToolChoiceTool type)

ToolChoiceType​

type ToolChoiceType string

const (
ToolChoiceAuto ToolChoiceType = "auto"
ToolChoiceNone ToolChoiceType = "none"
ToolChoiceRequired ToolChoiceType = "required"
ToolChoiceTool ToolChoiceType = "tool"
)

Types of tool choice strategies:

  • ToolChoiceAuto: Model decides whether to use tools
  • ToolChoiceNone: Model cannot use tools
  • ToolChoiceRequired: Model must use at least one tool
  • ToolChoiceTool: Model must use a specific tool

ToolExecutor​

type ToolExecutor func(
ctx context.Context,
input map[string]interface{},
options ToolExecutionOptions,
) (interface{}, error)

Function signature for tool execution.

ToolExecutionOptions​

type ToolExecutionOptions struct {
ToolCallID string
UserContext interface{}
Usage *Usage
Metadata map[string]interface{}
}

Options passed to tool execution.

Fields​

FieldTypeDescription
ToolCallIDstringUnique ID of this tool call
UserContextinterfaceUser-defined context
Usage*UsageCurrent token usage
Metadatamap[string]interfaceAdditional metadata

Examples​

Create Tool Call​

package main

import (
"github.com/digitallysavvy/go-ai/pkg/provider/types"
)

func main() {
toolCall := types.ToolCall{
ID: "call_abc123",
ToolName: "get_weather",
Arguments: map[string]interface{}{
"location": "Tokyo",
"units": "celsius",
},
}
}

Auto Tool Choice​

toolChoice := types.AutoToolChoice()
// Equivalent to:
// types.ToolChoice{Type: types.ToolChoiceAuto}

Required Tool Choice​

toolChoice := types.RequiredToolChoice()
// Model must call at least one tool

Specific Tool Choice​

toolChoice := types.SpecificToolChoice("get_weather")
// Model must call the "get_weather" tool

Handle Tool Result​

toolResult := types.ToolResult{
ToolCallID: "call_abc123",
ToolName: "get_weather",
Result: map[string]interface{}{
"temperature": 22,
"condition": "sunny",
},
}

if toolResult.Error != nil {
log.Printf("Tool failed: %v", toolResult.Error)
}

See Also​