refactor(tools): removing pointer map

This is not needed
This commit is contained in:
2025-04-05 14:59:50 +01:00
parent 5278727c51
commit e101070851
3 changed files with 6 additions and 6 deletions

View File

@ -204,7 +204,7 @@ func CreateAgentClient(prompt string) (AgentClient, error) {
}, },
ToolHandler: ToolsHandlers{ ToolHandler: ToolsHandlers{
handlers: &map[string]ToolHandler{}, handlers: map[string]ToolHandler{},
}, },
}, nil }, nil
} }

View File

@ -17,7 +17,7 @@ type ToolHandler struct {
} }
type ToolsHandlers struct { type ToolsHandlers struct {
handlers *map[string]ToolHandler handlers map[string]ToolHandler
} }
var NoToolCallError = errors.New("An assistant tool call with no tool calls was provided.") var NoToolCallError = errors.New("An assistant tool call with no tool calls was provided.")
@ -33,7 +33,7 @@ func (handler ToolsHandlers) Handle(info ToolHandlerInfo, toolCallMessage AgentA
fnName := toolCall.Function.Name fnName := toolCall.Function.Name
arguments := toolCall.Function.Arguments arguments := toolCall.Function.Arguments
fnHandler, exists := (*handler.handlers)[fnName] fnHandler, exists := handler.handlers[fnName]
if !exists { if !exists {
return []AgentTextMessage{}, errors.New("Could not find tool with this name.") return []AgentTextMessage{}, errors.New("Could not find tool with this name.")
} }
@ -58,8 +58,8 @@ func (handler ToolsHandlers) Handle(info ToolHandlerInfo, toolCallMessage AgentA
return responses, nil return responses, nil
} }
func (handler ToolsHandlers) AddTool(name string, fn func(info ToolHandlerInfo, args string, call ToolCall) (any, error)) { func (handler *ToolsHandlers) AddTool(name string, fn func(info ToolHandlerInfo, args string, call ToolCall) (any, error)) {
(*handler.handlers)[name] = ToolHandler{ handler.handlers[name] = ToolHandler{
Fn: func(info ToolHandlerInfo, args string, call ToolCall) (string, error) { Fn: func(info ToolHandlerInfo, args string, call ToolCall) (string, error) {
res, err := fn(info, args, call) res, err := fn(info, args, call)
if err != nil { if err != nil {

View File

@ -16,7 +16,7 @@ type ToolTestSuite struct {
func (suite *ToolTestSuite) SetupTest() { func (suite *ToolTestSuite) SetupTest() {
suite.handler = ToolsHandlers{ suite.handler = ToolsHandlers{
handlers: &map[string]ToolHandler{}, handlers: map[string]ToolHandler{},
} }
suite.handler.AddTool("a", func(info ToolHandlerInfo, args string, call ToolCall) (any, error) { suite.handler.AddTool("a", func(info ToolHandlerInfo, args string, call ToolCall) (any, error) {