Introduction to AI Agents with Crew AI
1. Introduction & Context
1.1. Overview
Objective:
Introduce AI Agents: Understand what AI agents are—autonomous
systems that can execute multi-step tasks and make decisions based on
their environment.
Demonstrate Building Agents: Learn how to build these agents using the
Crew AI framework.
Highlight Transition from LLMs: Explain how traditional large language
models (LLMs) produce single-turn responses, while AI agents are
designed for continuous, autonomous interaction.
Importance:
Automation and Efficiency: By building AI agents, developers can
automate complex workflows, reducing manual intervention.
Enhanced Decision-Making: Agents can process multiple steps and
incorporate external data, leading to smarter outcomes.
Industry Relevance: Skills in building autonomous agents are
increasingly in demand across sectors such as banking, education, and
transcription.
1.2. Prerequisites
Prior Knowledge:
Basic AI Concepts: Familiarity with general AI concepts, including what
LLMs are (e.g., ChatGPT, Co-pilot).
Python Programming: Ability to write and understand Python code,
including installing packages and managing environment variables.
Understanding of APIs: Basic knowledge of how API keys work and their
role in authenticating requests.
Additional Helpful Concepts:
Orchestration: Basic idea of managing multiple processes (or
“agents”) to work together.
Modular Programming: Familiarity with defining functions and
modules in Python.
2. Main Content
2.1 Session Overview
Session Goals:
Define AI Agents: Explain what they are and how they differ from LLMs.
Build an Agent: Demonstrate a live demo showing the construction of a
news research agent.
Interactivity and Autonomy: Emphasize the agent’s capability to
autonomously process multi-step tasks.
Demo Preview: A short 20-second video demo illustrates a working
example:
The agent takes a query (e.g., "What is AI?").
It autonomously gathers, summarizes, and analyzes news reports
related to the query.
Outcome: By session end, attendees should understand how to build a
basic autonomous news research agent using the Crew AI framework.
2.2. Fundamental Concepts of AI Agents
2.2.1. Understanding AI Agents vs. LLMs
Large Language Models (LLMs):
Function: Generate responses based solely on given text inputs.
Limitation: They produce one-shot responses; if further actions are
needed, additional prompts are required.
Example: Asking ChatGPT, "What is AI?" returns a text answer. To get
more details or follow-up actions, multiple queries are necessary.
AI Agents:
Definition: Autonomous software entities that not only generate
responses but also decide subsequent actions based on initial output.
Key Distinction:
Multi-Step Processing: Can autonomously perform tasks in
sequence (e.g., research, summarization, analysis).
Autonomy: Agents can "understand" the overall goal and interact
with their environment without constant human prompting.
Example Scenario – Weather and Commute:
LLM Approach: Ask about weather, then separately inquire about
dress code and commute time.
Agent Approach: An agent takes an image of the weather,
determines that it’s raining, infers increased traffic, and advises
leaving earlier while suggesting suitable attire (e.g., "carry an
umbrella").
2.2.2. Key Components of an AI Agent
Components:
LLM Selection: Decide which large language model to use (e.g., Gemini
Pro, ChatGPT).
Example: Choose Gemini Pro for its balance of performance and
accuracy.
API Key Management: Securely store your API keys (in an .env file) to
authenticate requests without exposing sensitive information.
Parameter Settings:
max_tokens: Limits the length of responses to control verbosity.
temperature: Adjusts creativity—lower values yield more
deterministic responses, while higher values introduce
randomness.
Practical Example: Setting up a basic agent might involve:
import os
from crewai import Agent, Crew
# Load API key securely
API_KEY = os.getenv("LLM_API_KEY")
# Define agent parameters
agent_config = {
"model": "GeminiPro",
"max_tokens": 150,
"temperature": 0.5,
"verbose": True
}
2.3. Building AI Agents with Crew AI
2.3.1. Introduction to Crew AI Framework
Definition:
Crew AI is an orchestration framework that facilitates the creation,
management, and coordination of multiple AI agents.
Role:
It acts as a "project manager" for agents, ensuring that each agent's
output is processed sequentially and effectively.
Benefits:
Simplification: Reduces complexity in managing multi-step workflows.
Automation: Allows agents to work collaboratively without continuous
human intervention.
Efficiency: Streamlines the process of building advanced AI systems.
2.3.2. Defining and Configuring Agents
Agent Attributes:
Role: E.g., Research Analyst, Content Summarizer, News Analyst.
Example: The Research Analyst might be tasked with gathering
news articles about AI.
Goal: Define what each agent is meant to achieve.
Example: The News Analyst could be aimed at identifying key
trends from the gathered articles.
Backstory: Provide context or expertise level; this helps in tuning the
agent's behavior.
Verbose Setting: Enables detailed output for debugging and
understanding the agent's decision-making.
Agent Initialization Example:
research_agent = Agent(role="Research Analyst",
goal="Gather latest AI news",
backstory="Expert in tech news",verbose=True)
summarizer_agent = Agent(role="Content Summarizer",
goal="Condense news articles",
backstory="Skilled in summarization", verbose=True)
analyst_agent = Agent(role="News Analyst",
goal="Identify trends and implications",
backstory="Experienced in data analysis", verbose=True)
2.3.3. Defining Tasks and Workflow Orchestration
Task Assignment:
Research Task: The Research Agent is assigned to collect relevant data
from news sources.
Summary Task: The Summarizer Agent condenses the information into
key points.
Analysis Task: The Analyst Agent examines the summarized data to
identify patterns and implications.
Orchestration with Crew AI:
Crew Object Creation: Instantiate the Crew object with the list of agents
and their tasks.
crew =
Crew(agents=[research_agent, summarizer_agent, analyst_agent],
tasks=["research", "summarise", "analyse"])
crew.kickoff_task("What are the latest news on AI?")
Sequential Execution: The framework ensures that each agent
performs its role in the correct order, allowing for autonomous multi-
step processing.
2.4. Enhancing Agent Capabilities with Tools and User Interfaces
2.4.1. Integration of External Tools
Purpose:
Enhance agent performance by incorporating external data and
functionalities.
Tools:
Surfer Dev Tool: Enables the agent to perform web searches to gather
the most relevant information.
Example: The Research Agent uses this tool to fetch the latest
news articles.
Website Scraper Tool: Extracts detailed content from websites
identified by the Surfer Dev Tool.
Benefit: Provides a richer dataset for further analysis.
Demonstration:
Configure these tools with the necessary API keys:
from crewai_tools import SurferDevTool, WebsiteScraperTool
surfer_tool = SurferDevTool(api_key=os.getenv("SURFER_API_KEY"))
scraper_tool
= WebsiteScraperTool(api_key=os.getenv("SCRAPER_API_KEY"))
research_agent.add_tool(surfer_tool)
research_agent.add_tool(scraper_tool)
2.4.2. Building an Interactive User Interface with Streamlit
Overview of Streamlit:
Streamlit is a Python package that helps build interactive UIs for data
science applications quickly.
Key UI Components for AI Agents:
Title and Description: Provide a clear title (e.g., "AI News Research
Assistant") and descriptive markdown text.
Input Fields: For API keys, configuration settings (model, max_tokens,
temperature), and initial query input.
Submit Button: A "Research Now" button to trigger the agent workflow.
Progress Display: Real-time status updates showing which agent is
currently working and displaying results.
Example UI Code:
import streamlit as st
st.title("AI News Research Assistant")
st.markdown("This tool uses Crew AI to autonomously research, summarize,
and analyze the latest news on AI.")
api_key = st.text_input("Enter your API Key:", type="password")
initial_query = st.text_input("Enter your query:",
"What are the latest news on AI?")
if st.button("Research Now"):
# Code to initialize Crew AI and run tasks
st.write("Processing your request...")
# Assume results are obtained after execution
st.write("Results will be displayed here.")
Benefits:
Enhances user engagement.
Provides a professional interface for demonstrating agent capabilities.
2.5. Conclusion & Next Steps
2.5.1. Core Message
Summary:
The session provided an in-depth introduction to AI agents using Crew
AI, emphasizing their autonomous multi-step processing abilities. Key
components included defining agent roles, orchestrating tasks,
integrating external tools, and building interactive user interfaces with
Streamlit.
Takeaway:
AI agents are transformative tools that can automate complex tasks and
improve decision-making, significantly extending the capabilities of
traditional LLMs.
2.5.2. Next Steps & Further Exploration
Advanced Techniques:
Future sessions will cover refined agent interactions, further tool
integrations, and more sophisticated task management.
Further Reading:
Delve into Crew AI documentation.
Explore additional tutorials on integrating external APIs and building
advanced UIs.
Practical Application:
Experiment with building your own news research agent and test
different configurations and tools.
3. Key Insights & Takeaways
Autonomy and Multi-Step Processing: Unlike LLMs, AI agents can
autonomously perform multi-step tasks without constant human input.
Crew AI Framework: Simplifies the orchestration of multiple AI agents,
ensuring seamless task execution and collaboration.
Tool Integration: External tools like the Surfer Dev and Website Scraper
expand an agent’s capability to retrieve and process real-time data.
User Interface Importance: Streamlit is a valuable tool for creating
engaging, interactive interfaces that make AI applications accessible and
professional.
Real-World Impact: Building AI agents enables automated research,
content summarization, and data analysis—critical for modern business
and technology applications.
4. Additional Enhancements for Engagement
4.1. Comparison Table: LLMs vs. AI Agents
Aspect LLMs AI Agents
Single-turn Autonomous multi-step
Response
responses based processing and decision-
Mechanism
on input making
Requires repeated Operates independently after
Interactivity
human prompting initial setup
Capabilities Generates text Can integrate external tools
based on patterns and manage complex
Aspect LLMs AI Agents
workflows
Handling comprehensive
Answering simple
Use Case tasks like news research and
queries
analysis
4.2. Self-Check Q&A
Q: What key feature distinguishes AI agents from traditional LLMs?
Q: How does Crew AI streamline the process of building AI agents?
Q: What role does Streamlit play in building AI applications?
4.3. Practice Tips
Experiment: Build simple AI agents using the Crew AI framework and
test different configurations (adjusting max_tokens, temperature, etc.).
Integrate Tools: Enhance your agent by integrating external tools like
the Surfer Dev and Website Scraper.
UI Development: Develop a simple Streamlit UI to trigger and display
agent tasks, then iterate based on user feedback.
Iterative Testing: Regularly test and refine each component of your
agent to ensure smooth orchestration and accurate outputs.
5. Additional Resources & Links
Commands to install the package: pip install crewai crewai-tools
streamlit streamlit-lottie
Practice Files and Supplementary Material: Download Supplementary
Material 1
Download Supplementary Material 2