Skip to content
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

HTTP 400 for Claude 3.5, "messages.4.content.0.tool_result.tool_use_id: Field required" #3397

Open
3 tasks done
stefan-girlich opened this issue Dec 16, 2024 · 0 comments
Open
3 tasks done
Assignees
Labels
kind:bug Indicates an unexpected problem or unintended behavior "needs-triage" priority:medium Indicates medium priority

Comments

@stefan-girlich
Copy link

stefan-girlich commented Dec 16, 2024

Before submitting your bug report

Relevant environment info

- OS: MacOS
- Continue version: 0.8.62 - 2024-12-10
- IDE version: 1.95.3
- Model: Claude Sonnet 3.5 via OpenRouter
- config.json:
  
{
  "models": [
    {
      "title": "Anthropic: Claude 3.5 Sonnet",
      "provider": "openai",
      "model": "anthropic/claude-3.5-sonnet",
      "contextLength": 200000,
      "apiBase": "https://openrouter.ai/api/v1",
      "apiKey": "redacted",
      "requestOptions": {
        "extraBodyProperties": {
          "transforms": []
        }
      }
    }
  ],
  "tabAutocompleteModel": {
    "title": "Tab Autocomplete Model",
    "provider": "ollama",
    "model": "qwen2.5-coder:1.5b"
  },
  "customCommands": [ /* defaults */],,
  "contextProviders": [ /* defaults */],
  "slashCommands": [ /* defaults */],,
  "embeddingsProvider": {
    "provider": "free-trial"
  },
  "reranker": {
    "name": "free-trial"
  }
}

  

Related: The [Discord invite](https://discord.gg/NWtdYexhMs) linked in the bug template is invalid.

Description

When the extension tries to use a tool (i.e. for reading a file), it fails with an API error from Claude.
This seems to be related to the introduction of tools. It would be great to be able to disable tools for now as a workaround.

To reproduce

  1. Mark a line of code, i.e. // eslint-disable-next-line max-classes-per-file
  2. Press Cmd+L to add selection to chat
  3. Enter "i want to disable this globally via tsconfig.json" as a prompt
  4. Fails with error:
{
  "message": "Provider returned error",
  "code": 400,
  "metadata": {
    "raw": "{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.4.content.0.tool_result.tool_use_id: Field required\"}}",
    "provider_name": "Anthropic"
  }
}

Log output

"Error handling webview message"
Error handling webview message: {
  "msg": {
    "messageId": "9f717652-106d-4265-aa75-46fe57299bb7",
    "messageType": "llm/streamChat",
    "data": {
      "messages": [
        {
          "role": "system",
          "content": "When generating new code:\n\n1. Always produce a single code block.\n2. Never separate the code into multiple code blocks.\n3. Only include the code that is being added.\n4. Replace existing code with a \"lazy\" comment like this: \"// ... existing code ...\"\n5. The \"lazy\" comment must always be a valid comment in the current context (e.g. \"<!-- ... existing code ... -->\" for HTML, \"// ... existing code ...\" for JavaScript, \"{/* ... existing code */}\" for TSX, etc.)\n6. You must always provide 1-2 lines of context above and below a \"lazy\" comment\n7. If the user submits a code block that contains a filename in the language specifier, always include the filename in any code block you generate based on that file. The filename should be on the same line as the language specifier in your code block.\n\nExample 1:\nInput:\ntest.js\nimport addition from \"addition\"\n\nclass Calculator {\n  constructor() {\n    this.result = 0;\n  }\n    \n  add(number) {\n    this.result += number;\n    return this;\n  }\n}\n```\nUser request: Add a subtract method\n\nOutput:\n```javascript test.js\n// ... existing code ...\nimport subtraction from \"subtraction\"\n\nclass Calculator {\n  // ... existing code ...\n  \n  subtract(number) {\n    this.result -= number;\n    return this;\n  }\n}\n```\n\nExample 2:\nInput:\n```javascript test.js (6-9)\nfunction helloWorld() {}\n```\n\nOutput:\n```javascript test.js\nfunction helloWorld() {\n  // New code here\n}\n```\n\nAlways follow these guidelines when generating code responses.\n\nWhen using tools, follow the following guidelines:\n- Avoid calling tools unless they are absolutely necessary. For example, if you are asked a simple programming question you do not need web search. As another example, if the user asks you to explain something about code, do not create a new file."
        },
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "i want to disable this completely in tsconfig.json"
            }
          ]
        },
        {
          "role": "assistant",
          "content": "I'll help you, but I need to know what specifically you want to disable in the tsconfig.json file. Could you please:\n\n1. Share what you're looking at (the specific rule or configuration), or\n2. Show me the current tsconfig.json contents\n\nOnce you provide this information, I can help you disable the specific configuration you're referring to.\n\nI can use the `read_file` tool to look at your tsconfig.json if it exists, or help you modify the right setting once you clarify what you want to disable."
        },
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "eslint-disable-next-line max-classes-per-file"
            }
          ]
        },
        {
          "role": "assistant",
          "content": "Ah, you want to disable the `max-classes-per-file` ESLint rule completely. This should be done in your ESLint configuration file (not tsconfig.json, since this is an ESLint rule rather than a TypeScript configuration).\n\nLet me help you locate and modify your ESLint config:"
        },
        {
          "role": "assistant",
          "content": "",
          "toolCalls": [
            {
              "id": "toolu_vrtx_01Ktkrmb4xtr7oxj1ZaqoD6k",
              "type": "function",
              "function": {
                "name": "run_terminal_command",
                "arguments": "{\"command\": \"ls .eslintrc*\"}"
              }
            }
          ]
        },
        {
          "role": "tool",
          "content": ".eslintrc.cjs\n",
          "toolCallId": "toolu_vrtx_01Ktkrmb4xtr7oxj1ZaqoD6k"
        },
        {
          "role": "user",
          "content": [
            {
              "type": "text",
              "text": "what?"
            }
          ]
        },
        {
          "role": "assistant",
          "content": ""
        }
      ],
      "title": "Anthropic: Claude 3.5 Sonnet",
      "completionOptions": {
        "tools": [
          {
            "type": "function",
            "displayTitle": "Read File",
            "wouldLikeTo": "read {{{ filepath }}}",
            "readonly": true,
            "function": {
              "name": "read_file",
              "description": "Use this tool whenever you need to view the contents of a file.",
              "parameters": {
                "type": "object",
                "required": [
                  "filepath"
                ],
                "properties": {
                  "filepath": {
                    "type": "string",
                    "description": "The path of the file to read, relative to the root of the workspace."
                  }
                }
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "Create New File",
            "wouldLikeTo": "create a new file",
            "readonly": false,
            "function": {
              "name": "create_new_file",
              "description": "Create a new file",
              "parameters": {
                "type": "object",
                "required": [
                  "filepath",
                  "contents"
                ],
                "properties": {
                  "filepath": {
                    "type": "string",
                    "description": "The path where the new file should be created"
                  },
                  "contents": {
                    "type": "string",
                    "description": "The contents to write to the new file"
                  }
                }
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "Run Terminal Command",
            "wouldLikeTo": "run a terminal command",
            "readonly": false,
            "function": {
              "name": "run_terminal_command",
              "description": "Run a terminal command in the current directory. The shell is not stateful and will not remember any previous commands.",
              "parameters": {
                "type": "object",
                "required": [
                  "command"
                ],
                "properties": {
                  "command": {
                    "type": "string",
                    "description": "The command to run. This will be passed directly into the shell."
                  }
                }
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "View Subdirectory",
            "wouldLikeTo": "view the contents of \"{{{ directory_path }}}\"",
            "readonly": true,
            "function": {
              "name": "view_subdirectory",
              "description": "View the contents of a subdirectory",
              "parameters": {
                "type": "object",
                "required": [
                  "directory_path"
                ],
                "properties": {
                  "directory_path": {
                    "type": "string",
                    "description": "The path of the subdirectory to view, relative to the root of the workspace"
                  }
                }
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "View Repo Map",
            "wouldLikeTo": "view the repository map",
            "readonly": true,
            "function": {
              "name": "view_repo_map",
              "description": "View the repository map",
              "parameters": {
                "type": "object",
                "properties": {}
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "Exact Search",
            "wouldLikeTo": "search for \"{{{ query }}}\" in the repository",
            "readonly": true,
            "function": {
              "name": "exact_search",
              "description": "Perform an exact search over the repository using ripgrep.",
              "parameters": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "The search query to use. Must be a valid ripgrep regex expression, escaped where needed"
                  }
                }
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "Search Web",
            "wouldLikeTo": "search the web for \"{{{ query }}}\"",
            "readonly": true,
            "function": {
              "name": "search_web",
              "description": "Performs a web search, returning top results. This tool should only be called for questions that require external knowledge. Common programming questions do not require web search.",
              "parameters": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "repo_url": {
                    "type": "string",
                    "description": "The natural language search query"
                  }
                }
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "View Diff",
            "wouldLikeTo": "view a diff",
            "readonly": true,
            "function": {
              "name": "view_diff",
              "description": "View the current diff of working changes",
              "parameters": {
                "type": "object",
                "properties": {}
              }
            }
          },
          {
            "type": "function",
            "displayTitle": "Read Currently Open File",
            "wouldLikeTo": "read the current file",
            "readonly": true,
            "function": {
              "name": "read_currently_open_file",
              "description": "Read the currently open file in the IDE. If the user seems to be referring to a file that you can't see, this is probably it.",
              "parameters": {
                "type": "object",
                "properties": {}
              }
            }
          }
        ]
      }
    }
  }
}



Error: Malformed JSON sent from server: {"error":{"message":"Provider returned error","code":400,"metadata":{"raw":"{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.4.content.0.tool_result.tool_use_id: Field required\"}}","provider_name":"Anthropic"}},"user_id":"user_2mTwE3f3DFZcYEYtuRwawtXe13P"}
Error in API response
{
  "message": "Provider returned error",
  "code": 400,
  "metadata": {
    "raw": "{\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.4.content.0.tool_result.tool_use_id: Field required\"}}",
    "provider_name": "Anthropic"
  }
}
@sestinj sestinj self-assigned this Dec 16, 2024
@dosubot dosubot bot added kind:bug Indicates an unexpected problem or unintended behavior priority:medium Indicates medium priority labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior "needs-triage" priority:medium Indicates medium priority
Projects
None yet
Development

No branches or pull requests

2 participants