-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: error from ontap_get retry as debug #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -172,6 +172,10 @@ func (a *Agent) ChatWithResponse(ctx context.Context, t *testing.T, userMessage | |||||||||||||||||||
| tools := a.convertMCPToolsToOpenAI() | ||||||||||||||||||||
| maxIterations := 10 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var errFound error | ||||||||||||||||||||
| failedTool := "" | ||||||||||||||||||||
| argsUsed := make(map[string]any) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| for range maxIterations { | ||||||||||||||||||||
| completion, err := a.openaiClient.Chat.Completions.New(ctx, openai.ChatCompletionNewParams{ | ||||||||||||||||||||
| Model: a.model, | ||||||||||||||||||||
|
|
@@ -185,7 +189,6 @@ func (a *Agent) ChatWithResponse(ctx context.Context, t *testing.T, userMessage | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| assistantMessage := completion.Choices[0].Message | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if len(assistantMessage.ToolCalls) == 0 { | ||||||||||||||||||||
| return assistantMessage.Content, nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -205,20 +208,23 @@ func (a *Agent) ChatWithResponse(ctx context.Context, t *testing.T, userMessage | |||||||||||||||||||
| result, err := a.callMCPTool(ctx, toolName, args) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| if expectedOntapErrorStr != "" && strings.Contains(err.Error(), expectedOntapErrorStr) { | ||||||||||||||||||||
| slog.Debug("Expected tool error", slog.String("tool", toolName), slog.Any("error", err)) | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| t.Errorf("Tool %q returned error LLM will retry: %v", toolName, err) | ||||||||||||||||||||
| return "", nil // test passed, expected error was observed | ||||||||||||||||||||
| } | ||||||||||||||||||||
| failedTool = toolName | ||||||||||||||||||||
| argsUsed = args | ||||||||||||||||||||
| errFound = err | ||||||||||||||||||||
| slog.Warn("LLM will retry", slog.String("tool", toolName), slog.Any("args", args), slog.Any("error", err)) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+213
to
+217
|
||||||||||||||||||||
| result = "Error: " + err.Error() | ||||||||||||||||||||
|
Comment on lines
209
to
218
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| slog.Debug("", slog.Any("Tool result", result)) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| messages = append(messages, openai.ToolMessage(result, toolCall.ID)) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return "", fmt.Errorf("max iterations (%d) reached without final assistant message", maxIterations) | ||||||||||||||||||||
| t.Errorf("Tool %q args %v returned error %v", failedTool, argsUsed, errFound) | ||||||||||||||||||||
| return "", fmt.Errorf("max iterations (%d) reached; last tool %q args %v error: %w", maxIterations, failedTool, argsUsed, errFound) | ||||||||||||||||||||
|
Comment on lines
+226
to
+227
|
||||||||||||||||||||
| t.Errorf("Tool %q args %v returned error %v", failedTool, argsUsed, errFound) | |
| return "", fmt.Errorf("max iterations (%d) reached; last tool %q args %v error: %w", maxIterations, failedTool, argsUsed, errFound) | |
| if errFound != nil { | |
| t.Errorf("Tool %q args %v returned error %v", failedTool, argsUsed, errFound) | |
| return "", fmt.Errorf("max iterations (%d) reached; last tool %q args %v error: %w", maxIterations, failedTool, argsUsed, errFound) | |
| } | |
| t.Errorf("max iterations (%d) reached without completing response", maxIterations) | |
| return "", fmt.Errorf("max iterations (%d) reached without completing response", maxIterations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argsUsed := make(map[string]any)is immediately overwritten viaargsUsed = args; the initial allocation is unused. You can declare it asvar argsUsed map[string]any(or assign when the failure occurs) to avoid the extra allocation.