“A Team” A Crew of AI Agents

How would you like to hire a team of AI agents to work together on a single task? Is it even possible?

I’ve been playing with this new framework for coworking agents as I learn Python. It’s really cool to see how this all works. You can use any LLM you want, whether running one locally or having an OpenAI account. I’ll only cover the basics here, as you can find more in-depth information over at Crewai’s documentation site.

The concept is simple, like assembling a team at any organization. Each team member has a role to play, and some of the roles depend on the output of the other team members to do their job. Let’s consider a real-world example: a team responsible for content publishing. This is something I can relate to. ;)

Here are the roles or personas we will need for the Agents.

  1. Researcher - Finds relevant content to write about (takes input from team lead (or human. More on this later) and outputs a summary of findings.

  2. Writer - Writes a content article based on the researcher's summary.

  3. Editor - Reviews the articles the writer produces and ensures consistency, format, voice, and theme. He has the ability to return the article to the writer for revision. Once approved, the final output is sent to the terminal as an article for publishing.

Now, this is fictitious, but you get the idea. You could add in a creative director and a photographer or digital media specialist who will source relevant images or generate them for you.

researcher = Agent(
    role="Content Researcher",
    goal="Find and explore the most exciting and relevant content and consumer trends to ensure that content is relevant and appealing, focusing on content published in 2024",
    backstory="""You are an expert strategist who knows how to spot emerging trends and companies. You know how 
    to discern between actual projects and companies and factious pages used for advertising. You're great at finding interesting, exciting content on the web. 
    You source scraped data to create detailed summaries containing names of the most exciting projects, products, trends and companies on the web. 
    ONLY use scraped text from the web for your summary report.""",
    verbose=True,
    allow_delegation=False,
    tools=[search_tool]+human_tools,
)

writer = Agent(
    role="Senior Writer",
    goal="Write an engaging and interesting blog post using the researchers summary report in simple, layman's vocabulary",
    backstory="""You create engaging content for blogs. You will create highly informative, relevant, valuable, and engaging blog posts on various topics. 
    You will be expected to write five or more paragraph articles, proofread your articles before submitting the drafts, and revise articles after receiving feedback from the editor. 
    The articles must be unique 100% factually correct, easy to read, and SEO friendly. You only use data that was provided to you from the researcher for the blog and site your sources.""",
    verbose=True,
    allow_delegation=True,
    tools=human_tools,
)

editor = Agent(
    role="Expert Writing Critic and Editor",
    goal="Provide feedback and criticize blog post drafts. Make sure that the tone and writing style is compelling, simple and concise",
    backstory="""You are an Expert at providing feedback to the writers. You can tell when a blog text isn't concise,
    simple, or engaging enough. You know how to provide helpful feedback that can improve any text. You know how to ensure that text 
    stays relevant and insightful by using layman's terms.""",
    verbose=True,
    allow_delegation=True,
)

Tasks

Now we have our “Agents,” and I’ve already given you an idea of their roles. Now, they need tasks, so let’s define them next.

  1. Research the web for ideas relating to the theme provided by the team lead and return a summary report containing ideas to write about based on your findings.

  2. Write an article about the one idea the team lead chose from the research report.

  3. Proofread the article for consistency and relevancy to the research and ensure it fits the format, voice, and theme the team lead stated when he delegated the task.

task_report = Task(
    description="""Use and summarize scraped data from the internet to make a detailed report on the latest content based on the theme provided by the human. Use ONLY 
    scraped data from the web to generate the report. Your final answer MUST be a full analysis report, text only; ignore any code or anything that 
    isn't text. The report has to have bullet points and 5-10 defining the scraped content. Write the names of every tool and project. 
    Each bullet point MUST contain 4 sentences that refer to one specific company, product, model, or anything you found online related to the theme provided by the human. 
    Include text from the scraped data in the report as quoted.""",
    agent=researcher,
)

task_blog = Task(
    description="""Write a blog article with text only and with a short but impactful headline and at least 10 paragraphs. The blog should summarize 
    the content the human has chosen from the researcher's report. The content in the blog post should be factual from the report. Style and tone should be compelling, 
    concise, fun, and technical, but also use layman's terms for the general public. Name specific new, exciting projects, apps, and companies in the report. Don't 
    write "**Paragraph [number of the paragraph]:**"; instead, start the new paragraph in a new line. Write the names of projects and tools in BOLD.
    ALWAYS include links to projects/tools/research papers. ONLY include information from the report.""",
    agent=writer,
)

task_critique = Task(
    description="""The Output MUST be concise, simple, and engaging. Provide helpful feedback that can improve the writing. Ensure that the text 
    stays relevant and insightful by using layman's terms.
    Make sure that it does; if it doesn't, have the writer rewrite it accordingly.
    """,
    agent=editor,
)

Notice the use of the word human. This is to inform the agent that they need to use a tool, much like the terms search the web or search online, cueing the agent that it needs to use a tool. In this case, the tool happens to be a Human… You are the human tool that tells the agents what to do. The agent will ask himself before performing each task, “Do I need to use a tool?” If it finds that it can't move forward with the task, it will use a tool if it fits the job; otherwise, it will either attempt to complete the task with no input or let you know that it can’t complete the task.

Tools

Sometimes, agents need tools to perform their tasks. Here are some tools we can provide them to use.

  1. Web Searching

  2. Web Scraping

  3. Consult with Human (Team Lead)

search = GoogleSerperAPIWrapper()

search_tool = Tool(
    name="Scrape google searches",
    func=search.run,
    description="useful for when you need to search the internet",
)

# Loading Human Tools
human_tools = load_tools(["human"])

This is just one tool; there are many free tools in the langchain library to use, as well as various APIs like this Google SERPER wrapper API here. For this article, I’ll stick to these two examples to simplify the post.

The last thing we need to do is get this crew working.

# instantiate crew of agents
crew = Crew(
    agents=[researcher, writer, editor],
    tasks=[task_report, task_blog, task_critique],
    verbose=2,
    process=Process.sequential,  # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
)

# Get your crew to work!
result = crew.kickoff()

print("######################")
print(result)

This is the basics of what needs to happen and how to set up a “Crew.” But before I leave you to try this yourself, I want to mention the comment in the code around the “process” key where we set the process to sequential. Here are the process types available as of this writing from the CrewAI documentation.

Process Implementations

  • Sequential: Executes tasks one after another, ensuring a linear and orderly progression.

  • Hierarchical: Implements a chain of command where tasks are delegated and executed based on a managerial structure.

  • Consensual (WIP): Future process type aiming for collaborative decision-making among agents on task execution.

As you can see, the processes available are really simple, and there is no real workflow available yet. However, I will be exploring other libraries that have workflows built in, so look out for my next post on this subject. But for now, you can find more details in the CrewAI documentation.

You can also check out my source code for this project on my GitHub repo.

Previous
Previous

Game Development with HTML5

Next
Next

Getting started with Ollama