CrewAI and n8n: The new era of automation in Marketing

The dynamic automation duo that is revolutionizing Digital Marketing

Walter Gandarella • October 30, 2024

If you work in digital marketing, you've probably found yourself thinking, "Wow, there's gotta be a smarter way to do this!" while performing those repetitive tasks that take up a good part of your day. Well, I have good news for you: there is! And better yet, I'm going to introduce you to not just one, but two powerful tools that are changing the game: CrewAI and n8n.

The current scenario of Digital Marketing

Before we dive into the tools themselves, let’s provide a little context. Today's digital marketing is like that plate of spaghetti your grandmother makes on Sunday: it has many different ingredients that need to be mixed together in the right proportions to produce a spectacular result. We have data analysis, campaign automation, content personalization, integration with multiple platforms... and so on.

And to make everything even more “interesting”, the market moves at the speed of light. As you read this article, some social network has probably already changed its algorithm or a new trend has emerged that will become popular in the coming weeks. It is in this dynamic scenario that our two protagonists enter the scene.

At Yes Marketing, we have been closely following this technological evolution. We are already implementing some solutions using CrewAI to meet specific demands, both ours and those of some clients. And although we have not yet implemented n8n, we are in an intense process of studying and evaluating the tool, seeking to understand how it can fit perfectly into our arsenal of solutions.

CrewAI: The conductor of the AI orchestra

Imagine you could have a team of super-intelligent virtual assistants, each specialized in a different task, working in harmony to achieve your marketing goals. This is basically the concept behind CrewAI.

CrewAI is like that dream project manager who can get everyone working together without any drama. Except instead of people, we're talking about AI agents. And the coolest thing? You can customize them according to your specific needs.

For example, you might have one agent who specializes in analyzing social media data, another focused on SEO optimization, and a third dedicated to generating content ideas. Everyone working together, sharing information and complementing each other. It's like having a turbocharged version of the Avengers, but for digital marketing!

The tool stands out especially for its flexibility with different language models (LLMs). You’re not locked into a single AI provider – you can use different models for different tasks, depending on what works best for each case.

n8n: The master of integrations

Now, imagine if you could connect all the tools you use in your daily life as simply as putting together a puzzle. This is n8n.

n8n is that friend who knows everyone and can make the right introductions. With over 400 ready-to-use integrations, it lets you connect virtually any service or application you use in your marketing efforts.

The difference with n8n is its intuitive visual interface. You don't need to be a coding ninja to create complex automations. It's all done through a drag-and-drop interface, where each action is represented by a "node" that you can connect with other nodes to create your workflows.

Want a practical example? You can create a flow that monitors mentions of your brand on social media, analyzes the sentiment of comments, categorizes them by relevance and urgency, and automatically triggers specific actions for each case - from sending a notification to the support team to updating monitoring dashboards.

Magic happens when they work together

What if I told you that you can combine the powers of these two tools? This is where things get really interesting!

Imagine using CrewAI to create a team of AI agents specialized in different aspects of your marketing, and using n8n to connect these agents with all your existing tools and platforms. It's like giving your superpowers superpowers!

For example, you can have a CrewAI agent analyzing campaign performance data and generating insights, while n8n automatically feeds this data with information from different sources and distributes the generated insights to the right teams, in the right channels, at the right time.

Practical cases that will make you daydream

Personalization at scale

Imagine being able to create truly personalized campaigns for thousands of customers, where every interaction is tailored based on customer history, preferences, and behavior. CrewAI can analyze data and generate personalized recommendations, while n8n takes care of implementing these recommendations through different communication channels.

Continuous campaign optimization

CrewAI agents can constantly monitor the performance of their campaigns, identify patterns, and make adjustments in real time. n8n, in turn, can automatically implement these optimizations and keep all platforms in sync.

Intelligent content generation and distribution

Use CrewAI to analyze trends, generate content ideas, and even create first drafts. n8n can then handle the entire flow of approval, publishing and distribution across the different channels.


Building your AI team with CrewAI: A practical guide

At the beginning of this article I mentioned that Yes Marketing is already using CrewAI Agents internally for some flows and is experimenting with them on some specific flows for some clients. Now I'm going to show you how to build your own team of AIs to generate content for LinkedIn (or anything else you can imagine).

Preparing the environment

First, let's install the necessary tools. You will need Python installed on your machine. Then, open your favorite terminal and install CrewAI:

pip install crewai crewai-tools

Setting API Keys

CrewAI uses OpenAI's GPT-4 to do the magic, and also Serper for web searches. You will need API keys for both:

  1. Create an OpenAI account and get your key at platform.openai.com
  2. Do the same on Serper at serper.dev

Now create a new Python file (it can be in VSCode or your preferred editor) and add the initial settings:

import the
from crewai import Agent, Task, Crew
from crewai_tools import SerperDevTool, ScrapeWebsiteTool

# Setting environment variables for APIs
os.environ['OPENAI_API_KEY'] = 'your_openai_key_here'
os.environ['SERPER_API_KEY'] = 'your_serper_key_here'
os.environ['OPENAI_MODEL_NAME'] = 'gpt-4'

# Initializing the tools that agents will use
search_tool = SerperDevTool() # To search on Google
scrap_tool = ScrapeWebsiteTool() # To extract content from found websites

Building your team

Here comes the fun part: we're going to create three agents, each with their own specialty. Think of them as highly efficient employees who never need coffee:

searcher = Agent(
    role='Content Searcher', # Defines the role of the agent
    goal='Search online for content about {topic}', # Main goal
    backstory='You are working on creating articles for LinkedIn about {topic}. '
             'You will research information on the internet and collate it for the Writer.', # Context and motivation
    tools=[search_tool, scrap_tool], # Tools he can use
    verbose=True # Show process details
)

writer = Agent(
    role='Content Writer',
    goal='Write a text for LinkedIn about {topic}',
    backstory='You will use the Search Engine data to create interesting and factual text. '
             'You can give opinions, but make it clear that they are personal.',
    tools=[search_tool, scrap_tool],
    verbose=True
)

editor = Agent(
    role='Content Editor',
    goal='Edit the text to a more informal tone',
    backstory='You will take the Writer's text and adjust it to have a lighter, more personal tone.',
    tools=[search_tool, scrap_tool],
    verbose=True
)

Each agent has a specific role. The role is like his position, the goal is the main objective, and the backstory is like a detailed briefing of what he needs to do. tools are the tools he can use to do his job.

The possible configurations you can make to an Agent can be found in the official CrewAI Agent Documentation

Define the tasks

Every agent needs to know exactly what to do. Let's create your tasks:

fetch = Task(
    description="Search for trends and relevant news about {topic}." # Detailed instructions
               "Identify target audience and important keywords.",
    agent=searcher, # Which agent will perform this task
    expected_output='A plan with trends, keywords and news about {topic}.'    # What must be delivered
)

write = Task(
    description="Create a compelling LinkedIn post using the data you collect."
               "Use keywords naturally and make a thoughtful conclusion.",
    agent=writer,
    expected_output='A LinkedIn text about {topic}.'
)

edit = Task(
    description="Review the text, correct errors and adjust it to a more personal and informal tone.",
    agent=publisher,
    expected_output='Final text ready for publication.'
)

Each task has a description which is like a manual of what needs to be done, an agent responsible for its execution, and an expected_output which clearly defines what should be delivered at the end.

Here you can also consult the CrewAi Task Documentation to learn all the configuration possibilities.

Time to put the team to work

Now let's put them all together and get started:

# Creating the team with all agents and their respective tasks
team = Crew(
    agents=[searcher, writer, editor], # List of available agents
    tasks=[search, compose, edit], # List of tasks to be performed
    verbose=True # Show the process in detail
)

# Set the theme and start working
theme = "Artificial Intelligence in Medicine"
result = team.kickoff(inputs={"theme": theme}) # inputs are the variables we use with {theme}
print(result)

The Crew is the one who coordinates everyone. You know which agents are available and what sequence of tasks needs to be performed. kickoff() is like giving the green light for the team to start working.

For more details, see the CrewAI Crew Documentation

And that's it! Your AI team will work in harmony: the search engine will research the content, the writer will transform it into a nice text, and the editor will give it that final touch to make it all yours.

Our result

The coolest thing about CrewAI is its flexibility - you can use this same framework to create Instagram posts, analyze stocks, plan trips... just adapt the agents and tasks to your goal.

The Future is Now (And It's Cooler Than We Imagined)

The combination of CrewAI and n8n represents more than just an evolution in marketing tools - it is a true revolution in the way we think about and execute digital strategies. It's like having a team of super geniuses working 24/7 to make your brand shine.

And best of all? We are just beginning to scratch the surface of what is possible with these tools. As AI continues to evolve and more integrations are added, the possibilities become virtually endless.

So, if you’re thinking about giving your digital marketing a boost, seriously consider including this dynamic duo in your arsenal of tools. After all, while your competitors are still trying to do everything manually, you could be building a digital empire with the help of your new automated assistants.

Remember: in the world of digital marketing, it's not just about working hard, it's about working smart. And with CrewAI and n8n by your side, you will have all the (artificial) intelligence you need to stand out in this increasingly competitive market.


Latest related articles