kdeps-tools-write_file
v2.0.0Write or overwrite a text file on the local filesystem. Creates a new file if it does not exist; overwrites existing files entirely. Use for creating or updating configuration files, source code, scripts, or any text-based file. Takes an absolute path.
set tools / shelf tools
LLM context: ~168 tokens when loaded (prompt or tool definition)
Where it runs
Part of the tools set, used in workflow and agent mode. What the model is told about each built-in tool: its description, usage notes and parameters. kdeps runs the tool itself.
- the agent loop builds the request
- the tool definitions are sent to the modeltools/write_file
- the model calls a tool
- kdeps runs it
- the result goes back to the model
Loaded by: kdeps (agent loop), /update, /settings, kdeps run, kdeps install, kdeps list, kdeps uninstall, kdeps update
In the code: kdeps (agent loop)agent.RegisterBuiltinToolsagent.definedAs
Install
A kdeps asset: installed with the first-run profile that includes its set, or the first time a command needs it, and updated without a new release.
Pin a version with kdeps install tools/write_file@<version>.
Contents
Write or overwrite a text file on the local filesystem. Creates a new file if it does not exist; overwrites existing files entirely. Use for creating or updating configuration files, source code, scripts, or any text-based file. Takes an absolute path.
- category
- file
- outputFormat
- confirmation message with bytes written
- seeAlso
- edit_file, read_file
| Parameter | Type | Description |
|---|---|---|
| content * | string | Text content to write to the file |
| file_path * | string | Absolute path to the file to write |
Python script (declared in YAML, no Go code)
import json, os, sys
a = json.loads(sys.argv[1])
path = (a.get("file_path") or "").strip()
if not path:
sys.exit("write_file: file_path is required")
path = os.path.abspath(path)
data = (a.get("content") or "").encode("utf-8")
# max_bytes comes from the file-read-limit event in an agent session.
cap = int(a.get("max_bytes") or 0) or 1048576
if len(data) > cap:
sys.exit("write_file: content is %d bytes (max %d)" % (len(data), cap))
if os.path.isdir(path):
sys.exit("write_file: %s is a directory" % path)
err = None
for _ in range(2): # written, read back, and written once more on a mismatch
try:
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | getattr(os, "O_BINARY", 0), 0o600)
with os.fdopen(fd, "wb") as f:
f.write(data)
with open(path, "rb") as f:
got = f.read()
except OSError as e:
err = "write_file: %s: %s" % (path, e.strerror or e)
continue
if got == data:
print("Wrote %d bytes to %s" % (len(data), path))
sys.exit(0)
err = "write_file: verify %s: wrote %d bytes but read back %d bytes" % (path, len(data), len(got))
sys.exit(err)
Paths kept in the workspace: file_path
aliases:
- write
- create_file
- save_file
- write_to_file
constraints: overwrites entire file — use edit_file for targeted changes;
relative paths resolve against the working directory; the parent directory
must exist
version: 2.0.0
category: file
aliases: [write, create_file, save_file, write_to_file] # other names a model may call it by; the model is shown only this tool's name
description: Write or overwrite a text file on the local filesystem. Creates a new file if it does not exist; overwrites existing files entirely. Use for creating or updating configuration files, source code, scripts, or any text-based file. Takes an absolute path.
constraints: overwrites entire file — use edit_file for targeted changes; relative paths resolve against the working directory; the parent directory must exist
outputFormat: confirmation message with bytes written
seeAlso: edit_file, read_file
parameters:
content:
type: string
description: Text content to write to the file
required: true
file_path:
type: string
description: Absolute path to the file to write
required: true
python:
paths: [file_path] # checked against the workspace boundary
script: |
import json, os, sys
a = json.loads(sys.argv[1])
path = (a.get("file_path") or "").strip()
if not path:
sys.exit("write_file: file_path is required")
path = os.path.abspath(path)
data = (a.get("content") or "").encode("utf-8")
# max_bytes comes from the file-read-limit event in an agent session.
cap = int(a.get("max_bytes") or 0) or 1048576
if len(data) > cap:
sys.exit("write_file: content is %d bytes (max %d)" % (len(data), cap))
if os.path.isdir(path):
sys.exit("write_file: %s is a directory" % path)
err = None
for _ in range(2): # written, read back, and written once more on a mismatch
try:
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | getattr(os, "O_BINARY", 0), 0o600)
with os.fdopen(fd, "wb") as f:
f.write(data)
with open(path, "rb") as f:
got = f.read()
except OSError as e:
err = "write_file: %s: %s" % (path, e.strerror or e)
continue
if got == data:
print("Wrote %d bytes to %s" % (len(data), path))
sys.exit(0)
err = "write_file: verify %s: wrote %d bytes but read back %d bytes" % (path, len(data), len(got))
sys.exit(err)
Versions
| Version | Published | Status |
|---|---|---|
| 2.0.0 | 10/24/2026 | active |
| 1.1.0 | 10/17/2026 | active |
| 1.0.0 | 10/11/2026 | active |
Details
- Author
- kdeps
- License
- Apache-2.0
- Latest Version
- 2.0.0
- Published
- 10/11/2026