MemoryWrite

Description

The Memory Write node saves incoming text data into a local JSON file (the "memory") under a specific key. It is the counterpart to the Memory Read node, enabling persistent data storage that survives workflow restarts and application sessions.

It is a side-effect node: its primary purpose is to write to disk. It is essential for caching AI-generated content, saving intermediate results, or passing data between completely different workflows that do not share the same canvas.


Configuration Properties

📁 Filepath Section

TextBox
The path to the JSON memory file. By default, it points to Workbench\memory.json in the same directory as the TzuFlow executable (e.g., if TzuFlow.exe is in C:\TzuFlow\, the default path is C:\TzuFlow\Workbench\memory.json).

Browse...
Opens a standard Windows file dialog to select a different memory file. You can use any .json file.

💡 Tip: The Workbench folder is a convention used by TzuFlow to centralize working files, but you can store memory files anywhere on your disk.


🔑 Key word Section

TextBox
The key (identifier) under which the data will be saved. The memory file is a simple JSON dictionary where each key maps to a text value.
Example: If you save a summary under the key "ArticleSummary", you can later retrieve it with a Memory Read node using that exact same key.

⚠️ Warning: If a key already exists in the memory file, saving with the same key will overwrite the previous value. Use unique keys or include timestamps/dates in the key name if you need to preserve history.


📤 Output Mode Section

Pass Through Input Text
When checked, the node sends the original input text to its output unchanged. This is useful when you want to save the data to memory but also continue processing it in the same workflow (e.g., save a draft, then immediately send it to a translation Agent).
When unchecked, the node sends a confirmation message downstream (e.g., "Memory saved: [KeyWord]") instead of the original text.


Usage Example

"Cache an AI summary for later use":

  1. An Agent node generates a summary of a long document.
  2. A Memory Write node with:
    • Filepath: Workbench\memory.json
    • Key word: DailySummary
    • Pass Through: unchecked
  3. Later, in a completely different workflow, a Memory Read node with Key word: DailySummary retrieves the text to send it via email.

"Save and translate in one pass":

  1. An Input node receives a text.
  2. A Memory Write node saves it under the key "OriginalText" with Pass Through checked.
  3. An Agent node receives the text (via the pass-through) and translates it.
  4. A second Memory Write node saves the translation under the key "TranslatedText".

⚠️ Pitfalls to Avoid

Overwriting keys: The memory file is a simple key-value store. If you run a workflow twice with the same Key word, the second run will overwrite the first. If you need to keep multiple versions, generate dynamic keys (e.g., using a TemplateNode to append a date: "Summary_20231024").

Empty Key Word: If the Key word field is empty, the node will not save anything (or may throw an error depending on the implementation). Always ensure a valid key is provided.

File format: The memory file is a JSON dictionary managed by TzuFlow's MemoryStorage module. Do not edit the memory.json file manually with a text editor while TzuFlow is running, as this can cause read/write conflicts or corrupt the JSON structure.

Large data: The entire memory file is loaded into memory on every read/write operation. If you store massive amounts of text (e.g., full books) under many keys, the file will grow large and operations will slow down. For heavy data storage, consider using File Write nodes to create individual files instead.

Concurrency: While MemoryStorage uses internal locking to prevent corruption, rapid successive writes to the same file from multiple parallel workflows can cause slight delays. For high-frequency logging, use a dedicated log file via File Write (Append Mode) instead of the memory JSON.