Documentation
¶
Index ¶
- func ToOpenAITools(tools []*Tool) []openai.ChatCompletionToolUnionParam
- type Agent
- func (agent *Agent) AddMessage(role roles.Role, content string)
- func (agent *Agent) AddMessages(msgs []messages.Message)
- func (agent *Agent) DetectParallelToolCalls(userMessages []messages.Message, toolCallback ...ToolCallback) (*ToolCallResult, error)
- func (agent *Agent) DetectParallelToolCallsWithConfirmation(userMessages []messages.Message, callbacks ...any) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoop(userMessages []messages.Message, toolCallback ...ToolCallback) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoopStream(userMessages []messages.Message, streamCallback StreamCallback, ...) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoopWithConfirmation(userMessages []messages.Message, callbacks ...any) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoopWithConfirmationStream(userMessages []messages.Message, streamCallback StreamCallback, ...) (*ToolCallResult, error)
- func (agent *Agent) ExportMessagesToJSON() (string, error)
- func (agent *Agent) GetConfig() agents.Config
- func (agent *Agent) GetContext() context.Context
- func (agent *Agent) GetContextSize() int
- func (agent *Agent) GetLastRequestRawJSON() string
- func (agent *Agent) GetLastRequestSON() (string, error)
- func (agent *Agent) GetLastResponseJSON() (string, error)
- func (agent *Agent) GetLastResponseRawJSON() string
- func (agent *Agent) GetLastStateToolCalls() LastToolCallsState
- func (agent *Agent) GetMessages() []messages.Message
- func (agent *Agent) GetModelConfig() models.Config
- func (agent *Agent) GetModelID() string
- func (agent *Agent) GetName() string
- func (agent *Agent) GetTools() []openai.ChatCompletionToolUnionParam
- func (agent *Agent) Kind() agents.Kind
- func (agent *Agent) ResetLastStateToolCalls()
- func (agent *Agent) ResetMessages()
- func (agent *Agent) SetConfig(config agents.Config)
- func (agent *Agent) SetContext(ctx context.Context)
- func (agent *Agent) SetModelConfig(config models.Config)
- type AgentOption
- type BaseAgent
- func (agent *BaseAgent) DetectParallelToolCalls(messages []openai.ChatCompletionMessageParamUnion, ...) (string, []string, string, error)
- func (agent *BaseAgent) DetectParallelToolCallsWitConfirmation(messages []openai.ChatCompletionMessageParamUnion, ...) (string, []string, string, error)
- func (agent *BaseAgent) DetectToolCallsLoop(messages []openai.ChatCompletionMessageParamUnion, ...) (string, []string, string, error)
- func (agent *BaseAgent) DetectToolCallsLoopStream(messages []openai.ChatCompletionMessageParamUnion, ...) (string, []string, string, error)
- func (agent *BaseAgent) DetectToolCallsLoopWithConfirmation(messages []openai.ChatCompletionMessageParamUnion, ...) (string, []string, string, error)
- func (agent *BaseAgent) DetectToolCallsLoopWithConfirmationStream(messages []openai.ChatCompletionMessageParamUnion, ...) (string, []string, string, error)
- func (agent *BaseAgent) Kind() (kind agents.Kind)
- type ConfirmationCallback
- type ConfirmationResponse
- type LastToolCallsState
- type Parameter
- type StreamCallback
- type Tool
- func (t *Tool) AddParameter(name, paramType, description string, isRequired bool) *Tool
- func (t *Tool) GetDescription() string
- func (t *Tool) GetName() string
- func (t *Tool) GetParameters() map[string]Parameter
- func (t *Tool) GetRequired() []string
- func (t *Tool) SetDescription(description string) *Tool
- func (t *Tool) ToOpenAI() openai.ChatCompletionToolUnionParam
- type ToolAgentOption
- type ToolCallResult
- type ToolCallback
- type ToolExecutionResult
- type ToolsAgentOption
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, options ...any, ) (*Agent, error)
NewAgent creates a new simplified tools agent
func (*Agent) AddMessage ¶
AddMessage adds a message to the conversation history
func (*Agent) AddMessages ¶ added in v1.0.4
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. DetectParallelToolCalls detects and executes multiple tool calls in parallel The toolCallback parameter is optional. If not provided, uses the callback set via WithExecuteFn option.
func (*Agent) DetectParallelToolCallsWithConfirmation ¶ added in v0.0.4
func (agent *Agent) DetectParallelToolCallsWithConfirmation( userMessages []messages.Message, callbacks ...any, ) (*ToolCallResult, error)
NOTE: IMPORTANT: Not all LLMs with tool support support parallel tool calls. DetectParallelToolCallsWithConfirmation detects and executes multiple tool calls with user confirmation Optional callbacks can be provided in order: toolCallback, confirmationCallback Usage:
- DetectParallelToolCallsWithConfirmation(messages) → uses both from options
- DetectParallelToolCallsWithConfirmation(messages, toolCallback) → toolCallback from param, confirmationCallback from option
- DetectParallelToolCallsWithConfirmation(messages, toolCallback, confirmationCallback) → both from params
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 The toolCallback parameter is optional. If not provided, uses the callback set via WithExecuteFn option. If neither is provided, returns an error.
func (*Agent) DetectToolCallsLoopStream ¶ added in v0.0.4
func (agent *Agent) DetectToolCallsLoopStream( userMessages []messages.Message, streamCallback StreamCallback, toolCallback ...ToolCallback, ) (*ToolCallResult, error)
DetectToolCallsLoopStream sends messages and detects tool calls with streaming The toolCallback parameter is optional. If not provided, uses the callback set via WithExecuteFn option. The streamCallback parameter is required (it's the purpose of this method).
func (*Agent) DetectToolCallsLoopWithConfirmation ¶ added in v0.0.4
func (agent *Agent) DetectToolCallsLoopWithConfirmation( userMessages []messages.Message, callbacks ...any, ) (*ToolCallResult, error)
DetectToolCallsLoopWithConfirmation sends messages and detects tool calls with user confirmation Optional callbacks can be provided in order: toolCallback, confirmationCallback If not provided, uses callbacks set via WithExecuteFn and WithConfirmationPromptFn options. Usage:
- DetectToolCallsLoopWithConfirmation(messages) → uses both from options
- DetectToolCallsLoopWithConfirmation(messages, toolCallback) → toolCallback from param, confirmationCallback from option
- DetectToolCallsLoopWithConfirmation(messages, toolCallback, confirmationCallback) → both from params
func (*Agent) DetectToolCallsLoopWithConfirmationStream ¶ added in v0.0.4
func (agent *Agent) DetectToolCallsLoopWithConfirmationStream( userMessages []messages.Message, streamCallback StreamCallback, callbacks ...any, ) (*ToolCallResult, error)
DetectToolCallsLoopWithConfirmationStream sends messages and detects tool calls with confirmation and streaming The streamCallback parameter is required. Optional callbacks can be provided in order: toolCallback, confirmationCallback Usage:
- DetectToolCallsLoopWithConfirmationStream(messages, streamCallback) → uses both callbacks from options
- DetectToolCallsLoopWithConfirmationStream(messages, streamCallback, toolCallback) → toolCallback from param, confirmationCallback from option
- DetectToolCallsLoopWithConfirmationStream(messages, streamCallback, toolCallback, confirmationCallback) → both from params
func (*Agent) ExportMessagesToJSON ¶ added in v1.1.2
func (*Agent) GetContext ¶ added in v1.2.2
GetContext returns the agent's context
func (*Agent) GetContextSize ¶
GetContextSize returns the approximate size of the current context
func (*Agent) GetLastRequestRawJSON ¶ added in v1.1.2
func (*Agent) GetLastRequestSON ¶ added in v1.1.2
func (*Agent) GetLastResponseJSON ¶ added in v1.0.2
func (*Agent) GetLastResponseRawJSON ¶ added in v1.1.2
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 ¶
GetMessages returns all conversation messages
func (*Agent) GetModelConfig ¶ added in v1.0.8
GetModelConfig returns the model configuration
func (*Agent) GetModelID ¶ added in v0.0.7
func (*Agent) GetTools ¶ added in v1.3.2
func (agent *Agent) GetTools() []openai.ChatCompletionToolUnionParam
GetTools returns the tools configured for this agent
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) SetContext ¶ added in v1.2.2
SetContext updates the agent's context
func (*Agent) SetModelConfig ¶ added in v1.0.8
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 ¶
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 (*BaseAgent) DetectToolCallsLoopStream ¶ added in v0.0.4
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)
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 StreamCallback ¶
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 (*Tool) AddParameter ¶
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 ¶
GetDescription returns the description of the tool
func (*Tool) GetParameters ¶
GetParameters returns the parameters of the tool
func (*Tool) GetRequired ¶
GetRequired returns the list of required parameter names
func (*Tool) SetDescription ¶
SetDescription sets the description of the tool
func (*Tool) ToOpenAI ¶
func (t *Tool) ToOpenAI() openai.ChatCompletionToolUnionParam
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 ¶
ToolCallResult represents the result of tool call detection
type ToolCallback ¶
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
type ToolsAgentOption ¶ added in v1.2.9
type ToolsAgentOption func(*Agent)
ToolsAgentOption is a functional option for configuring lifecycle hooks on the Agent
func AfterCompletion ¶ added in v1.2.9
func AfterCompletion(fn func(*Agent)) ToolsAgentOption
AfterCompletion sets a hook that is called after each tool call detection
func BeforeCompletion ¶ added in v1.2.9
func BeforeCompletion(fn func(*Agent)) ToolsAgentOption
BeforeCompletion sets a hook that is called before each tool call detection
func WithConfirmationPromptFn ¶ added in v1.3.2
func WithConfirmationPromptFn(fn ConfirmationCallback) ToolsAgentOption
WithConfirmationPromptFn sets the default confirmation callback for the agent This callback will be used by all confirmation methods if no callback is explicitly provided
func WithExecuteFn ¶ added in v1.3.2
func WithExecuteFn(fn ToolCallback) ToolsAgentOption
WithExecuteFn sets the default tool execution callback for the agent This callback will be used by all detection methods if no callback is explicitly provided