Saves text to a file on the computer. Agents use it to keep a record of what they produced: a report, a generated piece of code, or notes for the next stage.
Writes the supplied content to the file at the given path. Three modes are supported: 'overwrite' replaces any existing file; 'append' adds to the end of an existing file; 'create' fails if the file already exists. Parent directories are created automatically.
When a user asks:
Save the generated report to /reports/q4-2026.md.
the agent calls the tool:
file_write(path="/reports/q4-2026.md", content="…", mode="overwrite")and gets back: confirmation the file was written, with byte count.
Wire this tool into a SwarmAI crew. Use the YAML DSL for declarative workflows, or the Java builder API when you want full programmatic control.
YAML DSL
# archive.yaml
name: archive-crew
process: SEQUENTIAL
agents:
- id: archiver
role: Report Archiver
goal: Persist generated outputs to disk
tools:
- file_write
tasks:
- id: archive-task
agent: archiver
description: Save the generated report to /reports/q4-2026.md (overwrite if present).Java
import ai.intelliswarm.swarmai.agent.Agent;
import ai.intelliswarm.swarmai.task.Task;
import ai.intelliswarm.swarmai.swarm.Swarm;
import ai.intelliswarm.swarmai.swarm.SwarmOutput;
import ai.intelliswarm.swarmai.process.ProcessType;
import ai.intelliswarm.swarmai.tool.common.FileWriteTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
@Autowired ChatClient chatClient;
@Autowired FileWriteTool fileWriteTool;
Agent archiver = Agent.builder()
.role("Report Archiver")
.goal("Persist generated outputs to disk")
.chatClient(chatClient)
.tool(fileWriteTool)
.build();
Task archiverTask = Task.builder()
.description("Save the generated report to /reports/q4-2026.md (overwrite if present).")
.agent(archiver)
.build();
SwarmOutput result = Swarm.builder()
.agent(archiver)
.task(archiverTask)
.process(ProcessType.SEQUENTIAL)
.build()
.kickoff();Real scenarios where agents put this tool to work.
Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/common/FileWriteTool.java in the swarm-ai repository.