tools

package
v0.0.0-...-99d71fe Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToolDefinititionToAgent

func AddToolDefinititionToAgent[Input any, Output any](toolsAgent *ToolsAgent, name, description string, fn func(ctx *ai.ToolContext, input Input) (Output, error))

NOTE: in theory we do not need it, but keeping for consistency AddToolDefinititionToAgent adds a tool with full context to the ToolsAgent's tool index.

func AddToolToAgent

func AddToolToAgent[Input any, Output any](toolsAgent *ToolsAgent, name, description string, fn func(input Input) (Output, error))

NOTE: simpler version without context: AddToolToAgent adds a tool to the ToolsAgent's tool index.

func Transform

func Transform[T any](output any) (T, error)

Transform converts a map[string]interface{} output to a typed struct using JSON marshaling

Types

type ConfirmationResponse

type ConfirmationResponse int
const (
	Confirmed ConfirmationResponse = iota
	Denied
	Quit
)

type ContentItem

type ContentItem struct {
	Text string `json:"text"`
	Type string `json:"type"`
}

type ToolCallsRequest

type ToolCallsRequest struct {
	Prompt string `json:"prompt"`
}

type ToolCallsResult

type ToolCallsResult struct {
	Text string           `json:"text"`
	List []map[string]any `json:"list"`
}

type ToolDefinition

type ToolDefinition struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Function    any    `json:"-"`
}

ToolDefinition defines a tool that can be used by the ToolsAgent. It includes the tool's name, description, and the function that implements the tool's behavior. The `name` is the identifier the model uses to request the tool. The `description` helps the model understand when to use the tool. The function `fn` implements the tool's logic, taking an input of type `In`, and returning an output of type `Out`. The input and output types determine the `inputSchema` and `outputSchema` in the tool's definition, which guide the model on how to provide input and interpret output.

type ToolExecution

type ToolExecution struct {
	OnExecuted func(toolName string, toolInput any, toolCallRef string, output any, err error)
}

type ToolExecutionConfirmation

type ToolExecutionConfirmation struct {
	Question func(toolName string, toolInput any, toolCallRef string) ConfirmationResponse

	OnConfirmed func(toolName string, toolInput any, toolCallRef string, output any, err error)
	OnDenied    func(toolName string, toolInput any, toolCallRef string)
	OnQuit      func(toolName string, toolInput any, toolCallRef string)
	Default     func()
}

type ToolOutput

type ToolOutput struct {
	Content []ContentItem `json:"content"`
}

type ToolsAgent

type ToolsAgent struct {
	Name               string
	SystemInstructions string
	ModelID            string
	Messages           []*ai.Message

	Config models.ModelConfig

	ToolsIndex []ai.ToolRef
	// contains filtered or unexported fields
}

ToolsAgent is an implementation of an AI agent that can utilize various tools to perform tasks. IMPORTANT: ToolsAgent is not a chat agent.

func NewToolsAgent

func NewToolsAgent(
	ctx context.Context,
	toolsAgentConfig agents.AgentConfig,
	modelConfig models.ModelConfig,

	opts ...ToolsAgentOption,
) (*ToolsAgent, error)

func (*ToolsAgent) GetCurrentContextSize

func (toolsAgent *ToolsAgent) GetCurrentContextSize() int

GetCurrentContextSize returns the current context size in characters.

func (*ToolsAgent) GetInfo

func (toolsAgent *ToolsAgent) GetInfo() (agents.ToolsAgentInfo, error)

GetInfo returns the ToolsAgent information.

func (*ToolsAgent) GetMessages

func (toolsAgent *ToolsAgent) GetMessages() []*ai.Message

GetMessages returns the message history of the ToolsAgent.

func (*ToolsAgent) GetName

func (toolsAgent *ToolsAgent) GetName() string

GetName returns the name of the ToolsAgent.

func (*ToolsAgent) Kind

func (toolsAgent *ToolsAgent) Kind() agents.AgentKind

Kind returns the kind of the agent.

func (*ToolsAgent) RunToolCalls

func (toolsAgent *ToolsAgent) RunToolCalls(prompt string) (ToolCallsResult, error)

RunToolCalls runs the tool-calling flow with the given prompt.

type ToolsAgentOption

type ToolsAgentOption func(*ToolsAgent)

AgentOption defines a functional option for configuring LocalAIAgent

func EnableAutoToolCallFlow

func EnableAutoToolCallFlow() ToolsAgentOption

func EnableToolCallFlow

func EnableToolCallFlow() ToolsAgentOption

func WithConfirmation

func WithConfirmation(toolExecutionConfirmation ToolExecutionConfirmation) ToolsAgentOption

func WithLogLevel

func WithLogLevel(level logger.LogLevel) ToolsAgentOption

WithLogLevel sets the log level for the agent

func WithLogger

func WithLogger(log logger.Logger) ToolsAgentOption

WithLogger sets a custom logger for the agent

func WithToolExecution

func WithToolExecution(toolExecution ToolExecution) ToolsAgentOption

func WithVerbose

func WithVerbose(verbose bool) ToolsAgentOption

WithVerbose enables verbose logging (INFO level) with agent name prefix