[DOCS] Broken logic in Computer Use "agent loop" example code regarding Text Editor tool naming
Documentation Type
Unclear/confusing documentation
Documentation Location
https://platform.claude.com/docs/en/agents-and-tools/tool-use/computer-use-tool
Section/Topic
The section titled "Understanding the multi-agent loop", specifically the Python code block demonstrating the sampling_loop function.
Current Documentation
The current example code attempts to dynamically generate tool definitions using a tool_version variable:
# Configure tools - you should already have these initialized elsewhere
tools = [
{"type": f"computer_{tool_version}", "name": "computer", "display_width_px": 1024, "display_height_px": 768},
{"type": f"text_editor_{tool_version}", "name": "str_replace_editor"},
{"type": f"bash_{tool_version}", "name": "bash"}
]
What's Wrong or Missing?
The logic used to define the text editor tool is flawed because the required name of the tool changes depending on the version, but the code hardcodes the name as "str_replace_editor".
If a user sets tool_version to "20250728" (the version required for Claude 4 models), this code generates:{"type": "text_editor_20250728", "name": "str_replace_editor"}.
However, according to the Text Editor documentation, the text_editor_20250728 type must use the name str_replace_based_edit_tool. The name str_replace_editor is only valid for the older text_editor_20250124.
Consequently, running this example code with the latest tool version will result in an API error.
Suggested Improvement
The code example should be updated to handle the naming convention difference, or the dynamic f-string approach should be replaced with explicit definitions to avoid confusion.
Option A (Dynamic Logic Fix):
# Determine text editor name based on version
editor_name = "str_replace_based_edit_tool" if "20250728" in tool_version else "str_replace_editor"
# Configure tools
tools = [
{"type": f"computer_{tool_version}", "name": "computer", "display_width_px": 1024, "display_height_px": 768},
{"type": f"text_editor_{tool_version}", "name": editor_name},
{"type": f"bash_{tool_version}", "name": "bash"}
]
Option B (Explicit Definitions - Safer):
Remove the tool_version abstraction in this specific snippet and show the explicit configuration for the latest model to ensure users copy-paste working code.
Impact
High - Prevents users from using a feature
Additional Context
- Related documentation showing the correct naming conventions: https://platform.claude.com/docs/en/agents-and-tools/tool-use/text-editor-tool#model-compatibility
- The error usually manifests as a 400
invalid_request_errorregarding the tool definition when using Claude 4 models with this script.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗