|
| 1 | +# Coordinating Teams of AI Agents with CrewAI in Python |
| 2 | + |
| 3 | +Sample code for the Real Python tutorial |
| 4 | +[CrewAI in Python: Coordinating Teams of AI Agents](https://realpython.com/crewai-python/). |
| 5 | + |
| 6 | +## Requirements |
| 7 | + |
| 8 | +- Python 3.10 to 3.13 (CrewAI does not support 3.14+) |
| 9 | +- A free [Google AI Studio](https://aistudio.google.com/) API key for Gemini |
| 10 | + |
| 11 | +## Setup |
| 12 | + |
| 13 | +Create and activate a virtual environment, then install the dependencies: |
| 14 | + |
| 15 | +```console |
| 16 | +$ python -m venv venv |
| 17 | +$ source venv/bin/activate # On Windows: .\venv\Scripts\activate |
| 18 | +$ python -m pip install -r requirements.txt |
| 19 | +``` |
| 20 | + |
| 21 | +Set your Gemini API key as an environment variable: |
| 22 | + |
| 23 | +```console |
| 24 | +$ export GEMINI_API_KEY="your-gemini-api-key-here" |
| 25 | +``` |
| 26 | + |
| 27 | +On Windows PowerShell: |
| 28 | + |
| 29 | +```pscon |
| 30 | +PS> $ENV:GEMINI_API_KEY = "your-gemini-api-key-here" |
| 31 | +``` |
| 32 | + |
| 33 | +## Running the Examples |
| 34 | + |
| 35 | +Each script corresponds to one section of the tutorial: |
| 36 | + |
| 37 | +| File | Tutorial Section | |
| 38 | +|------|------------------| |
| 39 | +| `01_single_agent.py` | Get Started With CrewAI in Python | |
| 40 | +| `02_research_and_writer_crew.py` | Build Your First Multi-Agent Team | |
| 41 | +| `03_explicit_context.py` | Control Task Dependencies Explicitly | |
| 42 | +| `04_agent_with_tools.py` | Expand Agent Capabilities With Tools | |
| 43 | + |
| 44 | +Run any script with: |
| 45 | + |
| 46 | +```console |
| 47 | +$ python 01_single_agent.py |
| 48 | +``` |
| 49 | + |
| 50 | +## Notes |
| 51 | + |
| 52 | +- The `verbose=True` flag prints detailed agent reasoning logs — useful for |
| 53 | + learning, but noisy for production. |
| 54 | +- If CrewAI complains about a missing `OPENAI_API_KEY` (e.g., when memory |
| 55 | + or certain tools are enabled), set it to any non-empty string to suppress |
| 56 | + the error. |
| 57 | +- On first run, CrewAI may show a "Would you like to view your execution |
| 58 | + traces?" prompt that auto-dismisses after twenty seconds. |
0 commit comments