Sudheer Talluri

Everything is figurable!


How to Build Autonomous Agents with CrewAI: A Step-by-Step Guide

Imagine having a team of AI agents collaborating like human colleagues to brainstorm, research, and execute tasks autonomously. Sounds futuristic? With CrewAI, it’s already here.

Introduction: The Power of CrewAI

CrewAI is a groundbreaking framework designed to orchestrate autonomous multi-agent systems, allowing developers to focus on logic while the platform handles the complexities of agent coordination. It facilitates workflows where agents can assign tasks to each other, work collaboratively, and achieve complex goals independently.

One of the most fascinating aspects of CrewAI is that its own documentation was created by autonomous AI agents using the platform. This exemplifies its capabilities, where agents aren’t just tools but effective collaborators.


What Makes a Good Agent in CrewAI?

A well-designed agent can define the success of a workflow. Here are the key characteristics of a good agent:

  1. Clear Role and Responsibility:
    • Every agent must have a defined role and a specific task. For example, an “Idea Scout” should focus solely on researching and generating innovative ideas.
  2. Specialized Tools:
    • Agents should be equipped with tools tailored to their tasks. For example:
      • A web scraping agent may use tools like SerperTool for structured web searches.
      • A contextual analyzer may rely on semantic processing tools.
  3. Context Awareness:
    • A good agent should adapt to the task’s requirements and adjust its behavior accordingly. For instance, the Context Analyzer in Think Tank Buddy enriches ideas with relevant competitor analysis.
  4. Effective Communication:
    • Agents must exchange outputs seamlessly to ensure workflows remain efficient. CrewAI enables agents to share their results, allowing downstream agents to process data without bottlenecks.
  5. Collaboration Capabilities:
    • Agents are designed to work together as part of a crew, complementing each other’s roles. This multi-agent orchestration makes it possible to execute end-to-end workflows autonomously.

By following these principles, CrewAI agents can perform tasks efficiently and deliver meaningful outputs.


Components of CrewAI

To fully utilize CrewAI, it’s important to understand its main components:

  1. Tasks: Tasks are the building blocks of any crew. They specify what needs to be done and the expected outputs.
    • Example: Researching a topic or analyzing its feasibility.
  2. Agents: Agents execute tasks. Each agent has:
    • A role: Defines its purpose.
    • A goal: Specifies the objective it must achieve.
    • Tools: External systems or libraries that enhance its capabilities.
  3. Crews: A crew orchestrates agents and tasks into a cohesive workflow. It determines:
    • Task order (sequential or parallel).
    • Agent assignments.
    • Collaboration mechanisms.
  4. Flows: Flows manage the lifecycle of crews. They define how tasks are triggered, how outputs are consumed, and how the overall workflow progresses.

What did I build using CrewAI.com?

I had this idea: What if I could build an AI companion that doesn’t just assist me, but thinks with me, researches with me, and generates actionable insights autonomously? Today, I made it a reality.

Introducing Think Tank Buddy—a fully autonomous application powered by CrewAI.com.


Think Tank Buddy is an AI-powered application I created using CrewAI to showcase the potential of autonomous multi-agent systems. It takes a simple topic as input and outputs actionable insights by orchestrating agents that can surf the web, evaluate data, and generate detailed reports. This guide will walk you through the code, the concepts of CrewAI, and how you can set it up locally.


Think Tank Buddy: High-Level Workflow

Here’s how Think Tank Buddy uses these CrewAI concepts:

  1. Input: A topic, such as “Artificial Intelligent Agents.”
  2. Tasks:
    • Research the topic.
    • Enrich the findings with context.
    • Evaluate market impact and feasibility.
    • Generate a final report.
  3. Agents:
    • Idea Scout
    • Context Analyzer
    • Impact Estimator
    • Turnaround Evaluator
    • Report Generator
  4. Output: A detailed, actionable report structured as a JSON object.
  5. Find detailed code at – https://github.com/learnwithsudheer/think_tank_crewai_agents (Below is just a walkthrough of some part of the code)

Code Walkthrough

1. Project Structure


├── main.py # FastAPI backend
├── idea_generation_crew # CrewAI implementation (agents, tasks, crews)
│ ├── config/agents.yaml # Agent configurations
│ ├── config/tasks.yaml # Task configurations
│ ├── idea_generation_crew.py # Crew logic
├── tools.py # Helper tools (Serper and WebSearch)
├── requirements.txt # Dependencies
├── README.md # Project documentation

2. Agents Configuration (agents.yaml)

Agents are defined with their roles, goals, and backstories. For example:

idea_scout:
  role: >
    Idea Scout for {topic}
  goal: >
    Discover innovative applications and ideas in the field of {topic}.
    Explore emerging technologies such as AI, blockchain, quantum computing,
    and others. Ensure ideas are practical, relevant, and solve real-world problems
    with a focus on scalability and innovation.
  backstory: >
    You are a seasoned research assistant who specializes in identifying cutting-edge
    applications of technology. Your role involves analyzing credible sources
    like research papers, blogs, industry news, and whitepapers to identify novel ideas.

context_analyzer:
  role: >
    Context Analyzer for {topic}
  goal: >
    Provide detailed contextual insights for each idea, including its relevance
    to the market, potential target audience, competitive landscape, and the specific
    problem it addresses. Ensure enriched outputs are actionable.
  backstory: >
    You are a strategic advisor who specializes in turning raw ideas into actionable
    opportunities. Your expertise lies in understanding market dynamics, stakeholders,
    and key challenges to bridge the gap between conceptualization and execution.

impact_estimator:
  role: >
    Impact Estimator for {topic}
  goal: >
    Quantify the market size, number of beneficiaries, and measurable impact for each idea.
    Use data to evaluate the economic and societal value of each solution.
  backstory: >
    As a market analyst, you are responsible for evaluating the scope and scale of ideas.
    You assess how each solution can influence its domain, focusing on measurable
    outcomes like cost savings, efficiency improvements, and user reach.

turnaround_evaluator:
  role: >
    Turnaround Evaluator for {topic}
  goal: >
    Evaluate the feasibility of implementing each idea and determine the estimated
    time-to-market. Assign feasibility scores based on technical readiness, resource
    requirements, and scalability potential.
  backstory: >
    You are a project manager and execution specialist. Your expertise is in evaluating
    ideas for technical feasibility, resource allocation, and operational readiness.
    You ensure that ideas can be implemented efficiently and effectively.

report_generator:
  role: >
    Report Generator for {topic}
  goal: >
    Compile all outputs into a detailed, structured report that summarizes the enriched ideas,
    impact metrics, feasibility scores, and market potential. Ensure the report is
    clear, professional, and actionable.
  backstory: >
    You are a professional writer skilled at synthesizing complex information into concise,
    actionable reports. Decision-makers rely on you to present information in a format
    that is easy to interpret and implement.

3. Tasks Configuration (tasks.yaml)

Tasks define what agents should do and the expected output. For example:

idea_scouting_task:
  description: >
    Conduct an extensive web search to identify innovative applications and ideas in
    the given topic. Focus on technologies such as AI, blockchain, and quantum computing.
    Ensure the results include novel ideas that address real-world problems and offer
    actionable insights.
  expected_output: >
    A list of 3-5 ideas with detailed titles and descriptions. Each idea must include
    at least one unique application and explain how it addresses a specific problem.
  agent: idea_scout

context_enrichment_task:
  description: >
    Analyze the raw ideas to provide enriched contextual details. These details should
    include the target audience, the specific problem solved, potential competitors,
    and any relevant industry dynamics.
  expected_output: >
    A list of enriched ideas. Each idea should have:
      - Target audience: Who benefits from this idea.
      - Problem solved: A clear explanation of the issue it addresses.
      - Competitors: At least 2-3 existing solutions or market players.
  agent: context_analyzer

impact_estimation_task:
  description: >
    For each idea, estimate its market potential. Include quantitative metrics such
    as market size (in USD), number of beneficiaries (individuals or organizations),
    and measurable impacts (e.g., cost savings, efficiency improvements).
  expected_output: >
    A list of impact reports. Each report should include:
      - Market size (e.g., $X billion).
      - Potential beneficiaries (e.g., 10,000+ users).
      - Key measurable outcomes (e.g., 20% efficiency gain).
  agent: impact_estimator

turnaround_evaluation_task:
  description: >
    Evaluate the feasibility of implementing each idea and estimate its time-to-market.
    Assign a feasibility score (scale: 1-10) based on technical readiness, resource
    requirements, and potential risks. Provide an estimated timeline in months.
  expected_output: >
    A list of feasibility evaluations. Each evaluation should include:
      - Feasibility score (1-10, where 10 is highly feasible).
      - Time-to-market: Estimated implementation timeline in months.
      - Key risks and considerations for execution.
  agent: turnaround_evaluator

report_generation_task:
  description: >
    Compile all outputs into a structured report. The report should include summaries
    of enriched ideas, impact metrics, feasibility scores, and actionable insights.
  expected_output: >
    A dictionary with the following structure:
      - ideas: A list of enriched ideas, each including:
        - Title: The title of the idea.
        - Description: A description of the idea.
        - Target Audience: The target audience of the idea.
        - Problem Solved: The problem it addresses.
        - Competitors: List of competitors or existing solutions.
        - impact_metrics: A list of metrics for each idea, including:
          - Market Size: Estimated market size in USD.
          - Beneficiaries: Number of potential beneficiaries.
          - Key Outcomes: Specific measurable outcomes.
        - feasibility: A list of feasibility evaluations, including:
          - Feasibility Score: Score (1-10).
          - Time to Market: Estimated timeline in months.
          - Key Risks: Identified risks.
  agent: report_generator

4. Crews Logic (idea_generation_crew.py)

The crew orchestrates agents and tasks into a cohesive workflow.

import json
from crewai import Agent, Crew, Task, Process
from crewai.project import CrewBase, agent, task, crew
from setup_tools import get_serper_tool, get_websearch_tool


@CrewBase
class IdeaGenerationCrew:
"""Idea Generation Crew to scout, analyze, and evaluate ideas in a given topic."""

# Paths to configuration files for agents and tasks
agents_config = 'config/agents.yaml'
tasks_config = 'config/tasks.yaml'

# -----------------------------------
# Agents
# -----------------------------------

@agent
def idea_scout(self) -> Agent:
"""
Agent responsible for scouting innovative ideas.
Tools: SerperTool (structured web search), WebSearchTool (general search).
"""
return Agent(
config=self.agents_config['idea_scout'],
verbose=True,
tools=[get_serper_tool(), get_websearch_tool()]
)

@agent
def context_analyzer(self) -> Agent:
"""
Agent responsible for analyzing ideas and enriching them with
contextual details (e.g., audience, competitors).
Tool: WebSearchTool for supplementary data retrieval.
"""
return Agent(
config=self.agents_config['context_analyzer'],
verbose=True,
tools=[get_websearch_tool()]
)

@agent
def impact_estimator(self) -> Agent:
"""
Agent responsible for estimating the market impact of ideas.
No external tools required.
"""
return Agent(
config=self.agents_config['impact_estimator'],
verbose=True
)

@agent
def turnaround_evaluator(self) -> Agent:
"""
Agent responsible for evaluating feasibility and time-to-market.
No external tools required.
"""
return Agent(
config=self.agents_config['turnaround_evaluator'],
verbose=True
)

@agent
def report_generator(self) -> Agent:
"""
Agent responsible for compiling all outputs into a structured report.
No external tools required.
"""
return Agent(
config=self.agents_config['report_generator'],
verbose=True
)

# -----------------------------------
# Tasks
# -----------------------------------

@task
def idea_scouting_task(self) -> Task:
"""Task to scout for innovative ideas."""
return Task(
config=self.tasks_config['idea_scouting_task']
)

@task
def context_enrichment_task(self) -> Task:
"""Task to enrich raw ideas with contextual insights."""
return Task(
config=self.tasks_config['context_enrichment_task']
)

@task
def impact_estimation_task(self) -> Task:
"""Task to estimate the market impact of ideas."""
return Task(
config=self.tasks_config['impact_estimation_task']
)

@task
def turnaround_evaluation_task(self) -> Task:
"""Task to evaluate feasibility and time-to-market."""
return Task(
config=self.tasks_config['turnaround_evaluation_task']
)

@task
def report_generation_task(self) -> Task:
"""Task to generate a structured report summarizing all outputs."""
return Task(
config=self.tasks_config['report_generation_task']
)

# -----------------------------------
# Crew
# -----------------------------------

@crew
def think_tank_crew(self) -> Crew:
"""
Crew to execute all tasks sequentially to generate actionable insights and reports.
"""
return Crew(
agents=[
self.idea_scout(),
self.context_analyzer(),
self.impact_estimator(),
self.turnaround_evaluator(),
self.report_generator()
],
tasks=[
self.idea_scouting_task(),
self.context_enrichment_task(),
self.impact_estimation_task(),
self.turnaround_evaluation_task(),
self.report_generation_task()
],
process=Process.sequential, # Tasks are executed one after the other
verbose=True
)


if __name__ == "__main__":
# Instantiate the crew
ideas = IdeaGenerationCrew()

# Input for the pipeline
inputs = {"topic": "Artificial Intelligent Agents"}

# Run the crew and retrieve results
result = ideas.think_tank_crew().kickoff(inputs)
print("Final Result:", json.loads(result.raw))

5. FastAPI Integration (main.py)

The FastAPI server exposes an endpoint to trigger the crew.

from fastapi import FastAPI
from pydantic import BaseModel
from idea_generation_crew import IdeaGenerationCrew

app = FastAPI()

class TopicInput(BaseModel):
    topic: str

@app.post("/generate-ideas/")
async def generate_ideas(input_data: TopicInput):
    crew = IdeaGenerationCrew()
    inputs = {"topic": input_data.topic}
    result = crew.think_tank_crew().kickoff(inputs)
    return {"result": result.raw}

Steps to Set Up Locally

  1. Clone the Repository:
    • git clone https://github.com/learnwithsudheer/think_tank_crewai_agents.git
    • cd think_tank_crewai_agents
  2. Install Dependencies:
    • pip install -r requirements.txt
  3. Start the Backend:
    • uvicorn main:app --reload
  4. Interact with the API:
    • Open your browser and navigate to http://127.0.0.1:8000/docs to test the API.
    • POST a topic to /generate-ideas/ to see the agents in action.

Output Example

Here’s what a structured report might look like:

{
  "ideas": [
    {
      "title": "AI-Driven Chatbots",
      "description": "Chatbots to improve customer engagement.",
      "target_audience": "Businesses with customer support needs",
      "problem_solved": "Reduce response times and improve efficiency.",
      "competitors": ["Google DialogFlow", "ChatGPT"]
    }
  ],
  "impact_metrics": [
    {
      "title": "AI-Driven Chatbots",
      "market_size": "$3 billion",
      "beneficiaries": "10,000+ companies",
      "key_outcomes": "20% cost savings."
    }
  ],
  "feasibility": [
    {
      "title": "AI-Driven Chatbots",
      "feasibility_score": 8,
      "time_to_market": "6 months",
      "key_risks": ["Privacy concerns", "Initial setup costs"]
    }
  ]
}

Closing Thoughts

Think Tank Buddy demonstrates the power of CrewAI to automate workflows and orchestrate multi-agent systems. By combining the concepts of tasks, agents, crews, and flows, we can create scalable AI-powered solutions to solve real-world problems.

Whether you’re a beginner or an advanced developer, CrewAI’s documentation and the excellent deeplearning.ai courses can guide you toward building your own solutions:

Leave a comment