CrewAI Workflow for Prompts
2025-07-105 turns7,471 charsresearch
Summary
User wants to build a CrewAI workflow that processes markdown files and generates multiple unique Stable Diffusion prompts in readable JSON format for each article.
Messages
I want to use https://docs.crewai.com/en/introduction to run an agent workflow that will take a folder of .md files and generate a list of prompts which can be given to stable diffusion which will generate the pictures for the blog posts in the folder with the .md files --- write a guide which has the prompts I can give to CLIne in order to take a basic installation of crewai and build this workflow
To write the most accurate guide for using CrewAI to process a folder of .md blog files into prompts for Stable Diffusion image generation, could you clarify a few things:
1. What kind of images are you hoping Stable Diffusion will generate (e.g., illustrations, photorealistic, diagrams)?
2. Do you already have a prompt format in mind for Stable Diffusion (e.g., including mood, medium, style)?
3. Should the workflow generate one image per .md file, or multiple images per file?
4. Do you want the prompts to be embedded in the .md files or output to a separate file (e.g., JSON, CSV)?
5. Are there specific sections in the .md files (like titles or headers) that should be used to generate the prompts?
Once I have that, I’ll provide CLIne-compatible instructions and code to set up the agents and tasks in CrewAI.
research
1. illustrations, 2. no I want it to create that as well, 3. I want it to generate at least 4 pictures for each article with each prompt for stable diffusion being different 4. I want the stable diffusion prompts to be outputted in JSON but readable 5. the prompts should be based on the content of each file
Great. I’ll prepare a guide for using CrewAI to process a folder of markdown (.md) blog posts, extract content, and generate four unique Stable Diffusion illustration prompts per post. The workflow will create readable JSON output with these prompts.
I’ll include step-by-step instructions for setting up the CrewAI agents, defining their tasks, and running the full workflow via CLIne.
research
# Guide to Creating a CrewAI Workflow for Stable Diffusion Prompts
This guide shows how to use CrewAI’s CLI assistant (Cline) to build a workflow that scans a folder of Markdown files and generates multiple Stable Diffusion prompts per article. In summary, we will create a CrewAI project, define an agent that reads all `.md` files (using the **DirectoryReadTool** from CrewAI’s toolkit【11†L150-L159】), then for each file parse its content and produce *at least four* distinct image-generation prompts. These prompts will be output in structured JSON. We use CrewAI’s CLI commands and interactive chat (AI assistant) to build and run this crew.
**1. Install and initialize CrewAI.**
Ensure CrewAI is installed. For example, run:
```
pip install crewai
```
【18†L160-L168】. Then create a new CrewAI project (replace `blog_image_prompter` with your desired name):
```
crewai create crew blog_image_prompter
```
This sets up a new Crew project directory【18†L190-L199】.
**2. Define the Crew and Agents.**
Within the project, add an agent whose role is to process Markdown content. Give this agent the **DirectoryReadTool** so it can list files in a folder. For example (in code or YAML), your agent might include:
```python
from crewai_tools import DirectoryReadTool
agent = Agent(
role="Markdown Analyzer",
goal="Read articles and generate image prompts",
tools=[DirectoryReadTool()],
allow_delegation=False,
llm="gpt-4o"
)
```
This lets the agent read directory contents. (CrewAI’s file tools allow reading and listing files【11†L150-L159】.) In your tasks configuration, create a task that uses this agent to **list all `.md` files** in the target directory.
**3. Process each file (kickoff for each item).**
Use CrewAI’s **kickoff_for_each** feature to loop over the list of files【19†L154-L163】. For example, when kicking off the crew, pass the list of Markdown file paths as inputs (one input per article). The CLI assistant can help here. In a `crewai chat` session you might say:
> *“I have a list of Markdown files in `articles/`. Please run the crew once for each file. Use the directory-read agent to get the file paths, then feed each file’s content into the next task.”*
The assistant will guide you through setting up a loop (kickoff_for_each) so that the workflow runs on each file. This ensures every article is processed separately【19†L154-L163】.
**4. Generate Stable Diffusion prompts.**
Next, define a task that takes one file’s text and produces four distinct image prompts. In the task description, specify clearly that the output should be *four unique prompts based on the article’s content*. For example, you might write:
```
description: |
Read the article text and write 4 different creative image prompts
(for Stable Diffusion) that illustrate key themes of the article.
expected_output: "A JSON list of 4 text prompts for image generation."
```
CrewAI can output structured JSON if you set the `output_json` property with a Pydantic model【32†L865-L873】【32†L898-L907】. For instance, define a model like `class Prompts(BaseModel): prompts: List[str]`, and set `output_json=Prompts`. This ensures the agent’s answers come out as valid JSON. The agent (using its language model) will then generate four prompts (as bullet points or separate lines). Emphasize each prompt must be different.
If desired, you can also integrate CrewAI’s image tools (e.g. DALL·E) to actually generate images from the prompts【27†L189-L197】. But if you only need the prompts, simply collecting them as text is sufficient.
**5. Example CLI prompts to Cline.**
When you run `crewai chat`, the AI assistant will ask questions about the crew setup. You can guide it with prompts like:
- *“I want to create a crew named `BlogImageCrew`. It should read all Markdown files in a given directory.”*
- *“Add an agent with role ‘Markdown Reader’ using `DirectoryReadTool` to list files.”*
- *“Then add a task so that for each file, the agent reads its text and generates 4 distinct image prompts based on that content.”*
- *“Ensure the output is formatted as JSON (for example, a list of prompts).”*
The assistant will help translate these instructions into tasks and code. For example, it may set up a sequential process where one task lists files and then a second task processes each file. It will likely ask you to confirm task descriptions and outputs (using `output_json` and possibly an output file)【32†L865-L873】【18†L400-L408】.
**6. Run and view results.**
After the assistant configures the crew, execute it with:
```
crewai run
```
【18†L377-L386】. The crew will process all files, generating prompts. You can use `crewai log-tasks-outputs` to view the results or write them to an output JSON file via task settings. Each file’s result will be a JSON object containing the four prompts.
By following these steps and interacting with the `crewai chat` assistant using the prompts above, you’ll build a workflow that reads all your blog posts and produces multiple Stable Diffusion prompts per article – all in neatly structured JSON. This leverages CrewAI’s multi-agent workflow (agent+tools) and its JSON output features【11†L150-L159】【32†L865-L873】.
**Sources:** CrewAI documentation on using the CLI (`crewai create`, `crewai chat`, etc.)【18†L160-L168】【18†L377-L386】, tools overview (DirectoryReadTool, image tools)【11†L150-L159】【27†L189-L197】, kickoff_for_each usage【19†L154-L163】, and structured JSON output (`output_json`)【32†L865-L873】【32†L898-L907】.