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, toolCallback ToolCallback, ...) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoop(userMessages []messages.Message, toolCallback ToolCallback) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoopStream(userMessages []messages.Message, toolCallback ToolCallback, ...) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoopWithConfirmation(userMessages []messages.Message, toolCallback ToolCallback, ...) (*ToolCallResult, error)
- func (agent *Agent) DetectToolCallsLoopWithConfirmationStream(userMessages []messages.Message, toolCallback ToolCallback, ...) (*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) 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
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 ¶
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.
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) 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) 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