From 473175ee4ec2292b0b8c66fe5292894b38086e9c Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Fri, 22 Aug 2025 19:11:15 +0200 Subject: [PATCH] chore: lint --- agent.go | 2 +- agent_stream_test.go | 2 +- agent_test.go | 31 ++++++++++++++++++++----- examples/agent/main.go | 1 - examples/streaming-agent-simple/main.go | 1 - examples/streaming-agent/main.go | 1 - providers/openai.go | 3 --- providers/openai_test.go | 2 +- tool_test.go | 1 - 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/agent.go b/agent.go index 6fe6af5fbd458b49535022dba423060df2012157..5ac8b568d5dd8ee53533dd1305d74bfe767af168 100644 --- a/agent.go +++ b/agent.go @@ -1002,7 +1002,7 @@ func (a *agent) processStepStream(ctx context.Context, stream StreamResponse, op var stepContent []Content var stepToolCalls []ToolCallContent var stepUsage Usage - var stepFinishReason FinishReason = FinishReasonUnknown + stepFinishReason := FinishReasonUnknown var stepWarnings []CallWarning var stepProviderMetadata ProviderMetadata diff --git a/agent_stream_test.go b/agent_stream_test.go index 7b4aec4d4943560c8903e7d7aad9983444093d6c..e11011e8b308f95059be9c7d0c076c2ac2ff34e1 100644 --- a/agent_stream_test.go +++ b/agent_stream_test.go @@ -565,4 +565,4 @@ func TestStreamingAgentSources(t *testing.T) { // Verify sources are in final result resultSources := result.Response.Content.Sources() require.Equal(t, 2, len(resultSources)) -} \ No newline at end of file +} diff --git a/agent_test.go b/agent_test.go index 41632913a7043e2985cd19f3f1a45b4257365691..d50c87ca723a7dbccf8ce92cff39714fffd6e450 100644 --- a/agent_test.go +++ b/agent_test.go @@ -786,6 +786,7 @@ func TestStopConditions(t *testing.T) { } t.Run("StepCountIs", func(t *testing.T) { + t.Parallel() condition := StepCountIs(2) // Should not stop with 1 step @@ -802,6 +803,7 @@ func TestStopConditions(t *testing.T) { }) t.Run("HasToolCall", func(t *testing.T) { + t.Parallel() condition := HasToolCall("search") // Should not stop when tool not called @@ -822,6 +824,7 @@ func TestStopConditions(t *testing.T) { }) t.Run("HasContent", func(t *testing.T) { + t.Parallel() reasoningCondition := HasContent(ContentTypeReasoning) fileCondition := HasContent(ContentTypeFile) @@ -837,6 +840,7 @@ func TestStopConditions(t *testing.T) { }) t.Run("FinishReasonIs", func(t *testing.T) { + t.Parallel() stopCondition := FinishReasonIs(FinishReasonStop) lengthCondition := FinishReasonIs(FinishReasonLength) @@ -870,6 +874,7 @@ func TestStopConditions_Integration(t *testing.T) { t.Parallel() t.Run("StepCountIs integration", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -898,6 +903,7 @@ func TestStopConditions_Integration(t *testing.T) { }) t.Run("Multiple stop conditions", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -934,6 +940,7 @@ func TestPrepareStep(t *testing.T) { t.Parallel() t.Run("System prompt modification", func(t *testing.T) { + t.Parallel() var capturedSystemPrompt string model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { @@ -977,6 +984,7 @@ func TestPrepareStep(t *testing.T) { }) t.Run("Tool choice modification", func(t *testing.T) { + t.Parallel() var capturedToolChoice *ToolChoice model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { @@ -1014,6 +1022,7 @@ func TestPrepareStep(t *testing.T) { }) t.Run("Active tools modification", func(t *testing.T) { + t.Parallel() var capturedToolNames []string model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { @@ -1058,6 +1067,7 @@ func TestPrepareStep(t *testing.T) { }) t.Run("No tools when DisableAllTools is true", func(t *testing.T) { + t.Parallel() var capturedToolCount int model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { @@ -1095,6 +1105,7 @@ func TestPrepareStep(t *testing.T) { }) t.Run("All fields modified together", func(t *testing.T) { + t.Parallel() var capturedSystemPrompt string var capturedToolChoice *ToolChoice var capturedToolNames []string @@ -1158,6 +1169,7 @@ func TestPrepareStep(t *testing.T) { }) t.Run("Nil fields use parent values", func(t *testing.T) { + t.Parallel() var capturedSystemPrompt string var capturedToolChoice *ToolChoice var capturedToolNames []string @@ -1218,6 +1230,7 @@ func TestPrepareStep(t *testing.T) { }) t.Run("Empty ActiveTools means all tools", func(t *testing.T) { + t.Parallel() var capturedToolNames []string model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { @@ -1265,6 +1278,7 @@ func TestToolCallRepair(t *testing.T) { t.Parallel() t.Run("Valid tool call passes validation", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -1305,12 +1319,13 @@ func TestToolCallRepair(t *testing.T) { require.Len(t, result.Steps, 1) // Only one step since FinishReason is stop // Check that tool call was executed successfully - toolCalls := result.Steps[0].Response.Content.ToolCalls() + toolCalls := result.Steps[0].Content.ToolCalls() require.Len(t, toolCalls, 1) require.False(t, toolCalls[0].Invalid) // Should be valid }) t.Run("Invalid tool call without repair function", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -1348,13 +1363,14 @@ func TestToolCallRepair(t *testing.T) { require.Len(t, result.Steps, 1) // Only one step // Check that tool call was marked as invalid - toolCalls := result.Steps[0].Response.Content.ToolCalls() + toolCalls := result.Steps[0].Content.ToolCalls() require.Len(t, toolCalls, 1) require.True(t, toolCalls[0].Invalid) // Should be invalid require.Contains(t, toolCalls[0].ValidationError.Error(), "missing required parameter: value") }) t.Run("Invalid tool call with successful repair", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -1402,13 +1418,14 @@ func TestToolCallRepair(t *testing.T) { require.Len(t, result.Steps, 1) // Only one step // Check that tool call was repaired and is now valid - toolCalls := result.Steps[0].Response.Content.ToolCalls() + toolCalls := result.Steps[0].Content.ToolCalls() require.Len(t, toolCalls, 1) require.False(t, toolCalls[0].Invalid) // Should be valid after repair require.Equal(t, `{"value": "repaired"}`, toolCalls[0].Input) // Should have repaired input }) t.Run("Invalid tool call with failed repair", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -1451,13 +1468,14 @@ func TestToolCallRepair(t *testing.T) { require.Len(t, result.Steps, 1) // Only one step // Check that tool call was marked as invalid since repair failed - toolCalls := result.Steps[0].Response.Content.ToolCalls() + toolCalls := result.Steps[0].Content.ToolCalls() require.Len(t, toolCalls, 1) require.True(t, toolCalls[0].Invalid) // Should be invalid require.Contains(t, toolCalls[0].ValidationError.Error(), "missing required parameter: value") }) t.Run("Nonexistent tool call", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -1488,13 +1506,14 @@ func TestToolCallRepair(t *testing.T) { require.Len(t, result.Steps, 1) // Only one step // Check that tool call was marked as invalid due to nonexistent tool - toolCalls := result.Steps[0].Response.Content.ToolCalls() + toolCalls := result.Steps[0].Content.ToolCalls() require.Len(t, toolCalls, 1) require.True(t, toolCalls[0].Invalid) // Should be invalid require.Contains(t, toolCalls[0].ValidationError.Error(), "tool not found: nonexistent_tool") }) t.Run("Invalid JSON in tool call", func(t *testing.T) { + t.Parallel() model := &mockLanguageModel{ generateFunc: func(ctx context.Context, call Call) (*Response, error) { return &Response{ @@ -1532,7 +1551,7 @@ func TestToolCallRepair(t *testing.T) { require.Len(t, result.Steps, 1) // Only one step // Check that tool call was marked as invalid due to invalid JSON - toolCalls := result.Steps[0].Response.Content.ToolCalls() + toolCalls := result.Steps[0].Content.ToolCalls() require.Len(t, toolCalls, 1) require.True(t, toolCalls[0].Invalid) // Should be invalid require.Contains(t, toolCalls[0].ValidationError.Error(), "invalid JSON input") diff --git a/examples/agent/main.go b/examples/agent/main.go index 35972979c3482a9aaf83da0708f053fdedbcab7e..c6d563e2f192dec7888b518b0a32703366d9b739 100644 --- a/examples/agent/main.go +++ b/examples/agent/main.go @@ -44,7 +44,6 @@ func main() { if c.GetType() == ai.ContentTypeToolCall { tc, _ := ai.AsContentType[ai.ToolCallContent](c) fmt.Println("ToolCall: ", tc.ToolName) - } } } diff --git a/examples/streaming-agent-simple/main.go b/examples/streaming-agent-simple/main.go index 2c84ae5c94085ee38add7353d35e87dba50a8c41..00eb7177911bb31b93393f0b96af1d0004c286e0 100644 --- a/examples/streaming-agent-simple/main.go +++ b/examples/streaming-agent-simple/main.go @@ -84,4 +84,3 @@ func main() { fmt.Printf("\n\nFinal result: %s\n", result.Response.Content.Text()) fmt.Printf("Steps: %d, Total tokens: %d\n", len(result.Steps), result.TotalUsage.TotalTokens) } - diff --git a/examples/streaming-agent/main.go b/examples/streaming-agent/main.go index da7ef79db9e91cb45b3095404e2762f58769d408..4222277fc8afc17b06d0eb295ff18a0ce1a4fa9b 100644 --- a/examples/streaming-agent/main.go +++ b/examples/streaming-agent/main.go @@ -262,4 +262,3 @@ func main() { fmt.Println("✨ Example completed successfully!") } - diff --git a/providers/openai.go b/providers/openai.go index 300570680f981f66ea58060847d70be19fa9427b..9c3d4a07e6a7733f3f781582e1e2e22511bb99a4 100644 --- a/providers/openai.go +++ b/providers/openai.go @@ -634,7 +634,6 @@ func (o openAILanguageModel) Stream(ctx context.Context, call ai.Call) (ai.Strea existingToolCall.hasFinished = true toolCalls[toolCallDelta.Index] = existingToolCall } - } else { // Does not exist var err error @@ -721,7 +720,6 @@ func (o openAILanguageModel) Stream(ctx context.Context, call ai.Call) (ai.Strea } } } - } err := stream.Err() if err == nil || errors.Is(err, io.EOF) { @@ -766,7 +764,6 @@ func (o openAILanguageModel) Stream(ctx context.Context, call ai.Call) (ai.Strea ProviderMetadata: streamProviderMetadata, }) return - } else { yield(ai.StreamPart{ Type: ai.StreamPartTypeError, diff --git a/providers/openai_test.go b/providers/openai_test.go index 1b52399f40884bd40a45e71a14a3276cc68eb497..34f54c5a4602d3008fd354fa76aa6510240d7de6 100644 --- a/providers/openai_test.go +++ b/providers/openai_test.go @@ -2247,7 +2247,7 @@ func TestDoStream(t *testing.T) { require.True(t, len(parts) >= 4) // text-start, deltas, text-end, finish // Find text parts - var textStart, textEnd, finish int = -1, -1, -1 + textStart, textEnd, finish := -1, -1, -1 var deltas []string for i, part := range parts { diff --git a/tool_test.go b/tool_test.go index ea1ab76673eb018d416175f716b0b301c63889c8..8c9caf6389a138358402999bcfa636a5863c389f 100644 --- a/tool_test.go +++ b/tool_test.go @@ -208,4 +208,3 @@ func TestSchemaToParameters(t *testing.T) { t.Errorf("Expected 3 enum values, got %v", enumValues) } } -