There is nothing to call: api.tools.writeDocument is a declaration. What performs it is the run, through the machine your process is on.
Declaring it
const agent = api.agents.create({
model: { main: session },
storages: [pc], // the computer it may write to
tools: {
list_documents: api.tools.listDocuments,
read_document: api.tools.readDocument,
write_document: api.tools.writeDocument,
},
});agent = api.agents.create(
model={"main": session},
storages=[pc], # the computer it may write to
tools={
"list_documents": api.tools.list_documents,
"read_document": api.tools.read_document,
"write_document": api.tools.write_document,
},
)What the model sends
{ "path": "Launch plan/brief.md", "content": "# Brief\n\nShip in March.", "mode": "create" }{"path": "Launch plan/brief.md", "content": "# Brief\n\nShip in March.", "mode": "create"}pathstringrequiredRelative to the workspace on that machine.
contentstringrequiredText. Not a Buffer, not an object.
modestringcreatecreate · update · append.
| mode | Does | On a file already there |
|---|---|---|
create | Writes a new file. | Refused — it says to use update or append. |
update | Replaces the content. | The old version is kept first. |
append | Adds to the end. | The old version is kept first. |
Nothing is overwritten without a copy
Before an update or an append, the current content is written to .versions/<path>/<timestamp>. Hidden folders stay out of a listing, so the copies do not clutter the workspace — and the answer carries backup, the path of the one just made.
// What the run reports back
{ path: "Launch plan/brief.md", mode: "update", bytes: 412,
backup: ".versions/Launch plan/brief.md/2026-10-07T09-12-44-000Z.md" }# What the run reports back
{"path": "Launch plan/brief.md", "mode": "update", "bytes": 412,
"backup": ".versions/Launch plan/brief.md/2026-10-07T09-12-44-000Z.md"}An agent follows text that may have come from a web page or a document. Giving it a write that cannot be undone would make one bad instruction final. Here the previous version is one read away, and you can hand it back.
Text files only
The type is read from the extension, and anything that is not text is refused: .md, .txt, .json, .csv, .html, .yaml, source files. An image or a PDF is not written this way — generated media is attached to the run instead.
A long document is written in passes
The description says so to the model: create the file, then extend it with append. A single enormous write competes with the answer for the turn's output budget; several passes do not.
The server cannot reach a disk. When the agent calls this, the run asks the machine that holds the key to perform it, the package does the work there, and the answer goes back into the run. So it only works while your process is listening — and nothing of the file ever travels to be written.
Refusals the run reports
- A missing
path, or one that is not a string. contentthat is not text.- A
modeoutside the three. createon a path already taken, naming the two modes that would work.- A path outside the workspace, or an absolute one.