Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

fix: ensure output directory exists before writing in flow template (#5291)

Lorenze Jaybce10f597808
diff --git a/lib/crewai/src/crewai/cli/templates/flow/main.py b/lib/crewai/src/crewai/cli/templates/flow/main.py
index 29f21033f..836eb65ca 100644
--- a/lib/crewai/src/crewai/cli/templates/flow/main.py
+++ b/lib/crewai/src/crewai/cli/templates/flow/main.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python
+from pathlib import Path
+
from pydantic import BaseModel
from crewai.flow import Flow, listen, start
@@ -42,7 +44,9 @@ class ContentFlow(Flow[ContentState]):
@listen(generate_content)
def save_content(self):
print("Saving content")
- with open("output/post.md", "w") as f:
+ output_dir = Path("output")
+ output_dir.mkdir(exist_ok=True)
+ with open(output_dir / "post.md", "w") as f:
f.write(self.state.final_post)
print("Post saved to output/post.md")