Call/text: +1 (604) 337-7899
AI Agency projects

Introduction

In this article, we will explore the practicalities of creating a team of Agents and their workflow in the context of AI Agency projects. We will focus on the combination of CrewAI, an open-source AI assistants framework, and Gemini Pro, the AI model developed by Google. This combination allows us to create a specialized team of agents that can collaborate on complex tasks, such as crafting short stories with the help of user input. Whether you’re a programmer, a storyteller, or simply curious about the potential of artificial intelligence, this guide is for you.

What are CrewAI and Gemini Pro?

Before we dive into building our AI storyteller, let’s understand what CrewAI and Gemini Pro are.

CrewAI

CrewAI is a powerful framework designed to orchestrate multiple AI agents, each with its own unique skills and responsibilities, to collaborate on complex tasks. It enables us to create a team of specialized agents, such as screenwriters, critics, and story masters, to work together on writing stories.

Gemini Pro

Gemini Pro is a state-of-the-art language model developed by Google. It is known for its ability to understand and generate human-like text, making it an ideal candidate for creative tasks like storytelling.

The Importance of this Structure

The combination of CrewAI and Gemini Pro offers several benefits in the context of AI Agency projects. Let’s explore some of them:

Specialization

Each agent in the team can focus on what they do best, whether it’s crafting dialogue, ensuring consistency, or overseeing the project. This specialization allows for high-quality output in each aspect of the story creation process.

Collaboration

Agents can work together, combining their strengths and expertise to produce a story that is greater than the sum of its parts. The collaborative nature of the team ensures that different perspectives and skills are utilized to create a compelling narrative.

Flexibility

The setup of CrewAI and Gemini Pro is highly adaptable. It allows for different story elements to be emphasized or altered based on user input or creative direction. This flexibility ensures that the generated stories meet specific requirements or preferences.

Setting up the Environment

To create a team of agents using CrewAI and Gemini Pro, we need to set up the environment. Here’s how you can do it:

  1. Install Python: If you don’t already have Python installed on your machine, you can follow a tutorial or video guide to install Python. Make sure you have Python version 3.x.

  2. Install Required Libraries: Open your command line or terminal and use the following commands to install the necessary libraries:

    • pip install crewai
    • pip install langchain-google-genai
  3. Copy the Code: Copy the code provided below into your Python environment. This code will initialize the necessary modules and establish the connection to the Gemini Pro API.

“`python
import os
from langchain_google_genai import ChatGoogleGenerativeAI
from crewai import Agent, Task, Crew, Process

if name == “main“:
# Load the Google Gemini API key
google_api_key = os.getenv(“GOOGLE_API_KEY”)

# Set Gemini Pro as the language model
llm = ChatGoogleGenerativeAI(
    model="gemini-pro",
    verbose=True,
    temperature=0.9,
    google_api_key=google_api_key
)

“`

  1. Set up the Gemini Pro API Key: To use the Gemini Pro model, you need an API key. You can create this key in Google AI Studio for free. Once you have the API key, replace the placeholder YOUR_OWN_KEY in the code above with your actual API key.

  2. Define the Agents: Next, we need to define our agents. In this example, we will create a Screenwriter, a Critic, and a Story Master. Each agent has a specific role, goal, and backstory that guide their contributions to the story generation process. Here’s an example:

“`python
screenwriter = Agent(
role=”Screenwriter”,
goal=”Translate ideas into engaging scenes with vivid descriptions, snappy dialogue, and emotional depth.”,
backstory=”””Former freelance screenwriter for low-budget indie films. Learned to work quickly under constraints, generating multiple variations on a theme. Excels at building tension and incorporating plot twists.”””,
verbose=True,
allow_delegation=False,
llm=llm,
)

critic = Agent(
role=”Analytical Eye & Genre Enforcer”,
goal=”Ensure stories are internally consistent, adhere to the intended genre, and maintain stylistic choices.”,
backstory=”””A retired film studies professor with an encyclopedic knowledge of classic tropes, storytelling structures, and audience expectations. Has a knack for spotting potential plot holes and continuity errors.”””,
verbose=True,
allow_delegation=False,
llm=llm,
)

story_master = Agent(
role=”Project Lead & Master Orchestrator”,
goal=”Guide the overall story generation process, manage the workflow between the Screenwriter and Critic, and ensure a cohesive final product.”,
backstory=”””A seasoned novelist turned game narrative designer. Has a strong understanding of both high-level plot frameworks and the detailed scene creation required to immerse a reader in the world.”””,
verbose=True,
allow_delegation=True,
llm=llm,
)
“`

  1. Get User Input: Prompt the user to provide a short story idea. This input will be used to create a task that outlines what the story should include. Here’s an example:

python
user_input = input("Please provide a short story idea. You can specify the genre and theme: ")

  1. Create the Task: Use the user input to create a task that specifies the story requirements. The task will be assigned to the Story Master agent. Here’s an example:

python
story_task = Task(
description=f"Write a short story with the following user input: {user_input}",
agent=story_master,
)

  1. Create the Crew and Run the Task: Finally, create a crew by combining the agents and tasks. Specify the execution flow as sequential. Then, run the task to generate the story. Here’s an example:

“`python
story_crew = Crew(
agents=[screenwriter, critic, story_master],
tasks=[story_task],
verbose=True,
process=Process.sequential,
)

story_output = story_crew.kickoff()
“`

That’s it! You now have a team of AI agents collaborating to create an engaging short story based on user input. This example demonstrates the basic workflow of CrewAI and Gemini Pro. Keep in mind that the CrewAI framework offers more advanced features and capabilities, such as hierarchical processing and tool usage. You can explore these features in the official CrewAI documentation.

Conclusion

In this article, we explored the practicalities of creating a team of agents using CrewAI and Gemini Pro for AI Agency projects. We learned how to set up the environment, define specialized agents, and run tasks to generate stories. By leveraging the power of CrewAI and the language generation capabilities of Gemini Pro, we can create highly specialized and collaborative teams that produce high-quality outputs. Whether you’re a programmer, a storyteller, or simply interested in AI applications, this framework offers exciting possibilities. So go ahead, unleash your creativity, and create your own AI agency projects!

Leave a Reply

Your email address will not be published. Required fields are marked *

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from - Youtube
Vimeo
Consent to display content from - Vimeo
Google Maps
Consent to display content from - Google
Spotify
Consent to display content from - Spotify
Sound Cloud
Consent to display content from - Sound