From d11a5dfb1372707522c0fc33eb4f93ab34a19835 Mon Sep 17 00:00:00 2001 From: theCyberTech Date: Sun, 28 Jun 2026 13:26:33 +0800 Subject: [PATCH] docs(file-writer): show tool attached to an agent, not called directly Tools are meant to be handed to an Agent via tools=[...] and invoked by the agent during a task. The previous example called the tool's method directly, which is not how users should use CrewAI tools. Replace with a full agent+task+crew example mirroring the pattern used by sibling tool pages (e.g. seleniumscrapingtool). --- .../en/tools/file-document/filewritetool.mdx | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/docs/edge/en/tools/file-document/filewritetool.mdx b/docs/edge/en/tools/file-document/filewritetool.mdx index 7032f7072..e37f0d55a 100644 --- a/docs/edge/en/tools/file-document/filewritetool.mdx +++ b/docs/edge/en/tools/file-document/filewritetool.mdx @@ -29,23 +29,41 @@ pip install 'crewai[tools]' ## Example -To get started with the `FileWriterTool`: +The `FileWriterTool` is attached to an agent and invoked by that agent during a task — you don't call it yourself. Initialize the tool, hand it to an `Agent` via `tools=[...]`, and let the crew run. ```python Code +from crewai import Agent, Crew, Task, Process from crewai_tools import FileWriterTool # Initialize the tool file_writer_tool = FileWriterTool() -# Write content to a file in a specified directory -result = file_writer_tool.run( - filename='example.txt', - content='This is a test content.', - directory='test_directory', +# Define an agent that can write files +report_writer = Agent( + role="Report Writer", + goal="Produce written reports and save them to disk", + backstory="A meticulous writer who files every report as a .md file.", + tools=[file_writer_tool], ) -print(result) + +# Task that asks the agent to write a file +write_task = Task( + description="Write a short markdown report summarizing the Q3 results to a file named q3_report.md inside the reports directory.", + expected_output="Confirmation that q3_report.md was written to the reports directory.", + agent=report_writer, +) + +crew = Crew( + agents=[report_writer], + tasks=[write_task], + process=Process.sequential, +) +result = crew.kickoff() +print(result.raw) ``` +When the agent decides to write a file, it calls the tool with `filename`, `content`, and optionally `directory` and `overwrite` (see Arguments). + ## Arguments - `filename`: The name of the file you want to create or overwrite.