lint: preallocate slices

Andrey Nering created

Change summary

agent.go            | 2 +-
content.go          | 2 +-
providers/openai.go | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

Detailed changes

agent.go 🔗

@@ -841,7 +841,7 @@ func (a *agent) Stream(ctx context.Context, opts AgentStreamCall) (*AgentResult,
 }
 
 func (a *agent) prepareTools(tools []AgentTool, activeTools []string, disableAllTools bool) []Tool {
-	var preparedTools []Tool
+	preparedTools := make([]Tool, 0, len(tools))
 
 	// If explicitly disabling all tools, return no tools
 	if disableAllTools {

content.go 🔗

@@ -469,7 +469,7 @@ func NewUserMessage(prompt string, files ...FilePart) Message {
 }
 
 func NewSystemMessage(prompt ...string) Message {
-	var content []MessagePart
+	content := make([]MessagePart, 0, len(prompt))
 	for _, p := range prompt {
 		content = append(content, TextPart{Text: p})
 	}

providers/openai.go 🔗

@@ -436,7 +436,7 @@ func (o openAiLanguageModel) Generate(ctx context.Context, call ai.Call) (*ai.Re
 		return nil, errors.New("no response generated")
 	}
 	choice := response.Choices[0]
-	var content []ai.Content
+	content := make([]ai.Content, 0, 1+len(choice.Message.ToolCalls)+len(choice.Message.Annotations))
 	text := choice.Message.Content
 	if text != "" {
 		content = append(content, ai.TextContent{