Agentic AI: Part 1

image

Welcome to the first article in our exciting new series, “Agentic AI” In this series, we will delve deep into the world of multi-agent systems, showcasing how these innovative technologies are transforming the way we approach automation, workflow management, and AI integration.

What to Expect

In this series, we will delve into different aspects of Agentic AI. We will begin by taking a close look at CrewAI, an advanced framework created for developing and overseeing multi-agent systems. Each article will offer a thorough understanding of the tools, techniques, and applications that establish Agentic AI as a game-changer in the field of intelligent collaboration.

Why Agentic AI?

Agentic AI involves the utilization of several autonomous agents collaborating to accomplish complex objectives. Unlike conventional AI systems that function on their own, Agentic AI harnesses the combined expertise of different specialized agents to address diverse tasks more efficiently. This method not only boosts productivity but also enables increased adaptability and creativity in addressing real-world challenges.

Series Outline
  1. CrewAI

    • Introduction to CrewAI and its core components.

    • Setting up your environment and creating agents.

    • Practical examples of agent collaboration in real-world scenarios.

  2. Custom Tool Development for CrewAI

    • How to create custom tools to extend the capabilities of your agents.

    • A step-by-step guide to integrating a Google Drive upload tool.

    • Enhancing agent functionality with specialized tools.

  3. Building User Interfaces for Agentic AI

    • Integrating CrewAI with user interfaces using Streamlit and Panel.

    • Creating interactive and user-friendly applications.

  4. Exploring Microsoft’s AutoGen Framework

    • Introduction to Microsoft’s AutoGen framework.

    • Setting up and integrating AutoGen with multi-agent systems.

  5. Diving into Meta’s LLaMA Agentic System

    • Overview of Meta’s LLaMA Agentic System.

    • Practical applications and integration techniques.

  6. Advanced Features and Applications of Agentic AI

    • Exploring advanced features like memory, delegation, and error handling.

    • Case studies of Agentic AI in various industries.

    • Future trends and potential of multi-agent systems.

  7. The Future of Intelligent Collaboration

    • Insights into the evolving landscape of Agentic AI.

    • Predictions and trends for the next decade.

    • How to stay ahead in the rapidly advancing field of AI.

CrewAI

CrewAI is an innovative framework designed to create and manage multi-agent systems. It enables efficient collaboration among AI agents to accomplish various tasks. This platform is useful for automating workflows, enhancing productivity, and integrating advanced AI capabilities into projects.

image

Key Components of CrewAI

CrewAI consists of several core components that work together to facilitate the operation of AI agents:

Agents: Agents are the individual members of a crew, each with specific roles and skills, such as ‘Researcher’, ‘Writer’, or ‘Customer Support’. These roles help distribute tasks effectively across the team.

Tasks: Tasks are assignments that agents need to complete. Each task includes a description, the assigned agent, and any tools required for execution, allowing for flexible and complex workflows.

Tools: Tools in CrewAI are functions or skills that agents can use to perform actions. These can include web searches, data analysis, and other utilities that enhance agent capabilities. The framework supports both built-in tools and custom tools developed by users.

Processes: Processes manage how tasks are executed by agents, similar to project management in human teams. They ensure that tasks are distributed and completed efficiently according to a predefined strategy.

Crew: A crew is a collaborative group of agents working together to achieve a set of tasks. The crew defines the overall strategy for task execution and agent collaboration.

image

Getting Started with CrewAI
To begin using CrewAI, you need to set up your environment. This involves installing the CrewAI library and any necessary tool packages. The installation can be done via pip:

pip install crewai
pip install 'crewai[tools]'

After installation, you can create agents and assign them specific roles and tasks. Here’s a detailed example of how to set up agents and tasks, including setting up environment variables and using advanced features:

Example of Setting Up Agents and Tasks
import os

# Set environment variables for API keys and endpoints

os.environ["OPENAI_API_TYPE"] = "azure"

os.environ["OPENAI_API_VERSION"] = "2024-02-15-preview"

os.environ["OPENAI_API_KEY"] = ""

os.environ["AZURE_OPENAI_ENDPOINT"] = ""

os.environ["SERPER_API_KEY"] = ""

# Import necessary libraries

from crewai import Agent, Task, Crew, Process

from langchain_openai import AzureChatOpenAI

from crewai_tools import SerperDevTool

# Setup development and research tools

search_tool = SerperDevTool()
azure_llm = AzureChatOpenAI(
azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"),
api_key=os.environ.get("OPENAI_API_KEY"),
model="gpt-4o",
)

# Define a Senior Researcher Agent

researcher = Agent(
role='Senior Researcher',
goal='Uncover insights about {topic},
verbose=True,
backstory=(
"Driven by curiosity, you|'re at the forefront of"
"innovation, eager to explore and share knowledge that could change "
"the world. Your expertise helps demystify complex tech topics."
),
tools=[search_tool],
allow_delegation=True,
llm=azure_llm
)

# Define a Writer Agent

writer = Agent(
role='Writer',
goal='Craft engaging blog posts about {topic},
verbose=True,
backstory=(
"Armed with a knack for explaining intricate concepts, you create "
"enticing narratives that educate and engage readers, making new "
"tech accessible to all."
),
tools=[search_tool],
allow_delegation=False,
llm=azure_llm
)

# Define tasks

research_task = Task(
description=(
"Explore and report on the latest developments in {topic}."
"Identify benefits, drawbacks, and market potentials."
),
expected_output='A detailed report with three key sections on emerging trends in {topic}.',
tools=[search_tool],
agent=researcher,
)

write_task = Task(
description=(
"Write an insightful blog post on {topic}, highlighting recent trends and their impacts. "
"Ensure the content is understandable, engaging, and informative."
),
expected_output='A four-paragraph blog post on {topic}, formatted in markdown.',
tools=[search_tool],
agent=writer,
output_file='blog-post.md'
)

# Assemble the crew

tech_crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential,
cache=True,
max_rpm=100,
share_crew=True
)

# Execute the tasks

result = tech_crew.kickoff(inputs={'topic': 'AI in cybersecurity'})
print(result)

Core Concepts of CrewAI Processes

CrewAI’s process management system is designed to facilitate teamwork among agents, allowing them to operate as a cohesive unit. The key features of this system include:

  • Task Execution: Processes manage how tasks are executed, ensuring that goals are met effectively.
  • Team Coordination: Agents work together systematically, enhancing overall productivity and coherence.

Types of Processes

CrewAI implements several types of processes, each tailored for different task management needs:

  • Sequential Process: Tasks are executed in a predefined order. This method ensures that each task is completed before moving on to the next, allowing for a systematic approach to task management.
  • Hierarchical Process: This approach simulates a corporate hierarchy, where a designated manager agent oversees task execution. The manager allocates tasks based on agent capabilities, reviews outputs, and validates results, ensuring efficient delegation and management.
  • Consensual Process (Planned): A future implementation aimed at promoting collaborative decision-making among agents. This process is not yet available but is in development.
Implementing Processes

To implement a process in CrewAI, developers must specify the desired process type when creating a crew. Here are examples of how to create crews with different processes:

Sequential Process Example
from crewai import Crew

from crewai.process import Process

# Define agents and tasks

my_agents = [...] # List of agents

my_tasks = [...] # List of tasks

# Create a crew with a sequential process

crew = Crew(agents=my_agents, tasks=my_tasks, process=Process.sequential)
Hierarchical Process Example: Without a Manager Agent

Here’s how to define a Hierarchical Process without a manager agent, using CrewAI and Langchain’s ChatOpenAI to manage a team of AI agents with defined roles and goals

from langchain_openai import ChatOpenAI

from crewai import Crew, Process, Agent

# Agents are defined with attributes for backstory, cache, and verbose mode

researcher = Agent(
role='Researcher',
goal='Conduct in-depth analysis',
backstory='Experienced data analyst with a knack for uncovering hidden trends.',
cache=True,
verbose=False,
# tools=[] # This can be optionally specified; defaults to an empty list
)

writer = Agent(
role='Writer',
goal='Create engaging content',
backstory='Creative writer passionate about storytelling in technical domains.',
cache=True,
verbose=False,
# tools=[] # Optionally specify tools; defaults to an empty list
)

# Establishing the crew with a hierarchical process and additional configurations

project_crew = Crew(
tasks=[...], # Tasks to be delegated and executed under the manager's supervision
agents=[researcher, writer],
manager_llm=ChatOpenAI(temperature=0, model="gpt-4"), # Mandatory if manager_agent is not set
process=Process.hierarchical, # Specifies the hierarchical management approach
memory=True, # Enable memory usage for enhanced task execution
manager_agent=None, # Optional: explicitly set a specific agent as manager instead of the manager_llm
)

Source: https://docs.crewai.com/how-to/Hierarchical/#implementing-the-hierarchical-process
In this example:

  • The Researcher agent conducts in-depth analysis, and the Writer agent creates engaging content.
  • A hierarchical process is used to manage the agents and tasks, with ChatOpenAI as the manager, ensuring efficient task delegation and execution.
  • Memory is enabled for enhanced task performance.

Hierarchical Process Example: Without a Manager Agent

Here’s how you can define a research and writing crew with a custom project manager using CrewAI:

import os

from crewai import Agent, Task, Crew, Process

# Define your agents

researcher = Agent(
role="Researcher",
goal="Conduct thorough research and analysis on AI and AI agents",
backstory="You're an expert researcher, specialized in technology, software engineering, AI, and startups. You work as a freelancer and are currently researching for a new client.",
allow_delegation=False,
)

writer = Agent(
role="Senior Writer",
goal="Create compelling content about AI and AI agents",
backstory="You're a senior writer, specialized in technology, software engineering, AI, and startups. You work as a freelancer and are currently writing content for a new client.",
allow_delegation=False,
)

# Define your task

task = Task(
description="Generate a list of 5 interesting ideas for an article, then write one captivating paragraph for each idea that showcases the potential of a full article on this topic. Return the list of ideas with their paragraphs and your notes.",
expected_output="5 bullet points, each with a paragraph and accompanying notes.",
)

# Define the manager agent

manager = Agent(
role="Project Manager",
goal="Efficiently manage the crew and ensure high-quality task completion",
backstory="You're an experienced project manager, skilled in overseeing complex projects and guiding teams to success. Your role is to coordinate the efforts of the crew members, ensuring that each task is completed on time and to the highest standard.",
allow_delegation=True,
)

# Instantiate your crew with a custom manager

crew = Crew(
agents=[researcher, writer],
tasks=[task],
manager_agent=manager,
process=Process.hierarchical,
)

# Start the crew's work

result = crew.kickoff()

Source: https://docs.crewai.com/how-to/Your-Own-Manager-Agent/
In this example:

  • Researcher and Writer agents are defined with specific roles and goals, each specialized in AI and technology content.
  • A Task is created to generate article ideas and write paragraphs for each.
  • A Manager Agent is introduced to oversee and ensure the completion of tasks to high standards.
  • The Crew is instantiated with the agents, tasks, and manager, set to follow a hierarchical process.
  • Finally, the crew’s work is started, and the result is printed.
Key Features of Processes
  • Task Delegation: In the hierarchical process, a manager agent assigns tasks based on the strengths and roles of each agent.
  • Result Validation: The manager evaluates the outcomes of tasks to ensure they meet established standards.
  • Asynchronous Execution: Tasks can be executed concurrently, enhancing the efficiency of the crew.
  • Human Input Review: An optional feature allows human oversight of task outputs before finalization, ensuring quality control.
  • Output Customization: Tasks can generate outputs in various formats, such as JSON or Pydantic models, providing flexibility in data handling.

Conclusion

In the first part of our "Agentic AI" series, we've established the foundation for understanding the potential of multi-agent systems. Starting with CrewAI, we've delved into the fundamental concepts, key components, and practical applications that make Agentic AI a groundbreaking approach to intelligent collaboration. In upcoming installments, we'll further explore custom tool development, and user interface integration, and delve into advanced frameworks such as Microsoft's AutoGen and Meta's LLaMA Agentic System.

Stay tuned for our next article where we will explore creating custom tools for CrewAI, enhancing your agents'capabilities, and advancing your multi-agent systems to the next level.

If you found this introduction to Agentic AI insightful and are eager to learn more, make sure to subscribe to our series. By subscribing, you’ll receive the latest updates and insights directly in your inbox, helping you stay ahead in the ever-evolving field of AI.

Subscribe now and join us on this exciting journey into the world of Agentic AI!

If you’re interested in building such systems, want personalized guidance, aim to automate some processes, or wish to explore how AI can elevate your business, please book a call with us on Calendly. We would be thrilled to help you bring your multi-agent system projects to life.

Comments:

Leave a Reply

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