Incorrect parameters used when calling str_replace_editor tool – view_range used with str_replace command

#35
by wudaolj - opened

Hi everyone,

I'm using a function‑calling tool (str_replace_editor) that has several commands: view, create, str_replace, insert, undo_edit.

The tool definition expects:

  • For str_replace: command, path, old_str, new_str (required).
  • For view: command, path, and optionally view_range.

However, in my tool call I accidentally passed view_range while using the str_replace command, and I omitted the required old_str and new_str parameters.

  • Tool definition
        {
            "type": "function",
            "function": {
                "name": "str_replace_editor",
                "description": "Custom editing tool for viewing, creating and editing files in plain-text format\n* State is persistent across command calls and discussions with the user\n* If `path` is a file, `view` displays the result of applying `cat -n`. If `path` is a directory, `view` lists non-hidden files and directories up to 2 levels deep\n* The `create` command cannot be used if the specified `path` already exists as a file\n* If a `command` generates a long output, it will be truncated and marked with `<response clipped>`\n* The `undo_edit` command will revert the last edit made to the file at `path`\nNotes for using the `str_replace` command:\n* The `old_str` parameter should match EXACTLY one or more consecutive lines from the original file. Be mindful of whitespaces!\n* If the `old_str` parameter is not unique in the file, the replacement will not be performed. Make sure to include enough context in `old_str` to make it unique\n* The `new_str` parameter should contain the edited lines that should replace the `old_str`\n",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "command": {
                            "description": "The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`, `undo_edit`.",
                            "enum": [
                                "view",
                                "create",
                                "str_replace",
                                "insert",
                                "undo_edit"
                            ],
                            "type": "string"
                        },
                        "path": {
                            "description": "Absolute path to file or directory. On Unix/Linux/Mac use paths starting with `/` (e.g., `/workspace/file.py`). On Windows use Windows-style absolute paths (e.g., `C:\\workspace\\file.py`).",
                            "type": "string"
                        },
                        "file_text": {
                            "description": "Required parameter of `create` command, with the content of the file to be created.",
                            "type": "string"
                        },
                        "old_str": {
                            "description": "Required parameter of `str_replace` command containing the string in `path` to replace.",
                            "type": "string"
                        },
                        "new_str": {
                            "description": "Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert.",
                            "type": "string"
                        },
                        "insert_line": {
                            "description": "Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`.",
                            "type": "integer"
                        },
                        "view_range": {
                            "description": "Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file.",
                            "items": {
                                "type": "integer"
                            },
                            "type": "array"
                        }
                    },
                    "required": [
                        "command",
                        "path"
                    ]
                }
            }
        },
  • Response:
{
  "tool_calls": [
    {
      "function": {
        "arguments": "{\"command\": \"str_replace\", \"path\": \"/Users/default/Documents/project/src/index.tsx\", \"view_range\": [1, 10]}",
        "name": "str_replace_editor"
      },
      "id": "functions.str_replace_editor:6",
      "index": 0,
      "type": "function"
    }
  ]
}

Question:
What is the correct way to format the arguments for a str_replace operation with this tool? The view_range parameter is clearly invalid here – should I simply remove it and provide old_str + new_str? Or is there a different intended pattern?

Thank you for your help!

wudaolj changed discussion title from 调用 `str_replace_editor` 工具时使用了错误的参数 ——`view_range` 与 `str_replace` 命令一起使用 to Incorrect parameters used when calling str_replace_editor tool – view_range used with str_replace command

Sign up or log in to comment