Node Details

  • Name: WriteFile

  • Type: Tool

  • Version: 1.0

  • Category: Tools

  • Description: Write file to disk

Parameters

The node accepts one optional input parameter:

  • Base Path

    • Label: Base Path

    • Name: basePath

    • Type: string

    • Optional: true

    • Placeholder: C:\Users\User\Desktop

    • Description: The base directory path for file operations. If not provided, a default path will be used.

Functionality

This node creates a WriteFileTool instance, which is a structured tool for writing files. It uses a NodeFileStore to handle the actual file operations.

Input/Output

  • Input:

    • file_path: A string representing the name or path of the file to be written.

    • text: A string containing the content to be written to the file.

  • Output:

    • A success message: “File written to successfully.”

Usage

The WriteFile node is used when you need to save text content to a file as part of a workflow or process. It can be useful for:

  • Saving generated content

  • Logging information

  • Creating or updating configuration files

  • Exporting data from other nodes or processes

Implementation Details

  • The node uses Zod for input validation.

  • It extends the StructuredTool class from LangChain.

  • File operations are abstracted through a BaseFileStore class, with the actual implementation using NodeFileStore.

  • The tool supports custom base paths, allowing flexibility in where files are written.

Notes

  • Ensure that the process has the necessary permissions to write to the specified locations.

  • Be cautious when using this tool, as it can overwrite existing files.

  • The actual file path used will be a combination of the optional base path and the provided file_path in the tool’s input.