tools

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToOpenAITools

func ToOpenAITools(tools []*Tool) []openai.ChatCompletionToolUnionParam

ToOpenAITools converts a slice of Tool pointers to a slice of OpenAI ChatCompletionToolUnionParam

Types

type Agent

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

Agent represents a simplified tools agent that hides OpenAI SDK details

func NewAgent

func NewAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig models.Config,
	opts ...ToolAgentOption,
) (*Agent, error)

NewAgent creates a new simplified tools agent

func (*Agent) AddMessage

func (agent *Agent) AddMessage(role roles.Role, content string)

AddMessage adds a message to the conversation history

func (*Agent) AddMessages added in v1.0.4

func (agent *Agent) AddMessages(msgs []messages.Message)

AddMessages adds multiple messages to the conversation history

func (*Agent) DetectParallelToolCalls added in v0.0.4

func (agent *Agent) DetectParallelToolCalls(
	userMessages []messages.Message,
	toolCallback ToolCallback,
) (*ToolCallResult, error)

NOTE: IMPORTANT: Not all LLMs with tool support support parallel tool calls.

func (*Agent) DetectParallelToolCallsWithConfirmation added in v0.0.4

func (agent *Agent) DetectParallelToolCallsWithConfirmation(
	userMessages []messages.Message,
	toolCallback ToolCallback,
	confirmationCallback ConfirmationCallback,
) (*ToolCallResult, error)

NOTE: IMPORTANT: Not all LLMs with tool support support parallel tool calls.

func (*Agent) DetectToolCallsLoop added in v0.0.4

func (agent *Agent) DetectToolCallsLoop(
	userMessages []messages.Message,
	toolCallback ToolCallback,
) (*ToolCallResult, error)

DetectToolCallsLoop sends messages and detects tool calls, executing them via callback

func (*Agent) DetectToolCallsLoopStream added in v0.0.4

func (agent *Agent) DetectToolCallsLoopStream(
	userMessages []messages.Message,
	toolCallback ToolCallback,
	streamCallback StreamCallback,
) (*ToolCallResult, error)

DetectToolCallsLoopStream sends messages and detects tool calls with streaming

func (*Agent) DetectToolCallsLoopWithConfirmation added in v0.0.4

func (agent *Agent) DetectToolCallsLoopWithConfirmation(
	userMessages []messages.Message,
	toolCallback ToolCallback,
	confirmationCallback ConfirmationCallback,
) (*ToolCallResult, error)

func (*Agent) DetectToolCallsLoopWithConfirmationStream added in v0.0.4

func (agent *Agent) DetectToolCallsLoopWithConfirmationStream(
	userMessages []messages.Message,
	toolCallback ToolCallback,
	confirmationPrompt ConfirmationCallback,
	streamCallback StreamCallback,
) (*ToolCallResult, error)

DetectToolCallsStream sends messages and detects tool calls with streaming

func (*Agent) GetConfig added in v1.0.8

func (agent *Agent) GetConfig() agents.Config

GetConfig returns the agent configuration

func (*Agent) GetContextSize

func (agent *Agent) GetContextSize() int

GetContextSize returns the approximate size of the current context

func (*Agent) GetConversationHistoryJSON added in v1.0.2

func (agent *Agent) GetConversationHistoryJSON() (string, error)

GetConversationHistoryJSON returns the entire conversation history as JSON

func (*Agent) GetLastRequestContextLength added in v1.0.2

func (agent *Agent) GetLastRequestContextLength() int

GetLastRequestContextLength returns the context length of the last request

func (*Agent) GetLastRequestJSON added in v1.0.2

func (agent *Agent) GetLastRequestJSON() (string, error)

GetLastRequestJSON returns the last request sent to the LLM as JSON

func (*Agent) GetLastRequestMetadata added in v1.0.2

func (agent *Agent) GetLastRequestMetadata() base.RequestMetadata

GetLastRequestMetadata returns metadata about the last request

func (*Agent) GetLastResponseJSON added in v1.0.2

func (agent *Agent) GetLastResponseJSON() (string, error)

GetLastResponseJSON returns the last response received from the LLM as JSON

func (*Agent) GetLastResponseMetadata added in v1.0.2

func (agent *Agent) GetLastResponseMetadata() base.ResponseMetadata

GetLastResponseMetadata returns metadata about the last response

func (*Agent) GetMessages

func (agent *Agent) GetMessages() []messages.Message

GetMessages returns all conversation messages

func (*Agent) GetModelConfig added in v1.0.8

func (agent *Agent) GetModelConfig() models.Config

GetModelConfig returns the model configuration

func (*Agent) GetModelID added in v0.0.7

func (agent *Agent) GetModelID() string

func (*Agent) GetName added in v0.0.3

func (agent *Agent) GetName() string

func (*Agent) GetTotalTokensUsed added in v1.0.2

func (agent *Agent) GetTotalTokensUsed() int

GetTotalTokensUsed returns the total number of tokens used since the agent was created

func (*Agent) Kind

func (agent *Agent) Kind() agents.Kind

Kind returns the agent type

func (*Agent) ResetMessages

func (agent *Agent) ResetMessages()

ResetMessages clears all messages except the system instruction

func (*Agent) ResetTelemetry added in v1.0.2

func (agent *Agent) ResetTelemetry()

ResetTelemetry resets all telemetry counters and stored data

func (*Agent) SetConfig added in v1.0.8

func (agent *Agent) SetConfig(config agents.Config)

SetConfig updates the agent configuration

func (*Agent) SetModelConfig added in v1.0.8

func (agent *Agent) SetModelConfig(config models.Config)

SetModelConfig updates the model configuration Note: This updates the stored config but doesn't regenerate the internal OpenAI params For most parameters to take effect, create a new agent with the new config

func (*Agent) SetTelemetryCallback added in v1.0.2

func (agent *Agent) SetTelemetryCallback(callback base.TelemetryCallback)

SetTelemetryCallback sets a callback for receiving telemetry events in real-time

type AgentOption

type AgentOption func(*BaseAgent)

type BaseAgent

type BaseAgent struct {
	*base.Agent
}

BaseAgent wraps the shared base.Agent for tools-specific functionality

func NewBaseAgent

func NewBaseAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig openai.ChatCompletionNewParams,
	options ...AgentOption,
) (toolsAgent *BaseAgent, err error)

NewBaseAgent creates a simplified Tools agent using the shared base agent

func (*BaseAgent) DetectParallelToolCalls added in v0.0.4

func (agent *BaseAgent) DetectParallelToolCalls(messages []openai.ChatCompletionMessageParamUnion, toolCallBack func(functionName string, arguments string) (string, error)) (string, []string, string, error)

NOTE: IMPORTANT: Not all LLMs with tool support support parallel tool calls.

func (*BaseAgent) DetectParallelToolCallsWitConfirmation added in v0.0.4

func (agent *BaseAgent) DetectParallelToolCallsWitConfirmation(
	messages []openai.ChatCompletionMessageParamUnion,
	toolCallBack func(functionName string, arguments string) (string, error),
	confirmationCallBack func(functionName string, arguments string) ConfirmationResponse) (string, []string, string, error)

TODO: -> Tools.Agent

func (*BaseAgent) DetectToolCallsLoop added in v0.0.4

func (agent *BaseAgent) DetectToolCallsLoop(messages []openai.ChatCompletionMessageParamUnion, toolCallBack func(functionName string, arguments string) (string, error)) (string, []string, string, error)

func (*BaseAgent) DetectToolCallsLoopStream added in v0.0.4

func (agent *BaseAgent) DetectToolCallsLoopStream(messages []openai.ChatCompletionMessageParamUnion, toolCallback func(functionName string, arguments string) (string, error), streamCallback func(content string) error) (string, []string, string, error)

func (*BaseAgent) DetectToolCallsLoopWithConfirmation added in v0.0.4

func (agent *BaseAgent) DetectToolCallsLoopWithConfirmation(
	messages []openai.ChatCompletionMessageParamUnion,
	toolCallBack func(functionName string, arguments string) (string, error),
	confirmationCallBack func(functionName string, arguments string) ConfirmationResponse) (string, []string, string, error)

func (*BaseAgent) DetectToolCallsLoopWithConfirmationStream added in v0.0.4

func (agent *BaseAgent) DetectToolCallsLoopWithConfirmationStream(
	messages []openai.ChatCompletionMessageParamUnion,
	toolCallback func(functionName string, arguments string) (string, error),
	confirmationCallBack func(functionName string, arguments string) ConfirmationResponse,
	streamCallback func(content string) error) (string, []string, string, error)

func (*BaseAgent) Kind

func (agent *BaseAgent) Kind() (kind agents.Kind)

type ConfirmationCallback

type ConfirmationCallback func(functionName string, arguments string) ConfirmationResponse

type ConfirmationResponse

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

type Parameter

type Parameter struct {
	Type        string `json:"type"`
	Description string `json:"description"`
}

Parameter represents a function parameter

type StreamCallback

type StreamCallback func(chunk string) error

StreamCallback is a function called for each chunk of streaming response

type Tool

type Tool struct {
	Name        string
	Description string
	Parameters  map[string]Parameter
	Required    []string
}

Tool represents a function tool with a fluent builder API

func NewTool

func NewTool(name string) *Tool

NewTool creates a new Tool with the given name

func (*Tool) AddParameter

func (t *Tool) AddParameter(name, paramType, description string, isRequired bool) *Tool

AddParameter adds a parameter to the tool paramType should be one of: "string", "number", "boolean", "object", "array" isRequired indicates whether the parameter is required

func (*Tool) GetDescription

func (t *Tool) GetDescription() string

GetDescription returns the description of the tool

func (*Tool) GetName

func (t *Tool) GetName() string

GetName returns the name of the tool

func (*Tool) GetParameters

func (t *Tool) GetParameters() map[string]Parameter

GetParameters returns the parameters of the tool

func (*Tool) GetRequired

func (t *Tool) GetRequired() []string

GetRequired returns the list of required parameter names

func (*Tool) SetDescription

func (t *Tool) SetDescription(description string) *Tool

SetDescription sets the description of the tool

func (*Tool) ToOpenAI

ToOpenAI converts the Tool to an OpenAI ChatCompletionToolUnionParam

type ToolAgentOption added in v0.0.2

type ToolAgentOption func(*openai.ChatCompletionNewParams)

ToolAgentOption is a functional option for configuring an Agent during creation

func WithMCPTools added in v0.0.2

func WithMCPTools(tools []mcp.Tool) ToolAgentOption

func WithOpenAITools added in v0.0.2

func WithOpenAITools(tools []openai.ChatCompletionToolUnionParam) ToolAgentOption

WithTools sets custom tools for the agent

func WithTools added in v0.0.2

func WithTools(tools []*Tool) ToolAgentOption

type ToolCallResult

type ToolCallResult struct {
	FinishReason         string
	Results              []string
	LastAssistantMessage string
}

ToolCallResult represents the result of tool call detection

type ToolCallback

type ToolCallback func(functionName string, arguments string) (string, error)

ToolCallback is a function called when a tool needs to be executed

Jump to

Keyboard shortcuts

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