Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions aworld/experimental/cast/tools/cast_coder_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ def bar():
name="operation_json",
type="string",
required=True,
desc="""JSON format precise search and replace operation instruction. Format:
{
desc="""⚠️ IMPORTANT: This parameter MUST be a valid JSON STRING (not a JSON object).

JSON string format for precise search and replace operation:
'{
"operation": {
"type": "search_replace",
"file_path": "path/to/your/file.py",
Expand All @@ -165,13 +167,37 @@ def bar():
"exact_match_only": true,
"replace_all": false
}
}
}'

Required Parameters:
- type (string): Must be "search_replace"
- file_path (string): Relative path from source_dir (e.g., "src/main.py", "requirements.txt")
- search (string): Complete code lines to find. Use empty string "" for full file replacement or new file creation
- replace (string): Replacement content or full file content

Optional Parameters:
- exact_match_only (boolean): Fixed as true (default behavior)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The description for exact_match_only is slightly misleading. Stating it is "Fixed as true" can be confusing, as it is a configurable parameter. This contradicts the overall action description which mentions flexible and similarity matching features. It would be clearer to state that it defaults to true and explain what happens when it's set to false.

Suggested change
- exact_match_only (boolean): Fixed as true (default behavior)
- exact_match_only (boolean): If `false`, enables fuzzy matching. If `true`, only exact matching is used (default: `true`).

- replace_all (boolean): If true, replace all occurrences; if false, only first match (default: false)

Example Usage:
Single line replacement:
'{"operation":{"type":"search_replace","file_path":"main.py","search":"x = 1","replace":"x = 2"}}'

Multi-line replacement with context:
'{"operation":{"type":"search_replace","file_path":"app.py","search":"def foo():\\n return 1","replace":"def foo():\\n return 2"}}'

Parameters: type (string, required) Must be "search_replace"; file_path (string, required) Relative path from source_dir; search (string, required) One or more complete lines when modifying existing file, or empty string for full file replacement / creating new file; replace (string, required) Replacement block or full file content; exact_match_only (boolean, optional) Fixed as true; replace_all (boolean, optional) When true, replace all occurrences of search in file; when false, only first match (default: false).
Full file replacement or new file creation:
'{"operation":{"type":"search_replace","file_path":"config.py","search":"","replace":"# Configuration\\nDEBUG = True\\nPORT = 8000"}}'

Full file replacement: Use search="" and put full content in replace - works for both creating new files and replacing entire existing file content.
Replace all occurrences:
'{"operation":{"type":"search_replace","file_path":"utils.py","search":"old_name","replace":"new_name","replace_all":true}}'

Best Practices: When modifying existing file, use multi-line blocks with structural context (def/class) for accuracy. Use replace_all=true when the same block appears multiple times. For full file replacement, use search="" and put full content in replace."""
Best Practices:
- For existing file modifications: Include multi-line blocks with structural context (def/class/import) for accuracy
- For full file replacement: Use search="" and put entire content in replace field
- For renaming variables/functions: Use replace_all=true to replace all occurrences
- Ensure proper JSON escaping: use \\n for newlines, \\" for quotes within strings
- Match indentation and whitespace exactly as they appear in the source file"""
),
"source_dir": ParamInfo(
name="source_dir",
Expand Down
Loading