Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from crewai import Agent, Task, Crew, LLM

llm = LLM(model="gemini/gemini-2.5-flash")

travel_agent = Agent(
role="Travel Advisor",
goal="Provide helpful travel recommendations",
backstory=(
"You're an experienced travel advisor who has visited"
" over fifty countries and specializes in budget-friendly"
" adventure travel."
),
llm=llm,
verbose=True,
)

task = Task(
description="Suggest three budget-friendly destinations in Southeast Asia",
expected_output="A short list of three destinations with brief descriptions",
agent=travel_agent,
)

crew = Crew(agents=[travel_agent], tasks=[task])
result = crew.kickoff()
print(result.raw)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from crewai import Agent, Task, Crew, Process, LLM

llm = LLM(model="gemini/gemini-2.5-flash")

researcher = Agent(
role="Senior Research Analyst",
goal="Find comprehensive information about a given topic",
backstory=(
"You're a seasoned research analyst with a knack for"
" uncovering the most relevant and accurate information."
" You're known for your thorough and well-organized research."
),
llm=llm,
)

writer = Agent(
role="Content Writer",
goal="Write clear, engaging content based on research findings",
backstory=(
"You're an experienced writer who excels at transforming"
" complex research into accessible, well-structured articles"
" that readers enjoy."
),
llm=llm,
)

research_task = Task(
description="Research the latest trends in renewable energy technology",
expected_output=(
"A detailed list of the top five renewable energy trends"
" with explanations"
),
agent=researcher,
)

writing_task = Task(
description="Write a short article based on the research findings",
expected_output=(
"A well-structured article of about three hundred words"
" on renewable energy trends"
),
agent=writer,
)

crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
process=Process.sequential,
verbose=True,
)

result = crew.kickoff()
print(result.raw)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from crewai import Agent, Task, Crew, LLM

llm = LLM(model="gemini/gemini-2.5-flash")

researcher = Agent(
role="Senior Research Analyst",
goal="Find comprehensive information about a given topic",
backstory=(
"You're a seasoned research analyst with a knack for"
" uncovering the most relevant and accurate information."
" You're known for your thorough and well-organized research."
),
llm=llm,
)

writer = Agent(
role="Content Writer",
goal="Write clear, engaging content based on research findings",
backstory=(
"You're an experienced writer who excels at transforming"
" complex research into accessible, well-structured articles"
" that readers enjoy."
),
llm=llm,
)

research_task = Task(
description=(
"Research the current state of electric vehicle adoption worldwide"
),
expected_output=(
"A bullet-point list of key statistics and trends in EV adoption"
),
agent=researcher,
)

writing_task = Task(
description=(
"Using the provided research, write a concise summary article"
" about electric vehicle adoption"
),
expected_output="A two hundred word article summarizing EV adoption trends",
agent=writer,
context=[research_task],
)

crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
verbose=True,
)

result = crew.kickoff()
print(result.raw)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from crewai import Agent, Task, Crew, LLM
from crewai_tools import ScrapeWebsiteTool

llm = LLM(model="gemini/gemini-2.5-flash")

scrape_tool = ScrapeWebsiteTool()

researcher = Agent(
role="Python Release Analyst",
goal="Find the latest Python release information",
backstory=(
"You're a developer advocate who tracks Python releases"
" and summarizes what's new for the community."
),
tools=[scrape_tool],
llm=llm,
)

writer = Agent(
role="Tech Blogger",
goal="Write concise release summaries for a developer audience",
backstory=(
"You write clear, engaging blog posts that help developers"
" stay up to date with the Python ecosystem."
),
llm=llm,
)

research_task = Task(
description=(
"Scrape https://www.python.org/downloads/ and report"
" the latest stable Python version number and its release date"
),
expected_output="The latest Python version number and release date",
agent=researcher,
)

writing_task = Task(
description=(
"Write a one-paragraph announcement based on the Python"
" release information provided by the research task"
),
expected_output=(
"A concise one hundred word announcement covering the"
" latest Python version number and release date"
),
agent=writer,
context=[research_task],
)

crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
verbose=True,
)

result = crew.kickoff()
print(result.raw)
58 changes: 58 additions & 0 deletions coordinating-teams-of-ai-agents-with-crewai-in-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Coordinating Teams of AI Agents with CrewAI in Python

Sample code for the Real Python tutorial
[Coordinating Teams of AI Agents with CrewAI in Python](https://realpython.com/coordinating-teams-of-ai-agents-with-crewai-in-python/).

## Requirements

- Python 3.10 to 3.13 (CrewAI does not support 3.14+)
- A free [Google AI Studio](https://aistudio.google.com/) API key for Gemini

## Setup

Create and activate a virtual environment, then install the dependencies:

```console
$ python -m venv venv
$ source venv/bin/activate # On Windows: .\venv\Scripts\activate
$ python -m pip install -r requirements.txt
```

Set your Gemini API key as an environment variable:

```console
$ export GEMINI_API_KEY="your-gemini-api-key-here"
```

On Windows PowerShell:

```pscon
PS> $ENV:GEMINI_API_KEY = "your-gemini-api-key-here"
```

## Running the Examples

Each script corresponds to one section of the tutorial:

| File | Tutorial Section |
|------|------------------|
| `01_single_agent.py` | Start Using CrewAI to Create Agent Teams |
| `02_research_and_writer_crew.py` | Build Your First Multi-Agent Team |
| `03_explicit_context.py` | Control Task Dependencies Explicitly |
| `04_agent_with_tools.py` | Expand Agent Capabilities With Tools |

Run any script with:

```console
$ python 01_single_agent.py
```

## Notes

- The `verbose=True` flag prints detailed agent reasoning logs β€” useful for
learning, but noisy for production.
- If CrewAI complains about a missing `OPENAI_API_KEY` (e.g., when memory
or certain tools are enabled), set it to any non-empty string to suppress
the error.
- On first run, CrewAI may show a "Would you like to view your execution
traces?" prompt that auto-dismisses after twenty seconds.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
crewai[tools,google-genai]
Loading