Code | Solutions

What is AI Agent

An AI agent is an intelligent entity that perceives its environment and takes actions to achieve specific goals. Unlike a simple program, an agent can reason, learn from experience, and adapt its behavior. When multiple agents work together, they can solve complex problems that are beyond the capabilities of a single agent.

Crew AI

CrewAI is an open-source Python framework designed for orchestrating and managing collaborative teams of autonomous AI agents. Instead of relying on a single agent to handle a complex task, CrewAI allows developers to create a “crew” where each agent is assigned a specific role, goal, and set of tools. This role-based architecture mimics human teams, enabling agents to delegate tasks, communicate with each other, and work together in a sequential or hierarchical manner to achieve a common objective. By providing a structured and organized environment, CrewAI simplifies the development of multi-agent systems, making it a powerful tool for automating complex workflows, from content creation to market research and beyond.

    We can start by import the library

    from dotenv import load_dotenv
    from crewai import Agent, Process, Task, Crew, LLM
    load_dotenv()

    Now we are good to go, we can now define our LLM, for this project we are using Gemini

    llm = LLM(
       model="gemini/gemini-2.0-flash",
       temperature=0.7
    )

    you can use any LLM like OpenAi, Azure, IBM, you can check all the list of available LLM in the docs

    Now we will define our Agents

    First Agent: Content Planner

    planner = Agent(
            role="Content Planner",
            goal="Plan engaging and factually accurate content on {topic}",
            backstory="You're working on planning a blog article about the topic: {topic}. You collect information that helps the audience learn something and make informed decisions. Your work is the basis for the Content Writer to write an article on this topic.",
            allow_delegation=False,
            verbose=True,
            llm=llm
        )

    2nd Agent: Content Writer

    writer = Agent(
            role="Content Writer",
            goal="Write insightful and factually accurate opinion piece about the topic: {topic}",
            backstory="You're working on a writing a new opinion piece about the topic: {topic}. You base your writing on the work of the Content Planner, who provides an outline and relevant context about the topic. You follow the main objectives and direction of the outline, as provide by the Content Planner. You also provide objective and impartial insights and back them up with information provide by the Content Planner. You acknowledge in your opinion piece when your statements are opinions as opposed to objective statements.",
            allow_delegation=False,
            verbose=True,
            llm=llm
        )

    3rd Agent: Editor

    editor = Agent(
            role="Editor",
            goal="Edit a given blog post to align with the writing style of the organization.",
            backstory="You are an editor who receives a blog post from the Content Writer. Your goal is to review the blog post to ensure that it follows journalistic best practices, provides balanced viewpoints when providing opinions or assertions, and also avoids major controversial topics or opinions when possible.",
            allow_delegation=False,
            verbose=True,
            llm=llm
        )

    now we defined our agents, next step is to assign task to each agent.

    plan = Task(
            description=(
                "1. Prioritize the latest trends, key players, and noteworthy news on {topic}.\n"
                "2. Identify the target audience, considering their interests and pain points.\n"
                "3. Develop a detailed content outline including an introduction, key points, and a call to action.\n"
                "4. Include SEO keywords and relevant data or sources."
            ),
            expected_output="A comprehensive content plan document with an outline, audience analysis, SEO keywords, and resources.",
            agent=planner,
        )
    
        write = Task(
            description=(
                "1. Use the content plan to craft a compelling blog post on {topic}.\n"
                "2. Incorporate SEO keywords naturally.\n"
                "3. Sections/Subtitles are properly named in an engaging manner.\n"
                "4. Ensure the post is structured with an engaging introduction, insightful body, and a summarizing conclusion.\n"
                "5. Proofread for grammatical errors and alignment with the brand's voice.\n"
            ),
            expected_output="A well-written blog post in markdown format, ready for publication, each section should have 2 or 3 paragraphs.",
            agent=writer,
        )
    
        edit = Task(
            description=("Proofread the given blog post for grammatical errors and alignment with the brand's voice."),
            expected_output="A well-written blog post in markdown format, ready for publication, each section should have 2 or 3 paragraphs.",
            agent=editor
        )

    Now we setup Agents & Tasks, next we need to run the crew and saw the magic

    crew = Crew(
            agents=[planner, writer, editor],
            tasks=[plan, write, edit],
            process=Process.sequential,
            verbose=True
        )
    result = crew.kickoff(inputs={"topic": "Artificial Intelligence"})
    print(result)

    Thats it, you did it.

    Here is some screenshot of output

    multi agent using crew ai, starting progress
    multi agent using crew ai, 2nd agent
    multi agent using crew ai end result

    Recent News