MIT Professional Education: Agentic AI Course
A step-by-step guide for absolute beginners — no prior AI experience required
- What You'll Learn
- The Big Picture: What Are AI Agents?
- Understanding the Technology Stack
- What is Ollama? (Deep Dive)
- What is CrewAI? (Deep Dive)
- How the Demo Works
- Step-by-Step Setup Guide
- Running Your First Multi-Agent Task
- Understanding the Output
- Troubleshooting for Beginners
- Glossary
- Further Reading & Resources
By the end of this guide, you will:
- ✅ Understand what AI agents are and why they matter
- ✅ Know the difference between cloud AI (OpenAI) and local AI (Ollama)
- ✅ Have Ollama running on your computer with a working AI model
- ✅ Run a multi-agent research task and see three AI agents collaborate
- ✅ Understand the code well enough to modify it for your own projects
Time required: ~30 minutes for setup, ~10 minutes for your first run
You're probably familiar with AI chatbots like ChatGPT or Claude. You type a question, and they respond. This is called a single-turn interaction — you ask, they answer.
AI Agents are different. They can:
- Break down complex tasks into smaller steps
- Take actions (search the web, write files, call APIs)
- Work together with other agents
- Operate with minimal human intervention
Think of the difference like this:
| Chatbot | Agent |
|---|---|
| Answers questions | Completes tasks |
| Single response | Multiple steps |
| You guide every step | Works autonomously |
| Like a reference librarian | Like a research assistant |
Imagine you need a research report. With a single AI, you'd prompt it to do everything — research, write, and edit. The results are often mediocre because no single prompt can capture all those requirements.
Multi-agent systems solve this by having specialized agents:
┌─────────────â”� ┌─────────────â”� ┌─────────────â”�
│ RESEARCHER │ → │ WRITER │ → │ EDITOR │
│ │ │ │ │ │
│ Gathers │ │ Transforms │ │ Polishes │
│ facts & │ │ research │ │ for clarity │
│ data │ │ into prose │ │ & accuracy │
└─────────────┘ └─────────────┘ └─────────────┘
Each agent has:
- A role (what they do)
- A goal (what they're trying to achieve)
- A backstory (context that shapes their behavior)
This is exactly what our demo does!
Before we dive into setup, let's understand what each piece of technology does:
┌────────────────────────────────────────────────────────â”�
│ YOUR BROWSER │
│ (localhost:8501) │
└────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────â”�
│ STREAMLIT │
│ (Web interface - makes it pretty) │
│ │
│ File: pages/2_Multi_Agent_Demo.py │
└────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────â”�
│ CREWAI │
│ (Orchestrates agents - makes them work together) │
│ │
│ File: crews/research_crew.py │
└────────────────────────────────────────────────────────┘
│
▼
┌────────────────────────────────────────────────────────â”�
│ LANGUAGE MODEL (LLM) │
│ (The actual AI brain doing the thinking) │
│ │
│ Option A: Ollama (local, free) │
│ Option B: OpenAI (cloud, paid) │
└────────────────────────────────────────────────────────┘
| Technology | What It Does | Analogy |
|---|---|---|
| Streamlit | Creates the web interface | The "front desk" |
| CrewAI | Coordinates multiple agents | The "project manager" |
| LangChain | Connects to different AI providers | The "translator" |
| Ollama | Runs AI models locally | Your "in-house AI team" |
| OpenAI API | Cloud AI service | "Outsourced AI consultants" |
Traditionally, to use powerful AI models, you needed to:
- Send your data to a company's servers (privacy concern)
- Pay per request (cost adds up)
- Have internet access (dependency)
- Wait for network round-trips (latency)
Ollama lets you run the same AI models entirely on your own computer.
┌─────────────────────────────────────────────────────────â”�
│ YOUR COMPUTER │
│ │
│ ┌─────────────â”� ┌─────────────────────────────â”� │
│ │ Ollama │ │ Downloaded Models │ │
│ │ Server │ â†�── │ │ │
│ │ │ │ • llama3.2 (4.7 GB) │ │
│ │ localhost │ │ • mistral (4.1 GB) │ │
│ │ :11434 │ │ • phi3 (2.3 GB) │ │
│ └─────────────┘ └─────────────────────────────┘ │
│ ↑ │
│ │ │
│ ┌──────┴──────â”� │
│ │ Your Apps │ (Our demo connects here) │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────┘
1. Models A "model" is the trained AI brain. Different models have different capabilities:
| Model | Size | Best For | Speed |
|---|---|---|---|
phi3 |
2.3 GB | Quick tasks, limited RAM | ⚡⚡⚡ Fast |
mistral |
4.1 GB | Good balance | ⚡⚡ Medium |
llama3.2 |
4.7 GB | General use (recommended) | ⚡⚡ Medium |
llama3.1 |
8.5 GB | Complex reasoning | ⚡ Slower |
2. Server Ollama runs as a "server" on your computer. It listens on port 11434 for requests. When your app asks for AI help, Ollama:
- Receives the request
- Loads the model (if not already loaded)
- Processes your input
- Returns the response
3. Commands
ollama serve # Start the server (required first!)
ollama pull # Download a model
ollama list # See your downloaded models
ollama run # Chat with a model directly| Aspect | Ollama | OpenAI |
|---|---|---|
| Cost | Free | ~$0.01 per demo run |
| Privacy | Data stays on your machine | Data sent to OpenAI |
| Speed | Depends on your hardware | Consistently fast |
| Setup | More complex | Just need API key |
| Internet | Not required | Required |
| Quality | Good (varies by model) | Excellent |
When to use Ollama:
- Learning/experimenting (no cost)
- Privacy-sensitive data
- Offline work
- Understanding how AI works "under the hood"
When to use OpenAI:
- Production applications
- Fastest results needed
- Don't want to manage local setup
Single AI models, even powerful ones, struggle with complex tasks because:
- They have no memory between responses
- They can't break tasks into steps autonomously
- They don't have specialized skills for different subtasks
CrewAI is a framework that lets you create teams of AI agents that:
- Have specific roles and expertise
- Pass work to each other
- Remember context within a session
- Work toward a shared goal
CrewAI agents are not raw API calls or simple prompt templates. Instead, CrewAI uses an abstraction layer where you define agents with three key attributes:
| Attribute | Purpose | Example |
|---|---|---|
| Role | The agent's job title | "Research Analyst" |
| Goal | What the agent is trying to achieve | "Gather comprehensive information about {topic}" |
| Backstory | Context that shapes behavior and expertise | "You are an experienced researcher with expertise in finding accurate, relevant information..." |
What happens under the hood:
- You define
role,goal, andbackstoryfor each agent - CrewAI combines these with the task description
- CrewAI constructs a system prompt + user prompt internally
- The prompt is sent to the LLM (OpenAI, Ollama, etc.) via API call
This abstraction lets you define agent "personalities" without writing raw prompts. Think of it like hiring team members — you describe who they are, and CrewAI handles how to instruct them.
# This is simplified - see the actual code in crews/research_crew.py
from crewai import Agent, Task, Crew
# 1. Define specialized agents
researcher = Agent(
role="Research Analyst",
goal="Gather comprehensive information",
backstory="You are an experienced researcher..."
)
writer = Agent(
role="Content Writer",
goal="Transform research into clear content",
backstory="You excel at making complex topics accessible..."
)
editor = Agent(
role="Editor",
goal="Polish content for publication",
backstory="You have an eye for detail..."
)
# 2. Define tasks with dependencies
research_task = Task(
description="Research the topic thoroughly",
agent=researcher
)
writing_task = Task(
description="Write a clear brief from the research",
agent=writer,
context=[research_task] # Gets output from research
)
editing_task = Task(
description="Polish the written content",
agent=editor,
context=[writing_task] # Gets output from writer
)
# 3. Create the crew and run
crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, writing_task, editing_task]
)
result = crew.kickoff()USER INPUT: "Research AI in healthcare"
│
▼
┌─────────────────â”�
│ RESEARCHER │
│ │
│ Receives topic │
│ Gathers info │
│ Outputs brief │
└────────┬────────┘
│ passes research to...
▼
┌─────────────────â”�
│ WRITER │
│ │
│ Receives brief │
│ Writes content │
│ Outputs draft │
└────────┬────────┘
│ passes draft to...
▼
┌─────────────────â”�
│ EDITOR │
│ │
│ Receives draft │
│ Polishes text │
│ Outputs final │
└────────┬────────┘
│
▼
FINAL OUTPUT
Our demo combines all these technologies:
AgenticAI_foundry/
│
├── Home.py # Landing page (what you see first)
│
├── pages/
│ ├── 1_LLM_Cost_Calculator.py # Module 1 demo
│ └── 2_Multi_Agent_Demo.py # Module 2 demo â†� The agent demo
│
├── crews/ # 🚀 THE HEART OF MULTI-AGENT LOGIC
│ ├── __init__.py # Makes this a Python package
│ └── research_crew.py # The actual agent definitions & orchestration
│
└── docs/
├── DOCKER_GUIDE.md # Docker setup help
├── CREWAI_SETUP.md # Quick setup reference
└── BEGINNERS_GUIDE.md # This file!
The crews/ folder is where all the multi-agent logic lives. Think of it as the "brain" of the demo while the pages/ folder is the "face" (the user interface).
Why separate them?
| Folder | Purpose | Analogy |
|---|---|---|
pages/ |
User interface (buttons, displays) | The dashboard of a car |
crews/ |
Agent logic (AI coordination) | The engine under the hood |
This separation means you can:
- Reuse crews in different interfaces (web, CLI, API)
- Test agents independently of the UI
- Build new crews for different tasks (sales, support, analysis)
This file contains everything needed to run a multi-agent research team:
# 1. CONFIGURATION - Define providers (Ollama, OpenAI)
PROVIDER_CONFIGS = {
"ollama": ProviderConfig(...), # Free, local AI
"openai": ProviderConfig(...), # Paid, cloud AI
}
# 2. TELEMETRY - Track performance metrics
@dataclass
class AgentTelemetry:
duration_seconds: float # How long agent took
input_tokens: int # Tokens sent to AI
output_tokens: int # Tokens received back
...
# 3. AGENT DEFINITIONS - The three specialists
def create_research_crew(llm):
researcher = Agent(
role="Research Analyst",
goal="Gather comprehensive, accurate information",
backstory="You are an experienced researcher..."
)
writer = Agent(...)
editor = Agent(...)
return {"Researcher": researcher, "Writer": writer, "Editor": editor}
# 4. TASK DEFINITIONS - What each agent does
def create_tasks(agents, topic):
research_task = Task(description=f"Research {topic}...", agent=agents["Researcher"])
writing_task = Task(description="Write a brief...", agent=agents["Writer"])
editing_task = Task(description="Polish the content...", agent=agents["Editor"])
return [research_task, writing_task, editing_task]
# 5. EXECUTION - Run the crew and collect telemetry
def run_research_crew(topic, provider, ...):
llm = get_llm(provider) # Get AI model
agents = create_research_crew(llm) # Create agents
tasks = create_tasks(agents, topic) # Define tasks
crew = Crew(agents=..., tasks=...) # Assemble crew
result = crew.kickoff() # Run!
return CrewResult(output=result, telemetry=...)When you click "Run Research Crew" in the browser:
┌─────────────────────────────────────────────────────────────────â”�
│ BROWSER (what you see) │
│ pages/2_Multi_Agent_Demo.py │
│ │
│ ┌─────────────────â”� │
│ │ [Run Research] │ ◄── You click this │
│ └────────┬────────┘ │
└───────────┼─────────────────────────────────────────────────────┘
│
│ calls
▼
┌─────────────────────────────────────────────────────────────────â”�
│ CREWS ENGINE (what runs behind the scenes) │
│ crews/research_crew.py │
│ │
│ run_research_crew(topic="AI in healthcare", provider="ollama") │
│ │ │
│ ├── Creates LLM connection │
│ ├── Creates 3 agents │
│ ├── Creates 3 tasks │
│ ├── Runs Crew.kickoff() │
│ └── Returns result + telemetry │
└─────────────────────────────────────────────────────────────────┘
│
│ returns
▼
┌─────────────────────────────────────────────────────────────────â”�
│ BROWSER (displays results) │
│ │
│ 📊 Summary Metrics: 45.2s | 3,421 tokens | $0.0012 │
│ 📄 Final Output: "AI in healthcare is transforming..." │
│ 📈 Charts: Duration by agent, Token usage │
└─────────────────────────────────────────────────────────────────┘
Once you understand this pattern, you can create new crews for any task:
# Example: Customer Support Crew
support_crew/
├── __init__.py
└── support_crew.py
├── intake_agent # Understands customer issue
├── solution_agent # Finds answers in knowledge base
└── response_agent # Crafts friendly reply
# Example: Code Review Crew
code_crew/
├── __init__.py
└── code_crew.py
├── analyzer_agent # Reads and understands code
├── security_agent # Checks for vulnerabilities
└── reviewer_agent # Suggests improvementsThe pattern is always the same:
- Define agents with roles, goals, backstories
- Define tasks with descriptions and agent assignments
- Create a crew and call
kickoff()
1. You enter a topic in Streamlit
│
▼
2. Streamlit calls crews/research_crew.py
│
▼
3. research_crew.py creates 3 agents
│
▼
4. CrewAI orchestrates the workflow
│
▼
5. Each agent calls Ollama (or OpenAI) to "think"
│
▼
6. Results flow back through Streamlit
│
▼
7. You see the final output!
Before starting, verify you have:
- Python 3.9 or newer — Check with
python --version - pip — Check with
pip --version - 8+ GB RAM — Required for local AI models
- 10+ GB free disk space — Models are large files
macOS:
# Using Homebrew (recommended)
brew install ollama
# Or download from https://ollama.aiLinux:
curl -fsSL https://ollama.ai/install.sh | shWindows:
- Go to ollama.ai
- Click "Download"
- Run the installer
- Open a new terminal after installation
Verify installation:
ollama --version
# Should show something like: ollama version 0.1.x# Download the recommended model (takes 2-5 minutes)
ollama pull llama3.2
# Verify it downloaded
ollama list
# Should show: llama3.2:latestWhat's happening: Ollama is downloading a 4.7 GB file containing the trained neural network. This only happens once — the model is saved locally.
ollama serveLeave this terminal open! You should see:
Couldn't find '/Users/you/.ollama/id_ed25519'. Generating new private key.
Your new public key is: ...
2024/01/15 10:30:00 routes.go:1019: INFO server config...
What's happening: Ollama is now listening on http://localhost:11434 for AI requests.
Open a new terminal (keep Ollama running in the other):
# Navigate to where you want the project
cd ~/Projects # or wherever you prefer
# Clone the repo
git clone https://github.com/dlwhyte/AgenticAI_foundry.git
# Enter the directory
cd AgenticAI_foundry# Create a virtual environment (recommended)
python -m venv venv
# Activate it
# On macOS/Linux:
source venv/bin/activate
# On Windows:
.\venv\Scripts\activate
# Your prompt should now show (venv)# Install base requirements
pip install -r requirements.txt
# Install CrewAI and Ollama support
pip install crewai langchain-community# Check that Ollama is accessible
curl http://localhost:11434/api/tags
# Should return JSON with your models
# Or use our built-in check
python -m crews.research_crew --checkYou should see:
� Checking provider availability...
✅ ðŸ� Ollama (Local)
└─ Ollama is running
└─ llama3.2 model available
✅ â˜�ï¸� OpenAI
└─ ⚠ï¸� No API key. Set OPENAI_API_KEY
streamlit run Home.pyYour browser should open to http://localhost:8501. Click "Multi-Agent Demo" in the sidebar!
- Select Provider: Choose "ðŸ� Ollama (Local)" in the sidebar
- Enter a Topic: Try something like:
- "Research the impact of AI on healthcare"
- "Explain quantum computing for business leaders"
- "Summarize recent developments in renewable energy"
- Click "🚀 Run Research Crew"
- Watch the agents work!
For more control, use the CLI directly:
# Basic usage
python -m crews.research_crew --provider ollama --task "Research AI in education"
# See what's happening (verbose mode is on by default)
python -m crews.research_crew --provider ollama --task "Explain blockchain"
# Quiet mode (just the result)
python -m crews.research_crew --provider ollama --task "Topic" --quietWhen the demo runs, you'll see output like this:
====================================================================
🤖 CrewAI Research Team
====================================================================
Provider: ðŸ� Ollama (Local)
Model: llama3.2
Topic: Research AI in healthcare
====================================================================
📌 Initializing ðŸ� Ollama (Local)...
📌 Creating agents...
📌 Setting up tasks...
📌 ðŸ”� Researcher is gathering information...
[Agent: Research Analyst] Starting research on AI in healthcare...
[Agent: Research Analyst] Key findings:
- AI diagnostic accuracy rates...
- Implementation challenges...
[Agent: Content Writer] Transforming research into prose...
[Agent: Editor] Polishing final output...
====================================================================
✅ FINAL OUTPUT
====================================================================
[The polished research brief appears here]
Researcher Output:
- Raw facts and statistics
- Key trends and developments
- Notable examples
- Unstructured but comprehensive
Writer Output:
- Organized prose
- Clear introduction, body, conclusion
- Accessible language
- 300-500 words
Editor Output:
- Polished final version
- Corrected any errors
- Improved clarity
- Publication-ready
Symptom: Error says Ollama isn't available
Fix:
# In a separate terminal:
ollama serve
# Keep it running while using the demoSymptom: Error about missing model
Fix:
# Download the model
ollama pull llama3.2
# Verify it's there
ollama listSymptom: Computer freezes or error about memory
Fix:
- Close other applications
- Try a smaller model:
ollama pull phi3
# Then select phi3 in the demo or use --model phi3Symptom: Taking many minutes per agent
This is normal for local models! Tips:
- First run is slowest (loading model)
- Smaller models are faster (
phi3vsllama3.1) - GPU acceleration helps dramatically
- Consider OpenAI for speed-critical work
Symptom: Python can't find modules
Fix:
# Make sure you're in the right directory
cd AgenticAI_foundry
# Make sure venv is activated
source venv/bin/activate # or .\venv\Scripts\activate on Windows
# Reinstall dependencies
pip install -r requirements.txt
pip install crewai langchain-communitySymptom: Can't run scripts or access files
Fix (macOS/Linux):
chmod +x ollama # If needed for OllamaFix (Windows):
- Run terminal as Administrator
- Check antivirus isn't blocking
| Term | Definition |
|---|---|
| Agent | An AI entity with a specific role, goal, and capabilities |
| API | Application Programming Interface — how programs talk to each other |
| API Key | A secret password that lets you use a service (like OpenAI) |
| CLI | Command Line Interface — using text commands instead of clicking |
| Context Window | How much text an AI can "remember" at once |
| CrewAI | A Python framework for building multi-agent systems |
| Hallucination | When AI makes up false information confidently |
| LangChain | A library that connects to different AI providers |
| LLM | Large Language Model — the AI brain (like GPT, Llama, etc.) |
| Local Model | AI running on your own computer, not in the cloud |
| Model | The trained AI "brain" — a large file of learned patterns |
| Ollama | Software that runs AI models locally on your computer |
| OpenAI | Company that makes GPT models, accessed via their cloud API |
| Prompt | The input/instructions you give to an AI |
| Server | A program that waits for and responds to requests |
| Streamlit | A Python library for creating web apps quickly |
| Token | A chunk of text (~4 characters) — how AI "sees" words |
| venv | Virtual environment — isolated Python setup for a project |
- CrewAI: docs.crewai.com
- Ollama: github.com/ollama/ollama
- Streamlit: docs.streamlit.io
- LangChain: python.langchain.com
- DeepLearning.AI: Free courses on AI agents
- YouTube: Search "CrewAI tutorial" for video walkthroughs
- Ollama Blog: ollama.ai/blog for tips and updates
- CrewAI Discord: Active community for questions
- r/LocalLLaMA: Reddit community for local AI
- Ollama Discord: Help with local model setup
- "Building LLM Apps" by Valentino Gagliardi
- "Generative AI with LangChain" by Ben Auffarth
- Modify the agents: Edit
crews/research_crew.pyto change their personalities - Add new agents: Create a "Fact Checker" or "Translator" agent
- Connect tools: CrewAI supports web search, file reading, and more
- Build your own crew: Design agents for your specific use case
You've learned:
- AI Agents are autonomous entities that can complete multi-step tasks
- Ollama runs AI models locally on your computer (free, private)
- CrewAI orchestrates multiple agents working together
- Our demo shows Researcher → Writer → Editor collaboration
- Setup involves: Ollama + model + Python environment + our code
The key insight: Multi-agent systems can achieve better results than single models by having specialists collaborate — just like human teams.
MIT Professional Education | Agentic AI Course
Module 2: Multi-Agent Systems
Questions? Check the Quick Setup Guide or ask in class!
📊 See Also: Slides "How CrewAI Specializes Agents" and "What Happens Under the Hood" in the presentation deck.
A common question: Are CrewAI agents custom prompt templates or raw API calls?
Answer: Neither — it's an abstraction layer that handles both.
When you define an agent in CrewAI, you specify three things:
| Attribute | Purpose | Example |
|---|---|---|
| Role | The agent's job title | "Research Analyst" |
| Goal | What the agent is trying to achieve | "Gather comprehensive information about {topic}" |
| Backstory | Context that shapes behavior and expertise | "You are an experienced researcher with expertise in finding accurate, relevant information..." |
Agent(
role="Research Analyst",
goal="Gather comprehensive information about {topic}",
backstory="You are an experienced researcher with expertise in finding accurate, relevant information...",
llm=llm,
verbose=verbose
)┌─────────────────â”� ┌─────────────────â”� ┌─────────────────â”� ┌──────────â”�
│ Your Definition │ >>> │ CrewAI │ >>> │ LLM API │ >>> │ Output │
│ role, goal, │ │ Builds prompt │ │ OpenAI / Ollama │ │ Agent │
│ backstory │ │ from attributes │ │ │ │ result │
└─────────────────┘ └─────────────────┘ └─────────────────┘ └──────────┘
- You define the agent with role, goal, and backstory
- CrewAI combines these with the task description to construct a system prompt
- The prompt is sent to the LLM via API (OpenAI, Ollama, etc.)
- The response becomes the agent's output
CrewAI is an abstraction layer — you define "personalities" without writing raw prompts. This lets you:
- Focus on what agents should do, not how to prompt them
- Easily swap LLM providers (OpenAI ↔ Ollama) without changing agent definitions
- Create reusable agent "templates" for different use cases
In the Multi-Agent Demo, you'll see three agents (Researcher, Writer, Editor) with different roles, goals, and backstories. Each produces distinct output because CrewAI constructs different prompts based on their attributes — even though they're all using the same underlying LLM.
While crews/ contains CrewAI multi-agent logic, the agents/ folder contains LangChain single-agent implementations.
| Folder | Framework | Pattern | Example |
|---|---|---|---|
crews/ |
CrewAI | Multi-agent collaboration | Researcher → Writer → Editor |
agents/ |
LangChain | Single agent + tools | Agent + Web Search |
This file implements a LangChain agent that:
- Takes a question about cryptocurrency prices
- Uses the DuckDuckGo search tool to get real-time data
- Returns a formatted answer
Key Components:
# The LLM (brain)
llm = ChatOpenAI(model="gpt-4o-mini") # or ChatOllama
# The tool (capability)
search_tool = DuckDuckGoSearchRun()
# The agent (combines brain + tools)
agent = create_react_agent(llm, [search_tool], prompt)
# Run it
result = agent_executor.invoke({"input": "What's the Bitcoin price?"})LangChain agents use the ReAct (Reasoning + Acting) pattern:
Question: What's the current price of Bitcoin?
│
▼
Thought: I need to search for current Bitcoin price
│
▼
Action: web_search("Bitcoin current price")
│
▼
Observation: Bitcoin is trading at $97,245...
│
▼
Thought: I now have the information
│
▼
Final Answer: Bitcoin is currently trading at $97,245.
| Scenario | Use This |
|---|---|
| Multi-step workflow with handoffs | CrewAI (crews/) |
| Need real-time data from tools | LangChain (agents/) |
| Research → Write → Edit pipeline | CrewAI |
| Quick question with search | LangChain |