Develop Simple Agentic AI Workflow with CrewAI, Gemini, and Stable Diffusion
Learn the simple way to develop agents workflow
Agentic AI has become a popular framework to automate tasks and change how people work.
When we talk about Agentic AI, we refer to artificial intelligence designed to act autonomously and make decisions with minimum human intervention. It differs from a typical rule-based AI because the agent can understand the context and adapt to dynamic environments.
With the rise of multimodal AI and more muscular reasoning models, agentic AI become popular to improve productivity and potentially revolutionize industries. That’s why it’s beneficial to understand further about developing agents.
Agents might not be necessary for all the jobs out there, but it doesn't hurt to understand how to develop them. That’s why this article will explore how you can develop simple agents with the popular Agentic AI framework CrewAI and generative AI tools (LLM Gemini and text-to-image Stable Diffusion).
Let’s get into it.
Agentic AI Workflow
The code for this article is stored in the following repository. The tutorial is mostly done in VS Code IDE, but you can test it in the Jupyter Notebook.
The workflow of Agentic AI involves steps designed to perform autonomously and follow the previously established structure. Some frameworks allow the agent to think about its workflow, but we have already established most of them.
In this article, we will try to develop an agentic AI workflow that can produce personalized holiday stories via agents. Each agent will have their tasks and build on previous steps, making them sequential. The workflow will follow the procedure below.
As you can see, the workflow requires 5 different agents, which we designed as follows:
Develop Plot: Use the Plot Weaver agent to structure the story.
Drive Characters: Have the Character Driver agent flesh out the characters’ motivations and dialogues.
Paint Locale: Let the Locale Painter agent describe rich settings and festive atmospheres.
Construct Story: Merge all elements via the Story Constructor agent into a cohesive narrative.
Direct Cover Art: Employ the Cover Art Director agent to produce a final, story-consistent cover image.
The process will require a sequential approach, but the drive character and paint locale tasks will be executed simultaneously. The intended output will be the workflow where the agent can produce the story and cover image from the story.
In the repository above, we have the sample personalized story agent workflow using Streamlit, where you only need to run the following code to try:
streamlit run main.py
Having said that, we will learn how to set up everything for your Agentic AI workflow from the beginning.
Preparation
As a best practice, always initiate the Virtual Environment for your work, as we want environments to be isolated from one another. You can follow the code below to create them. Just change ‘myenv’ into your intended virtual environment name.
python -m venv myenv
Then, you can activate the virtual environment with the following code.
myenv\Scripts\activate
Then, we will install the required packages for the tutorial. If you use the repository above, you only need to install it from there. If not, you can install the following packages.
pip install crewai crewai-tools streamlit
Then, we will secure the API Key required for this tutorial. We will require both the Gemini API Key and the Stability AI API Key, which you can get on their respective platforms.
If you are using a Coding IDE such as Visual Studio Code, create a file called .env and put the following information in the file.
MODEL=gemini/gemini-1.5-flash
GEMINI_API_KEY=<GEMINI-API-KEY>
STABILITY_AI_API_KEY = <STABILITY-AI-API-KEY>
Replace all the keys with the API key you received from the Gemini and Stability AI platform.
Once everything is in place, we will start to develop our Agents.
Keep reading with a 7-day free trial
Subscribe to Non-Brand Data to keep reading this post and get 7 days of free access to the full post archives.