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
13 changes: 11 additions & 2 deletions src/strands_tools/file_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
"type": "string",
"description": "The content to write to the file",
},
"mode": {
"type": "string",
"description": "Write mode: 'w' (default) to overwrite, 'a' to append to existing content",
"enum": ["w", "a"],
"default": "w",
},
},
"required": ["path", "content"],
}
Expand Down Expand Up @@ -168,6 +174,7 @@ def file_write(tool: ToolUse, **kwargs: Any) -> ToolResult:
- path: The path to the file to write. User paths with tilde (~)
are automatically expanded.
- content: The content to write to the file.
- mode: Write mode - 'w' (default) to overwrite, 'a' to append.
**kwargs: Additional keyword arguments (not used currently)

Returns:
Expand Down Expand Up @@ -257,10 +264,12 @@ def file_write(tool: ToolUse, **kwargs: Any) -> ToolResult:
)

# Write the file
with open(path, "w") as file:
mode = tool.get("input", {}).get("mode", "w")
with open(path, mode) as file:
file.write(content)

success_message = f"File written successfully to {path}"
action = "appended to" if mode == "a" else "written successfully to"
success_message = f"Content {action} {path}"
success_panel = Panel(
Text(success_message, style="bold green"),
title="[bold green]Write Successful",
Expand Down
Loading