tools

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 16 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) ExportMessagesToJSON added in v1.1.2

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

func (*Agent) GetConfig added in v1.0.8

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

GetConfig returns the agent configuration

func (*Agent) GetContext added in v1.2.2

func (agent *Agent) GetContext() context.Context

GetContext returns the agent's context

func (*Agent) GetContextSize

func (agent *Agent) GetContextSize() int

GetContextSize returns the approximate size of the current context

func (*Agent) GetLastRequestRawJSON added in v1.1.2

func (agent *Agent) GetLastRequestRawJSON() string

func (*Agent) GetLastRequestSON added in v1.1.2

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

func (*Agent) GetLastResponseJSON added in v1.0.2

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

func (*Agent) GetLastResponseRawJSON added in v1.1.2

func (agent *Agent) GetLastResponseRawJSON() string

func (*Agent) GetLastStateToolCalls added in v1.1.8

func (agent *Agent) GetLastStateToolCalls() LastToolCallsState

GetLastStatedToolCalls returns the last stated tool calls state

  • IMPORTANT: Allows checking the state of tool calls across multiple invocations
  • USEFUL: for maintaining continuity in tool call confirmations and executions

and when transfering context between different agent instances

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) Kind

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

Kind returns the agent type

func (*Agent) ResetLastStateToolCalls added in v1.1.8

func (agent *Agent) ResetLastStateToolCalls()

func (*Agent) ResetMessages

func (agent *Agent) ResetMessages()

ResetMessages clears all messages except the system instruction

func (*Agent) SetConfig added in v1.0.8

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

SetConfig updates the agent configuration

func (*Agent) SetContext added in v1.2.2

func (agent *Agent) SetContext(ctx context.Context)

SetContext updates the agent's context

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

type AgentOption

type AgentOption func(*BaseAgent)

type BaseAgent

type BaseAgent struct {
	*base.Agent
	// contains filtered or unexported fields
}

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 LastToolCallsState added in v1.1.8

type LastToolCallsState struct {
	// If a tool call is awaiting user confirmation
	// Possible values: `Confirmed`, `Denied`, `Quit`
	// Denied: do not execute the tool call, but continue the flow
	// Quit: stop the entire agent execution (exit loop)
	Confirmation    ConfirmationResponse
	ExecutionResult ToolExecutionResult
}

WIP: GOAL: be able to check state of tool calls across multiple invocations

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

type ToolExecutionResult added in v1.1.8

type ToolExecutionResult struct {
	Content    string
	ShouldStop bool
	// Possible values: "function_executed", "user_denied", "user_quit", "error", "exit_loop"
	ExecFinishReason string
}

ToolExecutionResult holds the result of a tool execution

Jump to

Keyboard shortcuts

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