[BUG] crewai flow plot saves HTML to a hidden temp directory instead of the current working directory (despite CLI message)
Description
When running the crewai flow plot command (or calling .plot() programmatically without catching the return path), the framework generates the HTML visualization inside a hidden system temporary directory (e.g., /var/folders/.../T/crewai_flow_.../), instead of the user's current working directory.
Furthermore, the CLI outputs a misleading success message: Flow visualization saved to guide_creator_flow.html, leading the user to believe the file was saved locally in their project folder when it was not.
Steps to Reproduce
- Create a basic CrewAI Flow.
- Run crewai flow plot in the terminal.
- Observe the output: Flow visualization saved to guide_creator_flow.html.
- Run ls in the current directory. The .html file is nowhere to be found.
Expected behavior
The .plot() method and the crewai flow plot CLI command should either:
Save the HTML file directly into the current working directory. Print the actual absolute path to the temporary directory where it was saved so the user can locate it.
Screenshots/Code snippets
-
Run the command $ crewai flow plot Plotting the Flow Flow visualization saved to guide_creator_flow.html
-
Check the directory immediately after $ ls -l guide_creator_flow.html ls: guide_creator_flow.html: No such file or directory
-
Prove where it actually went using a Python script $ python -c "from src.guide_creator_flow.main import GuideCreatorFlow; print('Actual path:', GuideCreatorFlow().plot('guide_creator_flow.html'))" Actual path: /var/folders/ct/dgmxjsz54hx42xb88jzb5h1m0000gn/T/crewai_flow_1dw9hg68/guide_creator_flow.html
Operating System
macOS Sonoma
Python Version
3.11
crewAI Version
crewai, version 1.11.0
crewAI Tools Version
crewai-tools 1.11.0
Virtual Environment
Venv
Evidence
- Running the CLI command tells the user it saved in the current directory:
$ crewai flow plot
Plotting the Flow
Flow visualization saved to guide_creator_flow.html
2. However, checking the directory immediately after shows the file is missing:
bash
$ ls -l guide_creator_flow.html
ls: guide_creator_flow.html: No such file or directory
### Possible Solution
There are a couple of ways the maintainers could address this:
1. Fix the Save Location (Preferred): Update the plot() method in crewai/flow/flow.py. After generating the Pyvis HTML in the system's temporary directory, the framework should forcefully copy that .html artifact into the user's current working directory (os.getcwd()) so it's accessible.
2. Fix the CLI Output: If the file must remain in the temporary directory because of dependencies/assets, then update the CLI print statement in crewai.cli.flow to stop lying to the user. Instead of printing "Flow visualization saved to [filename]", it should print the actual absolute path returned by the method: "Flow visualization saved to /var/folders/.../T/crewai_flow/.../filename.html".
### Additional context
1. Operating System: macOS (applicable strictly given the /var/folders/ path, though likely affects Linux/Windows temp dirs as well).
2. Context: This completely breaks CI/CD pipelines or headless servers trying to generate the HTML diagram as an artifact, because users are currently forced to write their own wrapper script using shutil to extract the file from the hidden temp directory to the workspace.
Fixes #4991
Problem
When running crewai flow plot, the framework generates the HTML visualization inside a hidden system temporary directory instead of the user's current working directory.
The CLI outputs a misleading message: Flow visualization saved to guide_creator_flow.html, leading users to believe the file was saved locally when it was not.
Solution
Modified render_interactive() in crewai/flow/visualization/renderers/interactive.py to save files in the current working directory instead of creating a temporary directory.
Changes
- Changed
tempfile.mkdtemp()toPath.cwd()for output directory - Updated docstring to reflect the new behavior
- Removed unused
tempfileimport
Testing
The existing test test_visualization_plot_method() passes with this change. Files are now correctly saved where users expect them.
Submitted PR #5018 to fix this: https://github.com/crewAIInc/crewAI/pull/5018
This changes the flow visualization to save files in the current working directory instead of a hidden temp directory. Please review when you have time. Thanks!
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.